CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrVisUniqueIdMapping.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 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
39template<class T>
41{
42 typedef std::map<T, OdTrVisId> IdMap;
43 mutable struct IdMapEntry
44 {
45 IdMap m_idMap;
46 OdTrVisId m_idMapCounter;
47 void clear()
48 {
49 m_idMap.clear();
50 m_idMapCounter = 101;
51 }
52 IdMapEntry() : m_idMapCounter(101) { }
54 inline OdUInt32 genType(OdTrVisRendition::DataType type) const
56 protected:
58 {
59 if (counter == kTrVisNegativeId)
60 {
61 OdTrVisId id = 101;
62 do
63 {
64 if (!findUID(id, type))
65 return id;
66 id++;
67 } while (id < kTrVisNegativeId);
68 counter = 101;
69 }
70 return counter++;
71 }
72 public:
74
76 {
77 const OdUInt32 nFrom = (type != OdTrVisRendition::kNDataTypes) ? genType(type) : 0;
79 for (OdUInt32 nType = nFrom; nType < nTo; nType++)
80 m_idMapEntry[nType].clear();
81 }
82
84 { IdMapEntry &entry = m_idMapEntry[genType(type)];
85 OD_TYPENAME IdMap::const_iterator it = entry.m_idMap.find(uid);
86 if (it != entry.m_idMap.end())
87 return it->second;
88 entry.m_idMap[uid] = entry.m_idMapCounter;
89 return inc(entry.m_idMapCounter, type);
90 }
91
93 { IdMapEntry &entry = m_idMapEntry[genType(type)];
94 OD_TYPENAME IdMap::iterator it = entry.m_idMap.find(uid);
95 if (it != entry.m_idMap.end())
96 entry.m_idMap.erase(it);
97 }
98
100 { const IdMapEntry &entry = m_idMapEntry[genType(type)];
101 OD_TYPENAME IdMap::const_iterator it = entry.m_idMap.begin();
102 while (it != entry.m_idMap.end())
103 {
104 if (it->second == id)
105 return &it->first;
106 it++;
107 }
108 return NULL;
109 }
110
111 bool hasUID(const T& uid, OdTrVisRendition::DataType type) const
112 { const IdMapEntry &entry = m_idMapEntry[genType(type)];
113 OD_TYPENAME IdMap::const_iterator it = entry.m_idMap.find(uid);
114 return it != entry.m_idMap.end();
115 }
116
118 {
119 m_idMapEntry[genType(type)].m_idMap[uid] = id;
120 }
121
122 static OdAnsiString asString(const OdTrVisUniqueID &id) { return id.transform(); }
123 static OdTrVisUniqueID asUID(const OdAnsiString &str) { return OdTrVisUniqueID().untransform(str); }
124};
125
130
135
136/*
137static bool chk()
138{
139 OdTrVisUniqueIDMapping idMap;
140 OdTrVisUniqueID uid(22, 0, 707);
141 OdTrVisId id = idMap.getTrVisId(uid, OdTrVisRendition::kMetafileData);
142 // id == 100
143 id = idMap.getTrVisId(uid, OdTrVisRendition::kMetafileData);
144 // check back
145 OdTrVisUniqueID chk = *idMap.findUID(id, OdTrVisRendition::kMetafileData);
146 // For string
147 OdTrVisUniqueIDMappingStr idMap2;
148 id = idMap2.getTrVisId(idMap2.asString(uid), OdTrVisRendition::kMetafileData);
149 // id == 100
150 id = idMap2.getTrVisId(idMap2.asString(uid), OdTrVisRendition::kMetafileData);
151 // check back
152 chk = idMap2.asUID(*idMap2.findUID(id, OdTrVisRendition::kMetafileData));
153 return (chk == uid);
154}
155*/
156
157#include "TD_PackPop.h"
158
159#endif // ODTRVISUNIQUEIDMAPPING
#define OD_TYPENAME
Definition: OdPlatform.h:631
unsigned int OdUInt32
const OdTrVisId kTrVisNegativeId
Definition: TrVisDefs.h:128
OdTrVisUniqueIDMappingImpl< OdAnsiString > OdTrVisUniqueIDMappingStr
OdTrVisUniqueIDMappingImpl< OdTrVisUniqueID > OdTrVisUniqueIDMapping
OdTrVisUniqueID & untransform(const char *pStr, const UIDUnTransformer &untransformer=DefUIDUnTransformer())
const T * findUID(OdTrVisId id, OdTrVisRendition::DataType type) const
static OdAnsiString asString(const OdTrVisUniqueID &id)
void clean(OdTrVisRendition::DataType type=OdTrVisRendition::kNDataTypes)
OdTrVisId getTrVisId(const T &uid, OdTrVisRendition::DataType type) const
void killTrVisId(const T &uid, OdTrVisRendition::DataType type)
void setSpecialId(const T &uid, OdTrVisId id, OdTrVisRendition::DataType type)
static OdTrVisUniqueID asUID(const OdAnsiString &str)
OdTrVisId inc(OdTrVisId &counter, OdTrVisRendition::DataType type) const
bool hasUID(const T &uid, OdTrVisRendition::DataType type) const
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
static OdUInt32 toGenericDataType(DataType dt)