CFx SDK Documentation  2020SP3
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
OdTrVisUniqueID::operator>
bool operator>(const OdTrVisUniqueID &t2) const
Definition: TrVisUniqueId.h:123
OdTrVisUniqueID::DefUIDUnTransformer
Definition: TrVisUniqueId.h:187
NULL
#define NULL
Definition: GsProperties.h:177
OdTrVisUniqueID::isTransient
bool isTransient() const
Definition: TrVisUniqueId.h:104
OdTrVisUniqueID::kTransientID
@ kTransientID
Definition: TrVisUniqueId.h:43
OdTrVisUniqueID::m_entryType
OdUInt32 m_entryType
Definition: TrVisUniqueId.h:49
OdTrVisUniqueID::UIDUnTransformer::delimiter
virtual char delimiter() const
Definition: TrVisUniqueId.h:184
OdTrVisUniqueID::untransform
OdTrVisUniqueID & untransform(const char *pStr, const UIDUnTransformer &untransformer=DefUIDUnTransformer())
Definition: TrVisUniqueId.h:225
OdTrVisUniqueID::UIDTransformer::append
virtual void append(OdAnsiString &to, OdUInt32 from) const =0
OdTrVisPtrToId
#define OdTrVisPtrToId(ptr)
Definition: TrVisDefs.h:107
OdTrVisUniqueID::setData
void setData(OdUInt64 nData)
Definition: TrVisUniqueId.h:98
OdTrVisIdToPtr
#define OdTrVisIdToPtr(ptrType, id)
Definition: TrVisDefs.h:108
OdTrVisUniqueID::getType
OdUInt32 getType() const
Definition: TrVisUniqueId.h:107
OdTrVisUniqueID::m_entryData
OdUInt64 m_entryData
Definition: TrVisUniqueId.h:48
OdTrVisUniqueID
Definition: TrVisUniqueId.h:38
OdTrVisUniqueID::DefUIDTransformer::append
virtual void append(OdAnsiString &to, OdUInt32 from) const
Definition: TrVisUniqueId.h:143
OdTrVisUniqueID::UIDTransformer::append
virtual void append(OdAnsiString &to, OdDbStub *from) const =0
OdTrVisUniqueID::OdTrVisUniqueID
OdTrVisUniqueID()
Definition: TrVisUniqueId.h:51
TD_PackPop.h
OdTrVisUniqueID::setPersistent
void setPersistent()
Definition: TrVisUniqueId.h:101
OdTrVisUniqueID::operator!=
bool operator!=(const OdTrVisUniqueID &ui) const
Definition: TrVisUniqueId.h:84
OdTrVisUniqueID::setId
void setId(const void *pId)
Definition: TrVisUniqueId.h:94
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdTrVisUniqueID::DefUIDUnTransformer::makeUInt64
virtual OdUInt64 makeUInt64(const char *pStr) const
Definition: TrVisUniqueId.h:203
OdTrVisUniqueID::isPersistent
bool isPersistent() const
Definition: TrVisUniqueId.h:102
OdTrVisUniqueID::getId
OdUInt64 getId() const
Definition: TrVisUniqueId.h:95
OdTrVisUniqueID::setId
void setId(OdUInt64 nId)
Definition: TrVisUniqueId.h:93
OdTrVisUniqueID::IDType
IDType
Definition: TrVisUniqueId.h:41
OdTrVisUniqueID::UIDUnTransformer::makeUInt64
virtual OdUInt64 makeUInt64(const char *pStr) const =0
OdTrVisUniqueID::UIDUnTransformer
Definition: TrVisUniqueId.h:179
OdTrVisUniqueID::setTransient
void setTransient()
Definition: TrVisUniqueId.h:103
OdTrVisUniqueID::operator==
bool operator==(const OdTrVisUniqueID &ui) const
Definition: TrVisUniqueId.h:78
OdAnsiString.h
OdTrVisUniqueID::OdTrVisUniqueID
OdTrVisUniqueID(const OdTrVisUniqueID &ui)
Definition: TrVisUniqueId.h:57
TrVisDefs.h
OdTrVisUniqueID::setUtilitary
void setUtilitary(OdUInt32 utCode=kUtilitaryID)
Definition: TrVisUniqueId.h:105
OdTrVisUniqueID::DefUIDTransformer
Definition: TrVisUniqueId.h:137
OdTrVisUniqueID::operator=
OdTrVisUniqueID & operator=(const OdTrVisUniqueID &ui)
Definition: TrVisUniqueId.h:68
OdTrVisUniqueID::DefUIDUnTransformer::makeStub
virtual OdDbStub * makeStub(const char *pStr) const
Definition: TrVisUniqueId.h:189
OdTrVisUniqueID::UIDTransformer
Definition: TrVisUniqueId.h:129
OdTrVisUniqueID::DefUIDTransformer::delimiter
virtual char delimiter() const
Definition: TrVisUniqueId.h:155
OdTrVisUniqueID::operator>=
bool operator>=(const OdTrVisUniqueID &t2) const
Definition: TrVisUniqueId.h:124
OdTrVisUniqueID::UIDUnTransformer::makeUInt32
virtual OdUInt32 makeUInt32(const char *pStr) const =0
OdTrVisUniqueID::DefUIDTransformer::append
virtual void append(OdAnsiString &to, OdDbStub *from) const
Definition: TrVisUniqueId.h:139
OdTrVisUniqueID::isValid
bool isValid() const
Definition: TrVisUniqueId.h:91
OdTrVisUniqueID::compare
static int compare(const OdTrVisUniqueID &t1, const OdTrVisUniqueID &t2)
Definition: TrVisUniqueId.h:109
TD_PackPush.h
OdTrVisUniqueID::operator<=
bool operator<=(const OdTrVisUniqueID &t2) const
Definition: TrVisUniqueId.h:122
OdTrVisUniqueID::kPersistentID
@ kPersistentID
Definition: TrVisUniqueId.h:42
OdTrVisUniqueID::UIDTransformer::append
virtual void append(OdAnsiString &to, OdUInt64 from) const =0
OdTrVisUniqueID::OdTrVisUniqueID
OdTrVisUniqueID(OdUInt64 entryId, OdUInt32 entryType=kTransientID, OdUInt64 entryData=0)
Definition: TrVisUniqueId.h:63
OdTrVisUniqueID::kUtilitaryID
@ kUtilitaryID
Definition: TrVisUniqueId.h:44
OdTrVisUniqueID::getData
OdUInt64 getData() const
Definition: TrVisUniqueId.h:99
OdTrVisUniqueID::UIDUnTransformer::makeStub
virtual OdDbStub * makeStub(const char *pStr) const =0
OdTrVisUniqueID::UIDTransformer::delimiter
virtual char delimiter() const
Definition: TrVisUniqueId.h:134
OdTrVisUniqueID::operator<
bool operator<(const OdTrVisUniqueID &t2) const
Definition: TrVisUniqueId.h:121
OdTrVisUniqueID::transform
OdAnsiString transform(const UIDTransformer &transformer=DefUIDTransformer()) const
Definition: TrVisUniqueId.h:158
OdTrVisUniqueID::DefUIDUnTransformer::makeUInt32
virtual OdUInt32 makeUInt32(const char *pStr) const
Definition: TrVisUniqueId.h:193
OdTrVisUniqueID::persistentId
OdDbStub * persistentId() const
Definition: TrVisUniqueId.h:96
OdTrVisUniqueID::OdTrVisUniqueID
OdTrVisUniqueID(const OdAnsiString &asValue, const UIDUnTransformer &untransformer=DefUIDUnTransformer())
Definition: TrVisUniqueId.h:254
OdTrVisUniqueID::DefUIDUnTransformer::delimiter
virtual char delimiter() const
Definition: TrVisUniqueId.h:222
OdTrVisUniqueID::isUtilitary
bool isUtilitary() const
Definition: TrVisUniqueId.h:106
OdUInt64
Definition: Int64.h:137
OdTrVisUniqueID::DefUIDTransformer::append
virtual void append(OdAnsiString &to, OdUInt64 from) const
Definition: TrVisUniqueId.h:149
OdTrVisUniqueID::m_entryId
OdUInt64 m_entryId
Definition: TrVisUniqueId.h:47