Jetson Linux API Reference

36.3 Release
UUID.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2024, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
36 #ifndef _ARGUS_UUID_H
37 #define _ARGUS_UUID_H
38 
39 #include <stdint.h>
40 #include <cstring>
41 #include <cstdio>
42 
43 namespace Argus
44 {
45 
46 static const uint32_t MAX_UUID_NAME_SIZE = 32U;
47 
51 struct UUID
52 {
53  uint32_t time_low;
54  uint16_t time_mid;
56  uint16_t clock_seq;
57  uint8_t node[6];
58 
59  bool operator==(const UUID &r) const
60  {
61  return memcmp(this, &r, sizeof(UUID)) == 0;
62  }
63 
64  bool operator<(const UUID &r) const
65  {
66  return memcmp(this, &r, sizeof(UUID)) < 0;
67  }
68 };
69 
73 class NamedUUID : public UUID
74 {
75 public:
76  NamedUUID(uint32_t time_low_
77  , uint16_t time_mid_
78  , uint16_t time_hi_and_version_
79  , uint16_t clock_seq_
80  , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
81  , const char* name)
82  {
83  time_low = time_low_;
84  time_mid = time_mid_;
85  time_hi_and_version = time_hi_and_version_;
86  clock_seq = clock_seq_;
87  node[0] = c0; node[1] = c1; node[2] = c2; node[3] = c3; node[4] = c4; node[5] = c5;
88  strncpy(m_name, name, sizeof(m_name)-1);
89  m_name[sizeof(m_name)-1] = '\0';
90  }
91 
92  NamedUUID(const NamedUUID& copied)
93  : UUID(copied)
94  {
95  snprintf(m_name, sizeof(m_name), "%s", copied.m_name);
96  }
97 
98  NamedUUID& operator=(const NamedUUID& copied)
99  {
100  static_cast<UUID&>(*this) = copied;
101  snprintf(m_name, sizeof(m_name), "%s", copied.m_name);
102 
103  return *this;
104  }
105 
106  bool operator==(const NamedUUID& compared) const
107  {
108  return static_cast<const UUID&>(*this) == compared;
109  }
110 
111  bool operator!=(const NamedUUID& compared) const
112  {
113  return !(static_cast<const UUID&>(*this) == compared);
114  }
115 
116  const char* getName() const { return m_name; }
117 
118 private:
119  char m_name[MAX_UUID_NAME_SIZE];
120 
121  NamedUUID();
122 };
123 
125 #define DEFINE_UUID(TYPE, NAME, l, s0, s1, s2, c0,c1,c2,c3,c4,c5) \
126  static const TYPE NAME(0x##l, 0x##s0, 0x##s1, 0x##s2, \
127  0x##c0, 0x##c1, 0x##c2, 0x##c3, 0x##c4, 0x##c5, #NAME);
128 
129 #define DEFINE_NAMED_UUID_CLASS(NAME) \
130  class NAME : public NamedUUID \
131  { \
132  public: \
133  NAME(uint32_t time_low_ \
134  , uint16_t time_mid_ \
135  , uint16_t time_hi_and_version_ \
136  , uint16_t clock_seq_ \
137  , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5 \
138  , const char* name) \
139  : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_, \
140  c0, c1, c2, c3, c4, c5, name) \
141  {} \
142  private: \
143  NAME();\
144  };
145 
146 } // namespace Argus
147 
148 #endif // _ARGUS_UUID_H
Argus::MAX_UUID_NAME_SIZE
static const uint32_t MAX_UUID_NAME_SIZE
Definition: UUID.h:46
Argus::NamedUUID
A universally unique identifier with a name (used for debugging purposes).
Definition: UUID.h:73
Argus
Definition: BayerAverageMap.h:39
Argus::UUID::operator<
bool operator<(const UUID &r) const
Definition: UUID.h:64
Argus::UUID::clock_seq
uint16_t clock_seq
Definition: UUID.h:56
Argus::NamedUUID::getName
const char * getName() const
Definition: UUID.h:116
Argus::UUID::time_mid
uint16_t time_mid
Definition: UUID.h:54
Argus::NamedUUID::operator!=
bool operator!=(const NamedUUID &compared) const
Definition: UUID.h:111
Argus::NamedUUID::operator=
NamedUUID & operator=(const NamedUUID &copied)
Definition: UUID.h:98
Argus::UUID::operator==
bool operator==(const UUID &r) const
Definition: UUID.h:59
Argus::NamedUUID::NamedUUID
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)
Definition: UUID.h:76
Argus::UUID
A universally unique identifier.
Definition: UUID.h:51
Argus::NamedUUID::operator==
bool operator==(const NamedUUID &compared) const
Definition: UUID.h:106
Argus::UUID::time_hi_and_version
uint16_t time_hi_and_version
Definition: UUID.h:55
Argus::UUID::node
uint8_t node[6]
Definition: UUID.h:57
Argus::NamedUUID::NamedUUID
NamedUUID(const NamedUUID &copied)
Definition: UUID.h:92
Argus::UUID::time_low
uint32_t time_low
Definition: UUID.h:53