25 #ifndef INCLUDED_TypeSafeId_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2
26 #define INCLUDED_TypeSafeId_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2
41 template <
class Tag>
class TypeSafeId;
43 template <
class Tag>
class TypeSafeIdRefAccessorBase;
46 namespace typesafeid_traits {
49 template <
typename Tag>
struct WrappedType {
typedef uint32_t type; };
55 enum { value =
true };
67 enum { value =
false };
74 TypeSafeIdRefAccessorBase<Tag>,
82 typedef typename WrappedType<Tag>::type wrapped_type;
83 static wrapped_type
get() {
84 return std::numeric_limits<wrapped_type>::max();
110 typedef typename typesafeid_traits::WrappedType<Tag>::type
wrapped_type;
129 wrapped_type
value()
const {
return m_val; }
140 class TypeSafeIdRefAccessorBase :
public TypeSafeIdBase<Tag> {
142 typedef TypeSafeIdBase<Tag> Base;
143 typedef typename typesafeid_traits::WrappedType<Tag>::type wrapped_type;
144 TypeSafeIdRefAccessorBase() : Base() {}
145 explicit TypeSafeIdRefAccessorBase(wrapped_type val) : Base(val) {}
146 TypeSafeIdRefAccessorBase(TypeSafeIdRefAccessorBase
const &other)
152 wrapped_type &
value() {
return Base::m_val; }
156 class TypeSafeId :
public typesafeid_traits::ComputeBaseClass<Tag>::type {
159 typedef TypeSafeId<Tag> type;
161 typedef typename typesafeid_traits::ComputeBaseClass<Tag>::type Base;
162 typedef typename typesafeid_traits::WrappedType<Tag>::type wrapped_type;
163 TypeSafeId() : Base() {}
164 explicit TypeSafeId(wrapped_type val) : Base(val) {}
165 TypeSafeId(TypeSafeId
const &other) : Base(other) {}
170 template <
typename Tag>
171 inline bool operator==(TypeSafeId<Tag>
const a, TypeSafeId<Tag>
const b) {
172 return a.value() == b.value();
177 template <
typename Tag>
178 inline bool operator!=(TypeSafeId<Tag>
const a, TypeSafeId<Tag>
const b) {
179 return a.value() != b.value();
185 #endif // INCLUDED_TypeSafeId_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2
TypeSafeIdBase(wrapped_type val)
Explicit constructor from the wrapped type.
static wrapped_type sentinel()
Utility function to access the SentinelValue trait.
bool empty() const
Check whether the ID is empty/invalid.
wrapped_type value() const
Read-only accessor to the (non-type-safe!) wrapped value.
Header wrapping the C99 standard stdint header.
The main namespace for all C++ elements of the framework, internal and external.
Quick C++11-aligned conditional (if/then/elese) implementation.
static type invalid()
Static factory method to return an invalid/empty ID.
Header containing some basic, C++11-aligned implementations of functionality provided by
A generic typesafe (as long as you use differing tag types) wrapper for identifiers (typically intege...
Explicitly specialize for your tag type if you want a different signal value for invalid/empty: defau...
TypeSafeId< Tag > type
The "public" type of the current class.
Explicitly specialize for your tag type if you want a different underlying type.
bool operator==(const OSVR_TimeValue &tvA, const OSVR_TimeValue &tvB)
Operator == overload for time values.
typesafeid_traits::WrappedType< Tag >::type wrapped_type
The contained/wrapped type.
bool operator!=(const OSVR_TimeValue &tvA, const OSVR_TimeValue &tvB)
Operator == overload for time values.
TypeSafeIdBase(TypeSafeIdBase const &other)
Copy constructor.