2 * Copyright (c) 2012, 2013 Spectra Logic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * substantially similar to the "NO WARRANTY" disclaimer below
13 * ("Disclaimer") and any redistribution must be conditioned upon
14 * including a substantially similar Disclaimer requirement for further
15 * binary redistribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGES.
30 * Authors: Alan Somers (Spectra Logic Corporation)
34 * \file devdctl_guid.h
36 * Definition of the Guid class.
38 #ifndef _DEVDCTL_GUID_H_
39 #define _DEVDCTL_GUID_H_
41 /*============================ Namespace Control =============================*/
45 /*============================= Class Definitions ============================*/
46 /*----------------------------------- Guid -----------------------------------*/
48 * \brief Object that represents guids.
50 * It can generally be manipulated as a uint64_t, but with a special
51 * value INVALID_GUID that does not equal any valid guid.
53 * As of this writing, this class is only used to represent ZFS
54 * guids in events and spa_generate_guid() in spa_misc.c explicitly
55 * refuses to return a guid of 0. So this class uses 0 as the value
56 * for INVALID_GUID. In the future, if 0 is allowed to be a valid
57 * guid, the implementation of this class must change.
63 /* Default constructor: an Invalid guid */
65 /* Construct a guid from a provided integer */
67 /* Construct a guid from a string in base 8, 10, or 16 */
68 Guid(const std::string &guid);
69 static Guid InvalidGuid();
71 /* Test the validity of this guid. */
74 /* Comparison to other Guid operators */
75 bool operator==(const Guid& rhs) const;
76 bool operator!=(const Guid& rhs) const;
78 /* Integer conversion operators */
79 operator uint64_t() const;
80 operator bool() const;
83 static const uint64_t INVALID_GUID = 0;
85 /* The integer value of the GUID. */
89 //- Guid Inline Public Methods ------------------------------------------------
92 : m_GUID(INVALID_GUID)
97 Guid::Guid(uint64_t guid)
105 return (Guid(INVALID_GUID));
109 Guid::IsValid() const
111 return (m_GUID != INVALID_GUID);
115 Guid::operator==(const Guid& rhs) const
117 return (m_GUID == rhs.m_GUID);
121 Guid::operator!=(const Guid& rhs) const
123 return (m_GUID != rhs.m_GUID);
127 Guid::operator uint64_t() const
133 Guid::operator bool() const
135 return (m_GUID != INVALID_GUID);
138 /** Convert the GUID into its string representation */
139 std::ostream& operator<< (std::ostream& out, Guid g);
141 } // namespace DevdCtl
142 #endif /* _DEVDCTL_GUID_H_ */