Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:32

0001 // Boost uuid.hpp header file  ----------------------------------------------//
0002 
0003 // Copyright 2006 Andy Tompkins.
0004 // Distributed under the Boost Software License, Version 1.0. (See
0005 // accompanying file LICENSE_1_0.txt or copy at
0006 // https://www.boost.org/LICENSE_1_0.txt)
0007 
0008 // Revision History
0009 //  06 Feb 2006 - Initial Revision
0010 //  09 Nov 2006 - fixed variant and version bits for v4 guids
0011 //  13 Nov 2006 - added serialization
0012 //  17 Nov 2006 - added name-based guid creation
0013 //  20 Nov 2006 - add fixes for gcc (from Tim Blechmann)
0014 //  07 Mar 2007 - converted to header only
0015 //  10 May 2007 - removed need for Boost.Thread
0016 //              - added better seed - thanks Peter Dimov
0017 //              - removed null()
0018 //              - replaced byte_count() and output_bytes() with size() and begin() and end()
0019 //  11 May 2007 - fixed guid(ByteInputIterator first, ByteInputIterator last)
0020 //              - optimized operator>>
0021 //  14 May 2007 - converted from guid to uuid
0022 //  29 May 2007 - uses new implementation of sha1
0023 //  01 Jun 2007 - removed using namespace directives
0024 //  09 Nov 2007 - moved implementation to uuid.ipp file
0025 //  12 Nov 2007 - moved serialize code to uuid_serialize.hpp file
0026 //  25 Feb 2008 - moved to namespace boost::uuids
0027 //  19 Mar 2009 - changed to a POD, reorganized files
0028 //  28 Nov 2009 - disabled deprecated warnings for MSVC
0029 //  30 Nov 2009 - used BOOST_STATIC_CONSTANT
0030 //  02 Dec 2009 - removed BOOST_STATIC_CONSTANT - not all compilers like it
0031 //  29 Apr 2013 - added support for noexcept and constexpr, added optimizations for SSE/AVX
0032 
0033 #ifndef BOOST_UUID_HPP
0034 #define BOOST_UUID_HPP
0035 
0036 #include <cstddef>
0037 #include <boost/cstdint.hpp>
0038 #include <boost/uuid/detail/config.hpp>
0039 #ifndef BOOST_UUID_NO_TYPE_TRAITS
0040 #include <boost/type_traits/is_pod.hpp>
0041 #include <boost/type_traits/integral_constant.hpp>
0042 #endif
0043 
0044 #ifdef BOOST_HAS_PRAGMA_ONCE
0045 #pragma once
0046 #endif
0047 
0048 #if defined(_MSC_VER)
0049 #pragma warning(push) // Save warning settings.
0050 #pragma warning(disable : 4996) // Disable deprecated std::swap_ranges, std::equal
0051 #endif
0052 
0053 #ifdef BOOST_NO_STDC_NAMESPACE
0054 namespace std {
0055     using ::size_t;
0056     using ::ptrdiff_t;
0057 } //namespace std
0058 #endif //BOOST_NO_STDC_NAMESPACE
0059 
0060 namespace boost {
0061 namespace uuids {
0062 
0063 struct uuid
0064 {
0065 public:
0066     typedef uint8_t value_type;
0067     typedef uint8_t& reference;
0068     typedef uint8_t const& const_reference;
0069     typedef uint8_t* iterator;
0070     typedef uint8_t const* const_iterator;
0071     typedef std::size_t size_type;
0072     typedef std::ptrdiff_t difference_type;
0073 
0074     // This does not work on some compilers
0075     // They seem to want the variable definec in
0076     // a cpp file
0077     //BOOST_STATIC_CONSTANT(size_type, static_size = 16);
0078     static BOOST_CONSTEXPR size_type static_size() BOOST_NOEXCEPT { return 16; }
0079 
0080 public:
0081     iterator begin() BOOST_NOEXCEPT { return data; }
0082     const_iterator begin() const BOOST_NOEXCEPT { return data; }
0083     iterator end() BOOST_NOEXCEPT { return data+size(); }
0084     const_iterator end() const BOOST_NOEXCEPT { return data+size(); }
0085 
0086     BOOST_CONSTEXPR size_type size() const BOOST_NOEXCEPT { return static_size(); }
0087 
0088     bool is_nil() const BOOST_NOEXCEPT;
0089 
0090     enum variant_type
0091     {
0092         variant_ncs, // NCS backward compatibility
0093         variant_rfc_4122, // defined in RFC 4122 document
0094         variant_microsoft, // Microsoft Corporation backward compatibility
0095         variant_future // future definition
0096     };
0097     variant_type variant() const BOOST_NOEXCEPT
0098     {
0099         // variant is stored in octet 7
0100         // which is index 8, since indexes count backwards
0101         unsigned char octet7 = data[8]; // octet 7 is array index 8
0102         if ( (octet7 & 0x80) == 0x00 ) { // 0b0xxxxxxx
0103             return variant_ncs;
0104         } else if ( (octet7 & 0xC0) == 0x80 ) { // 0b10xxxxxx
0105             return variant_rfc_4122;
0106         } else if ( (octet7 & 0xE0) == 0xC0 ) { // 0b110xxxxx
0107             return variant_microsoft;
0108         } else {
0109             //assert( (octet7 & 0xE0) == 0xE0 ) // 0b111xxxx
0110             return variant_future;
0111         }
0112     }
0113 
0114     enum version_type
0115     {
0116         version_unknown = -1,
0117         version_time_based = 1,
0118         version_dce_security = 2,
0119         version_name_based_md5 = 3,
0120         version_random_number_based = 4,
0121         version_name_based_sha1 = 5
0122     };
0123     version_type version() const BOOST_NOEXCEPT
0124     {
0125         // version is stored in octet 9
0126         // which is index 6, since indexes count backwards
0127         uint8_t octet9 = data[6];
0128         if ( (octet9 & 0xF0) == 0x10 ) {
0129             return version_time_based;
0130         } else if ( (octet9 & 0xF0) == 0x20 ) {
0131             return version_dce_security;
0132         } else if ( (octet9 & 0xF0) == 0x30 ) {
0133             return version_name_based_md5;
0134         } else if ( (octet9 & 0xF0) == 0x40 ) {
0135             return version_random_number_based;
0136         } else if ( (octet9 & 0xF0) == 0x50 ) {
0137             return version_name_based_sha1;
0138         } else {
0139             return version_unknown;
0140         }
0141     }
0142 
0143     // note: linear complexity
0144     void swap(uuid& rhs) BOOST_NOEXCEPT;
0145 
0146 public:
0147     // or should it be array<uint8_t, 16>
0148     uint8_t data[16];
0149 };
0150 
0151 bool operator== (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT;
0152 bool operator< (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT;
0153 
0154 inline bool operator!=(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
0155 {
0156     return !(lhs == rhs);
0157 }
0158 
0159 inline bool operator>(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
0160 {
0161     return rhs < lhs;
0162 }
0163 inline bool operator<=(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
0164 {
0165     return !(rhs < lhs);
0166 }
0167 
0168 inline bool operator>=(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
0169 {
0170     return !(lhs < rhs);
0171 }
0172 
0173 inline void swap(uuid& lhs, uuid& rhs) BOOST_NOEXCEPT
0174 {
0175     lhs.swap(rhs);
0176 }
0177 
0178 // This is equivalent to boost::hash_range(u.begin(), u.end());
0179 inline std::size_t hash_value(uuid const& u) BOOST_NOEXCEPT
0180 {
0181     std::size_t seed = 0;
0182     for(uuid::const_iterator i=u.begin(), e=u.end(); i != e; ++i)
0183     {
0184         seed ^= static_cast<std::size_t>(*i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
0185     }
0186 
0187     return seed;
0188 }
0189 
0190 }} //namespace boost::uuids
0191 
0192 #ifndef BOOST_UUID_NO_TYPE_TRAITS
0193 // type traits specializations
0194 namespace boost {
0195 
0196 template <>
0197 struct is_pod<uuids::uuid> : true_type {};
0198 
0199 } // namespace boost
0200 #endif
0201 
0202 #if defined(BOOST_UUID_USE_SSE2)
0203 #include <boost/uuid/detail/uuid_x86.ipp>
0204 #else
0205 #include <boost/uuid/detail/uuid_generic.ipp>
0206 #endif
0207 
0208 #if defined(_MSC_VER)
0209 #pragma warning(pop) // Restore warnings to previous state.
0210 #endif
0211 
0212 #endif // BOOST_UUID_HPP