VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
uuid.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2022 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include "vrfutil/vrfutilDefines.h"
14 #include <boost/uuid/uuid.hpp>
15 #include <vlutil/vlUuid.h>
16 #include <boost/serialization/access.hpp>
17 #include <boost/serialization/nvp.hpp>
18 
20 
23 {
24 public:
25  virtual void uuidChanged() = 0;
26 };
27 
31 {
32 public:
34  virtual DtString markingText() = 0;
35  virtual DtUUIDMarkingTextProvider* clone() const = 0;
36 
37  operator DtString () { return markingText(); };
38 };
39 
42 {
43 public:
46 
47  virtual ~DtMarkingTextStringProvider();
48 
49  virtual void setMarkingText(const DtString& s) { myMarkingText = s; };
50  virtual DtString markingText() override { return myMarkingText; };
51 
52  virtual DtUUIDMarkingTextProvider* clone() const override;
53 
54 protected:
56 };
57 
60 {
61 protected:
62  enum UUIDType
63  {
64  NOTSET = 0,
65  BOOST = 1,
66  STRING = 2,
67  UUIDSTRING = 3
68  };
69 
70 public:
72  DtUUID(DtUUIDOwner* = nullptr);
73  DtUUID(const DtUUID&, DtUUIDOwner* = nullptr);
74  DtUUID(const boost::uuids::uuid&, DtUUIDOwner* = nullptr);
75  DtUUID(const DtVrlUuid&, DtUUIDOwner* = nullptr);
76 
82  explicit DtUUID(const DtString&, DtUUIDOwner* = nullptr, bool blockMarkingTextLookup = false);
83  explicit DtUUID(const std::string&, DtUUIDOwner* = nullptr, bool blockMarkingTextLookup = false);
84  explicit DtUUID(const char*, DtUUIDOwner* = nullptr, bool blockMarkingTextLookup = false);
85 
87  explicit DtUUID(const unsigned char* data, size_t dataLength, DtUUIDOwner* = nullptr);
88 
89  DtUUID& operator=(const DtUUID & orig);
90  DtUUID& operator=(const boost::uuids::uuid & orig);
91  DtUUID& operator=(const DtVrlUuid&);
92  bool operator<(const DtUUID & rhs) const;
93  bool operator>(const DtUUID & rhs) const;
94 
95  virtual ~DtUUID();
96 
98  const char* data() const
99  {
100  return &myData[0];
101  }
102 
103  unsigned int dataSize() const
104  {
105  return sizeof(myData);
106  }
107 
108  void setBuffer(const char*);
109 
111  static bool isVrfUUID(const DtString&);
112 
113  bool isBoostUUID() const;
114  bool isVrfUUID() const;
115 
116  UUIDType uuidType() const;
117 
119  virtual void setUUID(const DtString&, bool blockMarkingTextLookup = false);
120  virtual void setUUID(const DtVrlUuid&);
121  virtual const DtString& uuidString() const;
122 
127  static DtString uuidMarking();
128 
130  static DtUUID makeStringUUID(const DtString&);
131 
133  virtual void setMarkingText(const DtString&);
134 
137  virtual void setStringUUID(const DtString&);
138 
140  virtual void generateUUID();
141 
143  virtual void clearUUID();
144 
145  virtual DtVrlUuid vrlUuid() const;
146 
147  bool operator==(const DtString&) const;
148  bool operator==(const std::string&) const;
149  bool operator==(const char*) const;
150  bool operator==(const DtUUID&) const;
151  bool operator==(const DtVrlUuid&) const;
152  //bool operator==(const DtRwUUID&) const;
153 
154  bool operator!=(const DtUUID& rhs) const { return !(*this == rhs); };
155  bool operator!=(const DtString& rhs) const { return !(*this == rhs); };
156  //bool operator!=(const DtRwUUID& rhs) const { return !(*this == rhs); };
157  bool operator!=(const DtVrlUuid& rhs) const { return !(*this == rhs); };
158 
159  virtual bool isValid() const;
160  virtual bool isStringUUID() const;
161 
163  size_t hashValue() const;
164 
165  boost::uuids::uuid uuid() const
166  {
167  return asBoostUUID();
168  }
169 
170  boost::uuids::uuid asBoostUUID() const;
171 
172  static const DtUUID& nullUUID();
173 
175  virtual DtString markingText() const;
176 
178  std::string string() const;
179 
181  static DtObjectIdentificationResolver& objectIdentificationResolver();
182 
183  //-------------------------------------------
186 
188  DtString objectType() const override;
189 
191  DtString serialize() override;
192 
195  bool deserialize(const DtString& data) override;
196 
198  static DtAsciiSerializable* creator();
200 
201  static bool isValidBoostUUIDString(const DtString& str);
202 
203  virtual size_t calcHashValue() const;
204 
205  bool addedForUpgrade() const
206  {
207  return myAddedForUpgrade;
208  }
209 
210  void setAddedForUpgrade(bool b)
211  {
212  myAddedForUpgrade = b;
213  }
214 
215 protected:
216  friend class boost::serialization::access;
217 
221  template<class Archive>
222  void serialize(Archive & ar, const unsigned int version)
223  {
224  if (Archive::is_loading::value)
225  {
226  std::string uuidS;
227 
228  ar & BOOST_SERIALIZATION_NVP(uuidS);
229 
230  setUUID(uuidS.c_str());
231  }
232  else
233  {
234  std::string uuidS = uuidString().c_str();
235 
236  ar & BOOST_SERIALIZATION_NVP(uuidS);
237  }
238  }
239 
240 protected:
241  virtual void convertStringToData(const std::string&);
242  virtual boost::uuids::uuid convertToBoostUUID(const DtString&);
243  virtual boost::uuids::uuid convertStringToBoostUUID(const DtString&, bool blockMarkingTextLookup = false);
244  virtual const char* convertStringToStringUUID(const char* t) const;
245 
246 protected:
249  char myData[36];
250 
254 
257 
259 
260  size_t myHashValue;
262 };
263 
264 DT_DLL_vrfutil std::size_t hash_value(DtUUID const& b);
265 DT_DLL_vrfutil std::size_t hash_value(DtString const& b);
266 
267 template <>
268 struct std::hash<DtUUID>
269 {
270  std::size_t operator()(const DtUUID& s) const
271  {
272  return s.hashValue();
273  }
274 };
DtString myMarkingText
Definition: uuid.h:55
UUID is a unique ID wrapper class.
Definition: uuid.h:59
virtual DtString markingText() override
Definition: uuid.h:50
bool addedForUpgrade() const
Definition: uuid.h:205
Definition: asciiSerializable.h:38
virtual bool deserialize(const DtString &)=0
This function should take the string that was serialized via serialize() and fill this object with th...
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
virtual DtString serialize()=0
The following characters are reserved and cannot be used in serialization: &#39;|&#39;, &#39;:&#39;.
static DtObjectIdentificationResolver theObjectIdentificationResolver
Definition: uuid.h:258
size_t myHashValue
Definition: uuid.h:260
bool operator!=(const DtUUID &rhs) const
Definition: uuid.h:154
const char * data() const
Not this also contains the special marker – the actual UUID starts at byte 1.
Definition: uuid.h:98
Optional owner of this UUID. Since the UUID can change when remapped, supply an owner to be notified ...
Definition: uuid.h:22
bool myAddedForUpgrade
Definition: uuid.h:261
std::size_t operator()(const DtUUID &s) const
Definition: uuid.h:270
size_t hashValue() const
If the hashValue is 0 and this is a valid UUID, this will throw a std::runtime_exception.
bool operator>(const DtObjectType &lhs, const DtSimulationModelSetLoader::EntityData &rhs)
Definition: simulationModelSetLoader.h:1393
virtual DtString objectType() const =0
Should return the string name of this object. The object name should not be part of the serialization...
Simple provider that will give the marking text of the object.
Definition: uuid.h:41
DtString myMarkingText
Definition: uuid.h:255
std::size_t hash_value(const DtNodeBoundingInfoPtr &p)
needed for boost::unordered
Definition: boundingNodeInfo.h:89
UUIDType
Definition: uuid.h:62
virtual ~DtUUIDMarkingTextProvider()
Definition: uuid.h:33
virtual void setMarkingText(const DtString &s)
Definition: uuid.h:49
bool operator!=(const DtString &rhs) const
Definition: uuid.h:155
DtUUIDOwner * myOwner
Definition: uuid.h:256
DtString myUUIDString
If the assignment is not a valid boost UUID then the string UUID is what is used. ...
Definition: uuid.h:253
Definition: objectIdentificationResolver.h:29
#define DT_DLL_vrfutil
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfutilDefines.h:34
virtual DtUUIDMarkingTextProvider * clone() const =0
void setAddedForUpgrade(bool b)
Definition: uuid.h:210
unsigned int dataSize() const
Definition: uuid.h:103
void serialize(Archive &ar, const unsigned int version)
When the class Archive corresponds to an output archive, the &amp; operator is defined similar to &lt;&lt;...
Definition: uuid.h:222
To allow for faster marking text lookups, the DtUUIDMarkingTextProvider class wraps an object that wi...
Definition: uuid.h:30
bool operator!=(const DtVrlUuid &rhs) const
Definition: uuid.h:157
boost::uuids::uuid uuid() const
Definition: uuid.h:165

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)