CFx SDK Documentation  2023 SP0
TrVisUniqueId.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 // GLES2 dynamic unique ID declaration
24 
25 #ifndef ODTRVISUNIQUEID
26 #define ODTRVISUNIQUEID
27 
28 #include "TD_PackPush.h"
29 
30 #include "TrVisDefs.h"
31 #include "OdAnsiString.h"
32 #include "ExGsHelpers.h"
33 
38 {
39  public:
40  enum IDType
41  {
45  };
46  protected:
50  public:
52  : m_entryId(0)
53  , m_entryData(0)
54  , m_entryType(0)
55  {
56  }
58  : m_entryId(ui.m_entryId)
61  {
62  }
63  OdTrVisUniqueID(OdUInt64 entryId, OdUInt32 entryType = kTransientID, OdUInt64 entryData = 0)
64  : m_entryId(entryId), m_entryData(entryData), m_entryType(entryType)
65  {
66  }
67 
69  {
70  if (this == &ui)
71  return *this;
72  m_entryId = ui.m_entryId;
75  return *this;
76  }
77 
78  bool operator ==(const OdTrVisUniqueID &ui) const
79  {
80  return (m_entryId == ui.m_entryId) &&
81  (m_entryData == ui.m_entryData) &&
82  (m_entryType == ui.m_entryType);
83  }
84  bool operator !=(const OdTrVisUniqueID &ui) const
85  {
86  return (m_entryId != ui.m_entryId) ||
87  (m_entryData != ui.m_entryData) ||
88  (m_entryType != ui.m_entryType);
89  }
90 
91  bool isValid() const { return (m_entryId != 0) || (m_entryData != 0); }
92 
93  void setId(OdUInt64 nId) { m_entryId = nId; }
94  void setId(const void *pId) { m_entryId = OdTrVisPtrToId(pId); }
95  OdUInt64 getId() const { return m_entryId; }
96  OdDbStub *persistentId() const { return OdTrVisIdToPtr(OdDbStub, m_entryId); }
97 
98  void setData(OdUInt64 nData) { m_entryData = nData; }
99  OdUInt64 getData() const { return m_entryData; }
100 
102  bool isPersistent() const { return m_entryType == kPersistentID; }
104  bool isTransient() const { return m_entryType == kTransientID; }
105  void setUtilitary(OdUInt32 utCode = kUtilitaryID) { m_entryType = utCode; }
106  bool isUtilitary() const { return m_entryType >= kUtilitaryID; }
107  OdUInt32 getType() const { return m_entryType; }
108 
109  static int compare(const OdTrVisUniqueID &t1, const OdTrVisUniqueID &t2)
110  {
111  if (t1.m_entryId != t2.m_entryId)
112  return (t1.m_entryId < t2.m_entryId) ? -1 : 1;
113  if (t1.m_entryType != t2.m_entryType)
114  return (t1.m_entryType < t2.m_entryType) ? -1 : 1;
115  if (t1.m_entryData != t2.m_entryData)
116  return (t1.m_entryData < t2.m_entryData) ? -1 : 1;
117  return 0;
118  }
119  //bool operator ==(const OdTrVisUniqueID &t2) const { return compare(*this, t2) == 0; }
120  //bool operator !=(const OdTrVisUniqueID &t2) const { return compare(*this, t2) != 0; }
121  bool operator <(const OdTrVisUniqueID &t2) const { return compare(*this, t2) < 0; }
122  bool operator <=(const OdTrVisUniqueID &t2) const { return compare(*this, t2) <= 0; }
123  bool operator >(const OdTrVisUniqueID &t2) const { return compare(*this, t2) > 0; }
124  bool operator >=(const OdTrVisUniqueID &t2) const { return compare(*this, t2) >= 0; }
125 
126  // OdTrVisUniqueID -> OdAnsiString transformers
127 
129  {
130  public:
131  virtual void append(OdAnsiString &to, OdDbStub* from) const = 0;
132  virtual void append(OdAnsiString &to, OdUInt32 from) const = 0;
133  virtual void append(OdAnsiString &to, OdUInt64 from) const = 0;
134  virtual char delimiter() const { return '_'; }
135  };
137  {
138  public:
139  virtual void append(OdAnsiString &to, OdDbStub* from) const
140  {
141  append(to, OdTrVisPtrToId(from));
142  }
143  virtual void append(OdAnsiString &to, OdUInt32 from) const
144  {
145  OdAnsiString formatter;
146  formatter.format("%u", (unsigned)from);
147  to += formatter;
148  }
149  virtual void append(OdAnsiString &to, OdUInt64 from) const
150  {
151  char fromChr[18];
152  fromChr[::ExGsMakeHex(from, fromChr)] = 0;
153  to += fromChr;
154  }
155  virtual char delimiter() const { return '-'; }
156  };
157 
158  OdAnsiString transform(const UIDTransformer &transformer = DefUIDTransformer()) const
159  {
160  OdAnsiString formatter;
161  if (isPersistent())
162  transformer.append(formatter, persistentId());
163  else
164  {
165  transformer.append(formatter, getId());
166  formatter += transformer.delimiter();
167  transformer.append(formatter, getType());
168  }
169  if (getData() || !isPersistent())
170  {
171  // Persistent ID can have single or two elements. Other types will have three elements always, elsewhere them cannot be unparsed.
172  formatter += transformer.delimiter();
173  transformer.append(formatter, getData());
174  }
175  return formatter;
176  }
177 
179  {
180  public:
181  virtual OdDbStub *makeStub(const char *pStr) const = 0;
182  virtual OdUInt32 makeUInt32(const char *pStr) const = 0;
183  virtual OdUInt64 makeUInt64(const char *pStr) const = 0;
184  virtual char delimiter() const { return '_'; }
185  };
187  {
188  public:
189  virtual OdDbStub *makeStub(const char *pStr) const
190  {
191  return OdTrVisIdToPtr(OdDbStub, makeUInt64(pStr));
192  }
193  virtual OdUInt32 makeUInt32(const char *pStr) const
194  {
195  OdUInt32 nVal = 0;
196  while ((*pStr >= '0') && (*pStr <= '9'))
197  {
198  nVal = nVal * 10 + OdUInt32(*pStr - '0');
199  pStr++;
200  }
201  return nVal;
202  }
203  virtual OdUInt64 makeUInt64(const char *pStr) const
204  {
205  OdUInt64 nVal = 0;
206  while (((*pStr >= '0') && (*pStr <= '9')) ||
207  ((*pStr >= 'a') && (*pStr <= 'f')) ||
208  ((*pStr >= 'A') && (*pStr <= 'F')))
209  {
210  OdUInt64 mx = 0;
211  if ((*pStr >= '0') && (*pStr <= '9'))
212  mx = OdUInt64(*pStr - '0');
213  else if ((*pStr >= 'a') && (*pStr <= 'f'))
214  mx = OdUInt64(*pStr - 'a') + 10;
215  else if ((*pStr >= 'A') && (*pStr <= 'F'))
216  mx = OdUInt64(*pStr - 'A') + 10;
217  nVal = (nVal << 4) | mx;
218  pStr++;
219  }
220  return nVal;
221  }
222  virtual char delimiter() const { return '-'; }
223  };
224 
225  OdTrVisUniqueID &untransform(const char *pStr, const UIDUnTransformer &untransformer = DefUIDUnTransformer())
226  {
227  const char *pStr1 = pStr;
228  const char *pStr2 = NULL, *pStr3 = NULL;
229  while (*pStr && !pStr3)
230  {
231  if (*pStr == untransformer.delimiter())
232  {
233  if (!pStr2) pStr2 = pStr + 1;
234  else pStr3 = pStr + 1;
235  }
236  pStr++;
237  }
238  if (!pStr3)
239  { // Persistent id
240  setId(untransformer.makeStub(pStr1));
241  setPersistent();
242  if (pStr2)
243  setData(untransformer.makeUInt64(pStr2));
244  }
245  else
246  { // Transient or utilitary
247  setId(untransformer.makeUInt64(pStr1));
248  setUtilitary(untransformer.makeUInt32(pStr2));
249  setData(untransformer.makeUInt64(pStr3));
250  }
251  return *this;
252  }
253 
254  OdTrVisUniqueID(const OdAnsiString& asValue, const UIDUnTransformer &untransformer = DefUIDUnTransformer())
255  : m_entryId(0)
256  , m_entryData(0)
257  , m_entryType(0)
258  {
259  untransform(asValue, untransformer);
260  }
261 };
262 
263 #include "TD_PackPop.h"
264 
265 #endif // ODTRVISUNIQUEID
#define NULL
Definition: GsProperties.h:177
unsigned int OdUInt32
#define OdTrVisPtrToId(ptr)
Definition: TrVisDefs.h:107
#define OdTrVisIdToPtr(ptrType, id)
Definition: TrVisDefs.h:108
virtual void append(OdAnsiString &to, OdUInt64 from) const
virtual void append(OdAnsiString &to, OdDbStub *from) const
virtual void append(OdAnsiString &to, OdUInt32 from) const
virtual OdDbStub * makeStub(const char *pStr) const
virtual OdUInt64 makeUInt64(const char *pStr) const
virtual OdUInt32 makeUInt32(const char *pStr) const
virtual void append(OdAnsiString &to, OdUInt32 from) const =0
virtual void append(OdAnsiString &to, OdUInt64 from) const =0
virtual char delimiter() const
virtual void append(OdAnsiString &to, OdDbStub *from) const =0
virtual char delimiter() const
virtual OdUInt32 makeUInt32(const char *pStr) const =0
virtual OdDbStub * makeStub(const char *pStr) const =0
virtual OdUInt64 makeUInt64(const char *pStr) const =0
bool operator>=(const OdTrVisUniqueID &t2) const
bool operator<=(const OdTrVisUniqueID &t2) const
OdUInt64 m_entryData
Definition: TrVisUniqueId.h:48
OdTrVisUniqueID(const OdAnsiString &asValue, const UIDUnTransformer &untransformer=DefUIDUnTransformer())
bool operator<(const OdTrVisUniqueID &t2) const
OdDbStub * persistentId() const
Definition: TrVisUniqueId.h:96
bool operator>(const OdTrVisUniqueID &t2) const
void setData(OdUInt64 nData)
Definition: TrVisUniqueId.h:98
OdUInt64 m_entryId
Definition: TrVisUniqueId.h:47
OdUInt64 getData() const
Definition: TrVisUniqueId.h:99
OdTrVisUniqueID(const OdTrVisUniqueID &ui)
Definition: TrVisUniqueId.h:57
bool isTransient() const
bool operator==(const OdTrVisUniqueID &ui) const
Definition: TrVisUniqueId.h:78
bool isPersistent() const
static int compare(const OdTrVisUniqueID &t1, const OdTrVisUniqueID &t2)
void setId(const void *pId)
Definition: TrVisUniqueId.h:94
void setId(OdUInt64 nId)
Definition: TrVisUniqueId.h:93
OdUInt32 m_entryType
Definition: TrVisUniqueId.h:49
OdAnsiString transform(const UIDTransformer &transformer=DefUIDTransformer()) const
OdUInt64 getId() const
Definition: TrVisUniqueId.h:95
void setUtilitary(OdUInt32 utCode=kUtilitaryID)
OdUInt32 getType() const
OdTrVisUniqueID & untransform(const char *pStr, const UIDUnTransformer &untransformer=DefUIDUnTransformer())
bool operator!=(const OdTrVisUniqueID &ui) const
Definition: TrVisUniqueId.h:84
OdTrVisUniqueID & operator=(const OdTrVisUniqueID &ui)
Definition: TrVisUniqueId.h:68
bool isValid() const
Definition: TrVisUniqueId.h:91
bool isUtilitary() const
OdTrVisUniqueID(OdUInt64 entryId, OdUInt32 entryType=kTransientID, OdUInt64 entryData=0)
Definition: TrVisUniqueId.h:63