CFx SDK Documentation  2020SP3
TrVisUniqueIdMapping.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 mapping declaration
24 
25 #ifndef ODTRVISUNIQUEIDMAPPING
26 #define ODTRVISUNIQUEIDMAPPING
27 
28 #include "TD_PackPush.h"
29 
30 #include "TrVisRendition.h"
31 #include "TrVisUniqueId.h"
32 
33 #define STL_USING_MAP
34 #include "OdaSTL.h"
35 
39 template<class T>
41 {
42  typedef std::map<T, OdTrVisId> IdMap;
43  mutable IdMap m_idMap[OdTrVisRendition::kNDataTypes];
44  mutable OdTrVisId m_idMapCounters[OdTrVisRendition::kNDataTypes];
45  protected:
47  {
48  if (counter == kTrVisNegativeId)
49  {
50  OdTrVisId id = 101;
51  do
52  {
53  if (!findUID(id, type))
54  return id;
55  id++;
56  } while (id < kTrVisNegativeId);
57  counter = 101;
58  }
59  return counter++;
60  }
61  public:
63  {
64  clean();
65  }
66 
68  {
69  const OdUInt32 nFrom = (type != OdTrVisRendition::kNDataTypes) ? type : 0;
70  const OdUInt32 nTo = (type != OdTrVisRendition::kNDataTypes) ? (type + 1) : type;
71  for (OdUInt32 nType = nFrom; nType < nTo; nType++)
72  {
73  m_idMap[nType].clear();
74  m_idMapCounters[nType] = 101;
75  }
76  }
77 
79  {
80  OD_TYPENAME IdMap::const_iterator it = m_idMap[type].find(uid);
81  if (it != m_idMap[type].end())
82  return it->second;
83  m_idMap[type][uid] = m_idMapCounters[type];
84  return inc(m_idMapCounters[type], type);
85  }
86 
88  {
89  OD_TYPENAME IdMap::iterator it = m_idMap[type].find(uid);
90  if (it != m_idMap[type].end())
91  m_idMap[type].erase(it);
92  }
93 
95  {
96  OD_TYPENAME IdMap::const_iterator it = m_idMap[type].begin();
97  while (it != m_idMap[type].end())
98  {
99  if (it->second == id)
100  return &it->first;
101  it++;
102  }
103  return NULL;
104  }
105 
106  bool hasUID( const T& uid, OdTrVisRendition::DataType type ) const
107  {
108  OD_TYPENAME IdMap::iterator it = m_idMap[type].find(uid);
109  return it != m_idMap[type].end();
110  }
111 
113  {
114  m_idMap[type][uid] = id;
115  }
116 
117  static OdAnsiString asString(const OdTrVisUniqueID &id) { return id.transform(); }
118  static OdTrVisUniqueID asUID(const OdAnsiString &str) { return OdTrVisUniqueID().untransform(str); }
119 };
120 
125 
130 
131 /*
132 static bool chk()
133 {
134  OdTrVisUniqueIDMapping idMap;
135  OdTrVisUniqueID uid(22, 0, 707);
136  OdTrVisId id = idMap.getTrVisId(uid, OdTrVisRendition::kMetafileData);
137  // id == 100
138  id = idMap.getTrVisId(uid, OdTrVisRendition::kMetafileData);
139  // check back
140  OdTrVisUniqueID chk = *idMap.findUID(id, OdTrVisRendition::kMetafileData);
141  // For string
142  OdTrVisUniqueIDMappingStr idMap2;
143  id = idMap2.getTrVisId(idMap2.asString(uid), OdTrVisRendition::kMetafileData);
144  // id == 100
145  id = idMap2.getTrVisId(idMap2.asString(uid), OdTrVisRendition::kMetafileData);
146  // check back
147  chk = idMap2.asUID(*idMap2.findUID(id, OdTrVisRendition::kMetafileData));
148  return (chk == uid);
149 }
150 */
151 
152 #include "TD_PackPop.h"
153 
154 #endif // ODTRVISUNIQUEIDMAPPING
kTrVisNegativeId
const OdTrVisId kTrVisNegativeId
Definition: TrVisDefs.h:110
OdTrVisRendition::kNDataTypes
@ kNDataTypes
Definition: TrVisRendition.h:101
NULL
#define NULL
Definition: GsProperties.h:177
OdTrVisUniqueIDMappingImpl
Definition: TrVisUniqueIdMapping.h:41
OdTrVisUniqueIDMappingImpl::getTrVisId
OdTrVisId getTrVisId(const T &uid, OdTrVisRendition::DataType type) const
Definition: TrVisUniqueIdMapping.h:78
OdTrVisUniqueID::untransform
OdTrVisUniqueID & untransform(const char *pStr, const UIDUnTransformer &untransformer=DefUIDUnTransformer())
Definition: TrVisUniqueId.h:225
type
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
OdaSTL.h
OdTrVisUniqueID
Definition: TrVisUniqueId.h:38
TD_PackPop.h
OdTrVisUniqueIDMappingStr
OdTrVisUniqueIDMappingImpl< OdAnsiString > OdTrVisUniqueIDMappingStr
Definition: TrVisUniqueIdMapping.h:129
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdTrVisUniqueIDMappingImpl::killTrVisId
void killTrVisId(const T &uid, OdTrVisRendition::DataType type)
Definition: TrVisUniqueIdMapping.h:87
OD_TYPENAME
#define OD_TYPENAME
Definition: OdPlatform.h:581
OdTrVisUniqueIDMappingImpl::hasUID
bool hasUID(const T &uid, OdTrVisRendition::DataType type) const
Definition: TrVisUniqueIdMapping.h:106
TrVisRendition.h
OdTrVisUniqueIDMappingImpl::setSpecialId
void setSpecialId(const T &uid, OdTrVisId id, OdTrVisRendition::DataType type)
Definition: TrVisUniqueIdMapping.h:112
OdTrVisUniqueIDMappingImpl::inc
OdTrVisId inc(OdTrVisId &counter, OdTrVisRendition::DataType type) const
Definition: TrVisUniqueIdMapping.h:46
TD_PackPush.h
OdTrVisUniqueIDMappingImpl::findUID
const T * findUID(OdTrVisId id, OdTrVisRendition::DataType type) const
Definition: TrVisUniqueIdMapping.h:94
OdTrVisRendition::DataType
DataType
Definition: TrVisRendition.h:89
OdTrVisUniqueIDMappingImpl::OdTrVisUniqueIDMappingImpl
OdTrVisUniqueIDMappingImpl()
Definition: TrVisUniqueIdMapping.h:62
OdTrVisUniqueIDMappingImpl::clean
void clean(OdTrVisRendition::DataType type=OdTrVisRendition::kNDataTypes)
Definition: TrVisUniqueIdMapping.h:67
TrVisUniqueId.h
OdTrVisUniqueIDMapping
OdTrVisUniqueIDMappingImpl< OdTrVisUniqueID > OdTrVisUniqueIDMapping
Definition: TrVisUniqueIdMapping.h:124
OdTrVisUniqueIDMappingImpl::asString
static OdAnsiString asString(const OdTrVisUniqueID &id)
Definition: TrVisUniqueIdMapping.h:117
OdTrVisUniqueIDMappingImpl::asUID
static OdTrVisUniqueID asUID(const OdAnsiString &str)
Definition: TrVisUniqueIdMapping.h:118
OdUInt64
Definition: Int64.h:137