- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ptruid.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef QI_PTRUID_HPP
3 #define QI_PTRUID_HPP
4
5 #include <array>
6 #include <iosfwd>
7 #include <numeric>
8 #include <boost/config.hpp> // for BOOST_CONSTEXPR, et al.
9 #include <boost/functional/hash.hpp>
10 #include <qi/uuid.hpp>
11 #include <qi/api.hpp>
12 #include <qi/assert.hpp>
13 #include <ka/macroregular.hpp>
14
15 namespace qi
16 {
33 class QI_API PtrUid
34 {
35 using Digest = std::array<uint32_t, 5>;
36 using U32Iterator = Digest::iterator;
37 using U32ConstIterator = Digest::const_iterator;
38
39 Digest digest;
40
41 template<typename T>
42 static uint8_t* toUInt8Ptr(T* a)
43 {
44 return reinterpret_cast<uint8_t*>(a);
45 }
46
47 template<typename T>
48 static const uint8_t* toUInt8Ptr(const T* a)
49 {
50 return reinterpret_cast<const uint8_t*>(a);
51 }
52
53 public:
54 explicit PtrUid(const Uuid& machineUuid, const Uuid& processUuid, const void* ptr);
55
56 // Regular: copy, assignment and destruction by default
57 PtrUid() : digest()
58 {
59 }
60
61 KA_GENERATE_FRIEND_REGULAR_OPS_1(PtrUid, digest)
62
63 // OStreamable:
64 friend QI_API std::ostream& operator<<(std::ostream& o, const PtrUid& uid);
65
66 // Sequence:
67 friend uint8_t* begin(PtrUid& a) BOOST_NOEXCEPT
68 {
69 return toUInt8Ptr(&*beginUInt32(a));
70 }
71
72 friend uint8_t* end(PtrUid& a) BOOST_NOEXCEPT
73 {
74 return begin(a) + size(a);
75 }
76
77 friend const uint8_t* begin(const PtrUid& a) BOOST_NOEXCEPT
78 {
79 return begin(const_cast<PtrUid&>(a)); // const_cast is safe here.
80 }
81
82 friend const uint8_t* end(const PtrUid& a) BOOST_NOEXCEPT
83 {
84 return end(const_cast<PtrUid&>(a)); // const_cast is safe here.
85 }
86
87 friend BOOST_CONSTEXPR size_t size(const PtrUid&) BOOST_NOEXCEPT
88 {
89 return sizeof(Digest) / sizeof(uint8_t);
90 }
91
92 friend BOOST_CONSTEXPR bool empty(const PtrUid& a) BOOST_NOEXCEPT
93 {
94 return false;
95 }
96
98 const uint8_t& operator[](size_t n) const BOOST_NOEXCEPT
99 {
100 QI_ASSERT(n < size(*this));
101 return begin(*this)[n];
102 }
103
104 // Custom:
105 friend U32Iterator beginUInt32(PtrUid& a) BOOST_NOEXCEPT
106 {
107 return begin(a.digest);
108 }
109
110 friend U32Iterator endUInt32(PtrUid& a) BOOST_NOEXCEPT
111 {
112 return end(a.digest);
113 }
114
115 friend U32ConstIterator beginUInt32(const PtrUid& a) BOOST_NOEXCEPT
116 {
117 return begin(a.digest);
118 }
119
120 friend U32ConstIterator endUInt32(const PtrUid& a) BOOST_NOEXCEPT
121 {
122 return end(a.digest);
123 }
124 };
125
126 } // namespace qi
127
128 // Hashable:
129 namespace std
130 {
131 template<>
132 struct hash<qi::PtrUid>
133 {
134 std::size_t operator()(const qi::PtrUid& p) const
135 {
136 static_assert(sizeof(std::size_t) >= sizeof(*beginUInt32(p)),
137 "A std::size_t must be large enough to store a uint32_t.");
138 return boost::hash_range(beginUInt32(p), endUInt32(p));
139 }
140 };
141
142 } // namespace std
143
144 #endif
qi::PtrUid::endUInt32
friend U32ConstIterator endUInt32(const PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:120
QI_API
#define QI_API
Definition: api.hpp:33
qi::PtrUid::beginUInt32
friend U32ConstIterator beginUInt32(const PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:115
qi::PtrUid::end
friend uint8_t * end(PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:72
QI_ASSERT
#define QI_ASSERT(expr__)
Definition: assert.hpp:27
qi::PtrUid::operator[]
const uint8_t & operator[](size_t n) const BOOST_NOEXCEPT
Return a const ref to allow the address of the element to be taken.
Definition: ptruid.hpp:98
api.hpp
dll import/export and compiler message
qi::PtrUid::beginUInt32
friend U32Iterator beginUInt32(PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:105
qi::PtrUid::PtrUid
PtrUid()
Definition: ptruid.hpp:57
qi::PtrUid::endUInt32
friend U32Iterator endUInt32(PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:110
qi::PtrUid::begin
friend const uint8_t * begin(const PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:77
qi::uint8_t
uint8_t uint8_t
Definition: types.hpp:63
qi::PtrUid::empty
friend BOOST_CONSTEXPR bool empty(const PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:92
qi::Uuid
boost::uuids::uuid Uuid
Definition: uuid.hpp:12
assert.hpp
qi::PtrUid::end
friend const uint8_t * end(const PtrUid &a) BOOST_NOEXCEPT
Definition: ptruid.hpp:82
qi::PtrUid::size
friend BOOST_CONSTEXPR size_t size(const PtrUid &) BOOST_NOEXCEPT
Definition: ptruid.hpp:87
std::hash< qi::PtrUid >::operator()
std::size_t operator()(const qi::PtrUid &p) const
Definition: ptruid.hpp:134
uuid.hpp
qi::PtrUid
Definition: ptruid.hpp:33