123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- #ifndef BOOST_UUID_HPP
- #define BOOST_UUID_HPP
- #include <cstddef>
- #include <boost/cstdint.hpp>
- #include <boost/uuid/detail/config.hpp>
- #ifndef BOOST_UUID_NO_TYPE_TRAITS
- #include <boost/type_traits/is_pod.hpp>
- #include <boost/type_traits/integral_constant.hpp>
- #endif
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- #if defined(_MSC_VER)
- #pragma warning(push)
- #pragma warning(disable : 4996)
- #endif
- #ifdef BOOST_NO_STDC_NAMESPACE
- namespace std {
- using ::size_t;
- using ::ptrdiff_t;
- }
- #endif
- namespace boost {
- namespace uuids {
- struct uuid
- {
- public:
- typedef uint8_t value_type;
- typedef uint8_t& reference;
- typedef uint8_t const& const_reference;
- typedef uint8_t* iterator;
- typedef uint8_t const* const_iterator;
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
-
-
-
-
- static BOOST_CONSTEXPR size_type static_size() BOOST_NOEXCEPT { return 16; }
- public:
- iterator begin() BOOST_NOEXCEPT { return data; }
- const_iterator begin() const BOOST_NOEXCEPT { return data; }
- iterator end() BOOST_NOEXCEPT { return data+size(); }
- const_iterator end() const BOOST_NOEXCEPT { return data+size(); }
- BOOST_CONSTEXPR size_type size() const BOOST_NOEXCEPT { return static_size(); }
- bool is_nil() const BOOST_NOEXCEPT;
- enum variant_type
- {
- variant_ncs,
- variant_rfc_4122,
- variant_microsoft,
- variant_future
- };
- variant_type variant() const BOOST_NOEXCEPT
- {
-
-
- unsigned char octet7 = data[8];
- if ( (octet7 & 0x80) == 0x00 ) {
- return variant_ncs;
- } else if ( (octet7 & 0xC0) == 0x80 ) {
- return variant_rfc_4122;
- } else if ( (octet7 & 0xE0) == 0xC0 ) {
- return variant_microsoft;
- } else {
-
- return variant_future;
- }
- }
- enum version_type
- {
- version_unknown = -1,
- version_time_based = 1,
- version_dce_security = 2,
- version_name_based_md5 = 3,
- version_random_number_based = 4,
- version_name_based_sha1 = 5
- };
- version_type version() const BOOST_NOEXCEPT
- {
-
-
- uint8_t octet9 = data[6];
- if ( (octet9 & 0xF0) == 0x10 ) {
- return version_time_based;
- } else if ( (octet9 & 0xF0) == 0x20 ) {
- return version_dce_security;
- } else if ( (octet9 & 0xF0) == 0x30 ) {
- return version_name_based_md5;
- } else if ( (octet9 & 0xF0) == 0x40 ) {
- return version_random_number_based;
- } else if ( (octet9 & 0xF0) == 0x50 ) {
- return version_name_based_sha1;
- } else {
- return version_unknown;
- }
- }
-
- void swap(uuid& rhs) BOOST_NOEXCEPT;
- public:
-
- uint8_t data[16];
- };
- bool operator== (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT;
- bool operator< (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT;
- inline bool operator!=(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
- {
- return !(lhs == rhs);
- }
- inline bool operator>(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
- {
- return rhs < lhs;
- }
- inline bool operator<=(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
- {
- return !(rhs < lhs);
- }
- inline bool operator>=(uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
- {
- return !(lhs < rhs);
- }
- inline void swap(uuid& lhs, uuid& rhs) BOOST_NOEXCEPT
- {
- lhs.swap(rhs);
- }
- inline std::size_t hash_value(uuid const& u) BOOST_NOEXCEPT
- {
- std::size_t seed = 0;
- for(uuid::const_iterator i=u.begin(), e=u.end(); i != e; ++i)
- {
- seed ^= static_cast<std::size_t>(*i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
- }
- return seed;
- }
- }}
- #ifndef BOOST_UUID_NO_TYPE_TRAITS
- namespace boost {
- template <>
- struct is_pod<uuids::uuid> : true_type {};
- }
- #endif
- #if defined(BOOST_UUID_USE_SSE2)
- #include <boost/uuid/detail/uuid_x86.ipp>
- #else
- #include <boost/uuid/detail/uuid_generic.ipp>
- #endif
- #if defined(_MSC_VER)
- #pragma warning(pop)
- #endif
- #endif
|