123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #ifndef _ARGUS_UUID_H
- #define _ARGUS_UUID_H
- #include <stdint.h>
- #include <cstring>
- namespace Argus
- {
- const uint32_t MAX_UUID_NAME_SIZE = 32;
- struct UUID
- {
- uint32_t time_low;
- uint16_t time_mid;
- uint16_t time_hi_and_version;
- uint16_t clock_seq;
- uint8_t node[6];
- bool operator==(const UUID &r) const
- {
- return memcmp(this, &r, sizeof(UUID)) == 0;
- }
- bool operator<(const UUID &r) const
- {
- return memcmp(this, &r, sizeof(UUID)) < 0;
- }
- };
- class NamedUUID : public UUID
- {
- public:
- NamedUUID(uint32_t time_low_
- , uint16_t time_mid_
- , uint16_t time_hi_and_version_
- , uint16_t clock_seq_
- , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
- , const char* name)
- {
- time_low = time_low_;
- time_mid = time_mid_;
- time_hi_and_version = time_hi_and_version_;
- clock_seq = clock_seq_;
- node[0] = c0; node[1] = c1; node[2] = c2; node[3] = c3; node[4] = c4; node[5] = c5;
- strncpy(m_name, name, sizeof(m_name)-1);
- m_name[sizeof(m_name)-1] = '\0';
- }
- NamedUUID(const NamedUUID& copied)
- : UUID(copied)
- {
- memcpy(m_name, copied.m_name, (strnlen(copied.m_name, (sizeof(m_name) - 1)) + 1));
- m_name[sizeof(m_name)-1] = '\0';
- }
- NamedUUID& operator=(const NamedUUID& copied)
- {
- static_cast<UUID&>(*this) = copied;
- return *this;
- }
- bool operator==(const NamedUUID& compared) const
- {
- return static_cast<const UUID&>(*this) == compared;
- }
- bool operator!=(const NamedUUID& compared) const
- {
- return !(static_cast<const UUID&>(*this) == compared);
- }
- const char* getName() const { return m_name; }
- private:
- char m_name[MAX_UUID_NAME_SIZE];
- NamedUUID();
- };
- #define DEFINE_UUID(TYPE, NAME, l, s0, s1, s2, c0,c1,c2,c3,c4,c5) \
- static const TYPE NAME(0x##l, 0x##s0, 0x##s1, 0x##s2, \
- 0x##c0, 0x##c1, 0x##c2, 0x##c3, 0x##c4, 0x##c5, #NAME);
- #define DEFINE_NAMED_UUID_CLASS(NAME) \
- class NAME : public NamedUUID \
- { \
- public: \
- NAME(uint32_t time_low_ \
- , uint16_t time_mid_ \
- , uint16_t time_hi_and_version_ \
- , uint16_t clock_seq_ \
- , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5 \
- , const char* name) \
- : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_, \
- c0, c1, c2, c3, c4, c5, name) \
- {} \
- private: \
- NAME();\
- };
- }
- #endif
|