CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GsFilerV100Impl.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
24#ifndef __OdGsFilerV100Impl_H__
25#define __OdGsFilerV100Impl_H__
26
27#include "TD_PackPush.h"
28#include "Ge/GeMatrix3d.h"
29#include "Ge/GeExtents3d.h"
30#include "DbBaseDatabase.h"
31#include "GsFiler.h"
32#include "OdStack.h"
33#include "RxObjectImpl.h"
34
35
36// Database linker
38{
39public:
44
48 virtual ~OdGsFilerDbLinker() { }
49public:
57 virtual OdBinaryData getDbHash(const OdDbBaseDatabase *pDb) const;
58
59 // Transform database handle
65 virtual OdUInt64 stubToDbHandle(OdDbStub *pStub) const = 0;
66
72 virtual OdDbStub *handleToDbStub(OdUInt64 nHandle) const = 0;
73
74 // Util methods
80 virtual OdDbBaseDatabase *getDatabase() const = 0;
81
87 virtual OdDbBaseDatabase *getDatabase(OdDbStub *pStub) const = 0;
88};
89
94
95
96
97#define STL_USING_MAP
98#define STL_USING_SET
99#include "OdaSTL.h"
100
101// Implement substitutor
103{
104 template<OdUInt32 nBytes> struct DataTyp
105 {
106 OdUInt8 m_data[nBytes];
107 static int compare(const DataTyp &t1, const DataTyp &t2)
108 {
109 for (OdUInt32 nb = 0; nb < nBytes; nb++)
110 {
111 if (t1.m_data[nb] != t2.m_data[nb])
112 return int(t1.m_data[nb]) - int(t2.m_data[nb]);
113 }
114 return 0;
115 }
116 bool operator ==(const DataTyp &t2) const { return compare(*this, t2) == 0; }
117 bool operator !=(const DataTyp &t2) const { return compare(*this, t2) != 0; }
118 bool operator <(const DataTyp &t2) const { return compare(*this, t2) < 0; }
119 bool operator <=(const DataTyp &t2) const { return compare(*this, t2) <= 0; }
120 bool operator >(const DataTyp &t2) const { return compare(*this, t2) > 0; }
121 bool operator >=(const DataTyp &t2) const { return compare(*this, t2) >= 0; }
122
123 operator const void*() const { return this; }
124 };
125 struct VoidsSet
126 {
127 void *m_pVoid;
129 };
130 struct VoidArry : public VoidsSet
131 {
134 : m_nVoids(0)
135 {
136 m_pVoid = NULL;
137 m_pAct = NULL;
138 }
139 ~VoidArry() { clear(); }
140 VoidsSet *getSet() { return (VoidsSet*)m_pVoid; }
142 if (m_nVoids == 1)
143 return this;
144 return getSet() + n;
145 }
146 bool contains(void *pVoid);
147 void add(void *pVoid, OdGsFiler::SubstitutionActuator *pAct);
148 void kill(void *pVoid);
149 void clear();
150 };
151
153 {
155 AbstractTyp() : m_pContainer(NULL) { }
156 };
157 typedef std::map<OdUInt32, AbstractTyp> RegsMap;
158 typedef std::map<OdUInt32, AbstractTyp> SubstsMap;
161
162 template<OdUInt32 nBytes> struct Procs
163 {
165 typedef std::map<ProcTyp, ProcTyp> RegMap;
166 typedef std::map<ProcTyp, VoidArry> SubstMap;
167 static void makeSubst(void *pPlace, const void *pSubstitution)
168 {
169 *(ProcTyp*)(pPlace) = *(const ProcTyp*)(pSubstitution);
170 }
171 static void runSubst(void *pPlace, const void *pSubstitution, OdGsFiler::SubstitutionActuator *pActuator)
172 {
173 ODA_ASSERT(pActuator);
174 pActuator->applySubstitution(pPlace, pSubstitution, makeSubst);
175 }
176 static void subst(OdGsFiler_SubstitutorImpl &impl, const void *pValue, void *pPlace, OdGsFiler::SubstitutionActuator *pAct, const void *pSubstitution, bool bClear)
177 {
178 if (pPlace && pSubstitution)
179 {
180 runSubst(pPlace, pSubstitution, pAct);
181 return;
182 }
183 if (pValue)
184 {
185 if (pPlace)
186 {
187 RegMap *pRegMap = (RegMap*)impl.m_regs[nBytes].m_pContainer;
188 OD_TYPENAME RegMap::iterator itReg = pRegMap->find(*(const ProcTyp*)pValue);
189 if (itReg != pRegMap->end())
190 {
191 runSubst(pPlace, itReg->second, pAct);
192 if (bClear)
193 pRegMap->erase(itReg);
194 }
195 }
196 else if (pSubstitution)
197 {
198 SubstMap *pSubMap = (SubstMap*)impl.m_substs[nBytes].m_pContainer;
199 OD_TYPENAME SubstMap::iterator itSub = pSubMap->find(*(const ProcTyp*)pValue);
200 if (itSub != pSubMap->end())
201 {
202 for (OdInt32 n = 0; n < itSub->second.m_nVoids; n++)
203 runSubst(itSub->second.at(n)->m_pVoid, pSubstitution, itSub->second.at(n)->m_pAct);
204 if (bClear)
205 pSubMap->erase(itSub);
206 }
207 }
208 else
209 {
210 RegMap *pRegMap = (RegMap*)impl.m_regs[nBytes].m_pContainer;
211 SubstMap *pSubMap = (SubstMap*)impl.m_substs[nBytes].m_pContainer;
212 if (pRegMap && pSubMap)
213 {
214 OD_TYPENAME RegMap::iterator itReg = pRegMap->find(*(const ProcTyp*)pValue);
215 OD_TYPENAME SubstMap::iterator itSub = pSubMap->find(*(const ProcTyp*)pValue);
216 if ((itReg != pRegMap->end()) && (itSub != pSubMap->end()))
217 {
218 for (OdInt32 n = 0; n < itSub->second.m_nVoids; n++)
219 runSubst(itSub->second.at(n)->m_pVoid, itReg->second, itSub->second.at(n)->m_pAct);
220 }
221 if (bClear)
222 {
223 if (itReg != pRegMap->end())
224 pRegMap->erase(itReg);
225 if (itSub != pSubMap->end())
226 pSubMap->erase(itSub);
227 }
228 }
229 else if (bClear)
230 {
231 if (pRegMap)
232 {
233 OD_TYPENAME RegMap::iterator itReg = pRegMap->find(*(const ProcTyp*)pValue);
234 if (itReg != pRegMap->end())
235 pRegMap->erase(itReg);
236 }
237 if (pSubMap)
238 {
239 OD_TYPENAME SubstMap::iterator itSub = pSubMap->find(*(const ProcTyp*)pValue);
240 if (itSub != pSubMap->end())
241 pSubMap->erase(itSub);
242 }
243 }
244 }
245 return;
246 }
247 RegMap *pRegMap = (RegMap*)impl.m_regs[nBytes].m_pContainer;
248 SubstMap *pSubMap = (SubstMap*)impl.m_substs[nBytes].m_pContainer;
249 if (pRegMap && pSubMap)
250 {
251 OD_TYPENAME RegMap::iterator itReg = pRegMap->begin();
252 while (itReg != pRegMap->end())
253 {
254 OD_TYPENAME SubstMap::iterator itSub = pSubMap->find(itReg->first);
255 if (itSub != pSubMap->end())
256 {
257 for (OdInt32 n = 0; n < itSub->second.m_nVoids; n++)
258 runSubst(itSub->second.at(n)->m_pVoid, itReg->second, itSub->second.at(n)->m_pAct);
259 }
260 itReg++;
261 }
262 }
263 if (bClear)
264 {
265 if (pRegMap) { delete pRegMap; impl.m_regs[nBytes].m_pContainer = NULL; }
266 if (pSubMap) { delete pSubMap; impl.m_substs[nBytes].m_pContainer = NULL; }
267 }
268 }
269 static void reg(OdGsFiler_SubstitutorImpl &impl, const void *pValue, const void *pSubstitution, bool bRegister, bool bImmediate)
270 {
271 if (bRegister)
272 {
274 if (!cont.m_pContainer)
275 cont.m_pContainer = new RegMap;
276 RegMap &pMap = *(RegMap*)cont.m_pContainer;
277 pMap[*(const ProcTyp*)pValue] = *(const ProcTyp*)pSubstitution;
278 }
279 if (bImmediate)
280 subst(impl, pValue, NULL, NULL, pSubstitution, false);
281 }
282 static void req(OdGsFiler_SubstitutorImpl &impl, void *pPlace, OdGsFiler::SubstitutionActuator *pAct, const void *pValue, bool bRegister, bool bImmediate)
283 {
284 if (bRegister)
285 {
286 if (bImmediate)
287 {
288 RegMap *pRegMap = (RegMap*)impl.m_regs[nBytes].m_pContainer;
289 if (pRegMap)
290 {
291 OD_TYPENAME RegMap::iterator itReg = pRegMap->find(*(const ProcTyp*)pValue);
292 if (itReg != pRegMap->end())
293 {
294 runSubst(pPlace, itReg->second, pAct);
295 return;
296 }
297 }
298 }
300 if (!cont.m_pContainer)
301 cont.m_pContainer = new SubstMap;
302 SubstMap &pMap = *(SubstMap*)cont.m_pContainer;
303 pMap[*(const ProcTyp*)pValue].add(pPlace, pAct);
304 }
305 else if (bImmediate)
306 subst(impl, pValue, pPlace, pAct, NULL, false);
307 }
308 static void clear(OdGsFiler_SubstitutorImpl &impl, const void *pValue)
309 {
310 RegMap *pRegMap = (RegMap*)impl.m_regs[nBytes].m_pContainer;
311 SubstMap *pSubMap = (SubstMap*)impl.m_substs[nBytes].m_pContainer;
312 if (pValue)
313 {
314 if (pRegMap)
315 {
316 OD_TYPENAME RegMap::iterator it = pRegMap->find(*(const ProcTyp*)pValue);
317 if (it != pRegMap->end())
318 pRegMap->erase(it);
319 }
320 if (pSubMap)
321 {
322 OD_TYPENAME SubstMap::iterator it = pSubMap->find(*(const ProcTyp*)pValue);
323 if (it != pSubMap->end())
324 pSubMap->erase(it);
325 }
326 }
327 else
328 {
329 if (pRegMap) { delete pRegMap; impl.m_regs[nBytes].m_pContainer = NULL; }
330 if (pSubMap) { delete pSubMap; impl.m_substs[nBytes].m_pContainer = NULL; }
331 }
332 }
333 };
334
336 static struct OdRxObjectSubstitutionActuator : public OdGsFiler::SubstitutionActuator
337 {
338 OdRxObjectSubstitutionActuator() { }
339 virtual void applySubstitution(void *pPlace, const void *pValue, SetPtrFunc pSetFunc)
340 {
342 if (pPlace)
343 (*reinterpret_cast<OdRxObjectPtr*>(pPlace))->addRef();
344 }
345 } g_rxObjectActuator;
346
347 // Register known substitution
348 virtual void registerSubstitution(const void *pValue, const void *pSubstitution, OdUInt32 size = sizeof(OdIntPtr), bool bRegister = true, bool bImmediate = false);
349 // Register substitution request
350 virtual void requestSubstitution(void *pPlace, const void *pValue, OdUInt32 size = sizeof(OdIntPtr), bool bRegister = true, bool bImmediate = true);
351 // Register substitution request for smart pointer
352 virtual void requestSubstitution(OdBaseObjectPtr *pPlace, const void *pValue, bool bRegister = true, bool bImmediate = true);
353 // Register substitution with non-default behavior
354 virtual void requestSubstitution(void *pPlace, OdGsFiler::SubstitutionActuator *pActuator, const void *pValue, OdUInt32 size = sizeof(OdIntPtr), bool bRegister = true, bool bImmediate = true);
355 // Clear substitutions
356 virtual void clearSubstitutions(const void *pValue = NULL, OdUInt32 size = 0);
357 // Run substitutions
358 virtual void runSubstitutions(const void *pValue = NULL, OdUInt32 size = 0, bool bClear = true);
359#undef REG_FUNCCALL
361};
362
363
364// Implement V1 version filer
366protected:
367 enum Flags {
368 kOpenedForWrite = (1 << 0),
369
370 kLastFlag = kOpenedForWrite
371 };
372protected:
385 : m_type(OdGsFiler::kEOFSection)
386 , m_begin(0)
387 { }
389 : m_type(section)
390 , m_begin(tell)
391 { }
392 };
395 typedef std::map<OdString, OdRxObjectPtr> ArbDataMap;
397 typedef std::set<const void *> RegPtrsSet;
399protected:
400 bool isWriting() const { return GETBIT(m_nFlags, kOpenedForWrite); }
401 void setWriting(bool bSet) { SETBIT(m_nFlags, kOpenedForWrite, bSet); }
402
403 void assertWr() const { if (!isWriting()) throw OdError(eNotOpenForWrite); }
404 void assertRd() const { if (isWriting()) throw OdError(eNotOpenForRead); }
405public:
420 : m_nSectionsToWrite(OdUInt64(-1))
421 , m_nSectionsToRead(OdUInt64(-1))
422 , m_nFlags(0)
423 , m_nVersion(kV2)
424 , m_nCurSection(kEOFSection)
425 , m_nCurSectionSize(0)
426 {
428 }
429
434 {
435 }
436
444
449
456 virtual bool setStream(OdStreamBuf *pStream, bool bWrite = false);
457
461 virtual OdStreamBufPtr getStream() const;
462
468 virtual void setDatabase(const OdDbBaseDatabase *pDb);
469
474
480 virtual void setVersion(OdUInt32 nVersion);
481
490 virtual OdUInt32 version() const;
491
492 virtual void wrDbHash(const OdDbBaseDatabase *pDb);
493 virtual bool checkDbHash(const OdDbBaseDatabase *pDb);
494
500 virtual void setWriteSections(OdUInt64 nSections);
501
508 virtual void setWriteSection(Section section, bool bSet);
509
517 virtual bool isWriteSection(Section section) const;
518
524 virtual void setReadSections(OdUInt64 nSections);
525
532 virtual void setReadSection(Section section, bool bSet);
533
541 virtual bool isReadSection(Section section) const;
542
548 virtual void wrSectionBegin(Section section);
549
555 virtual void wrSectionEnd(Section section);
556
560 virtual void wrEOFSection();
561
565 virtual Section rdSection() const;
566
570 virtual Section curSection() const;
571
575 virtual void skipSection() const;
576 virtual void rdBackSection() const;
577
583 virtual bool checkEOF() const;
584
585 virtual Substitutor *subst() const;
586 virtual void makeSubstitutions(bool bClear = true) const;
588 virtual void setSubstitutor(OdRxObject *pSubst);
589
590 virtual void setArbitraryData(const OdChar *pName, OdRxObject *pObject);
591 virtual OdRxObjectPtr getArbitraryData(const OdChar *pName) const;
592 virtual bool hasArbitraryData(const OdChar *pName) const;
593 virtual void clearArbitraryData();
594
595 virtual void registerPtr(const void *pPtr);
596 virtual void unregisterPtr(const void *pPtr);
597 virtual bool isPtrRegistered(const void *pPtr) const;
598 virtual void clearRegisteredPtrs();
599
605 virtual void wrHandle(OdDbStub *pHandle);
606
610 virtual OdDbStub *rdHandle() const;
611
617 virtual void wrClass(OdRxObject *pObj);
618
625 virtual OdRxObjectPtr rdClass() const;
626
633 virtual void wrRawData(const void *pData, OdUInt32 nDataSize);
634
641 virtual void rdRawData(void *pData, OdUInt32 nDataSize) const;
642};
643
644#include "TD_PackPop.h"
645
646#endif // __OdGsFilerV100Impl_H__
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
bool operator!=(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:403
bool operator==(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:397
#define GS_TOOLKIT_EXPORT
Definition: GsExport.h:37
OdSmartPtr< OdGsFilerDbLinker > OdGsFilerDbLinkerPtr
#define OD_TYPENAME
Definition: OdPlatform.h:631
unsigned int OdUInt32
int OdInt32
unsigned char OdUInt8
ptrdiff_t OdIntPtr
wchar_t OdChar
bool operator>=(const OdString &s1, const OdString &s2)
Definition: OdString.h:1376
bool operator<=(const OdString &s1, const OdString &s2)
Definition: OdString.h:1354
bool operator<(const OdString &s1, const OdString &s2)
Definition: OdString.h:1309
bool operator>(const OdString &s1, const OdString &s2)
Definition: OdString.h:1332
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:516
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
virtual OdUInt64 stubToDbHandle(OdDbStub *pStub) const =0
virtual OdDbStub * handleToDbStub(OdUInt64 nHandle) const =0
virtual OdBinaryData getDbHash(const OdDbBaseDatabase *pDb) const
virtual OdDbBaseDatabase * getDatabase() const =0
virtual ~OdGsFilerDbLinker()
virtual OdDbBaseDatabase * getDatabase(OdDbStub *pStub) const =0
virtual void wrHandle(OdDbStub *pHandle)
void assertWr() const
virtual void wrSectionEnd(Section section)
virtual void setReadSections(OdUInt64 nSections)
virtual OdRxObjectPtr rdClass() const
std::map< OdString, OdRxObjectPtr > ArbDataMap
virtual bool checkDbHash(const OdDbBaseDatabase *pDb)
virtual bool setStream(OdStreamBuf *pStream, bool bWrite=false)
virtual void skipSection() const
void assertRd() const
virtual bool hasArbitraryData(const OdChar *pName) const
virtual bool isWriteSection(Section section) const
OdUInt32 headerTestChunk() const
virtual void unregisterPtr(const void *pPtr)
virtual void wrEOFSection()
bool isWriting() const
OdSmartPtr< OdGsFiler_SubstitutorImpl > m_subst
virtual void wrRawData(const void *pData, OdUInt32 nDataSize)
virtual Section rdSection() const
virtual OdRxObjectPtr getArbitraryData(const OdChar *pName) const
virtual void wrDbHash(const OdDbBaseDatabase *pDb)
OdGsFilerDbLinkerPtr m_pLinker
virtual void setArbitraryData(const OdChar *pName, OdRxObject *pObject)
std::set< const void * > RegPtrsSet
virtual void setWriteSection(Section section, bool bSet)
virtual void rdBackSection() const
virtual void wrClass(OdRxObject *pObj)
OdStreamBufPtr m_pStream
virtual void rdRawData(void *pData, OdUInt32 nDataSize) const
virtual OdRxObjectPtr getSubstitutor() const
virtual Section curSection() const
OdUInt64 m_nSectionsToWrite
virtual void setVersion(OdUInt32 nVersion)
virtual void setSubstitutor(OdRxObject *pSubst)
virtual OdDbBaseDatabase * getDatabase() const
virtual void wrSectionBegin(Section section)
virtual void setDatabase(const OdDbBaseDatabase *pDb)
virtual void clearArbitraryData()
virtual void clearRegisteredPtrs()
virtual bool isPtrRegistered(const void *pPtr) const
virtual OdUInt32 version() const
virtual bool isReadSection(Section section) const
virtual void setReadSection(Section section, bool bSet)
virtual OdDbStub * rdHandle() const
virtual bool checkEOF() const
virtual Substitutor * subst() const
virtual void makeSubstitutions(bool bClear=true) const
virtual void registerPtr(const void *pPtr)
OdUInt64 m_nSectionsToRead
void setWriting(bool bSet)
virtual void setWriteSections(OdUInt64 nSections)
OdUInt32 m_nCurSectionSize
OdStack< WrSectionData > m_sectionStack
virtual OdStreamBufPtr getStream() const
static OdSmartPtr< TInterface > createObject()
Definition: RxObjectImpl.h:107
GLsizeiptr size
Definition: gles2_ext.h:182
virtual void applySubstitution(void *pPlace, const void *pValue, SetPtrFunc pSetFunc)
Definition: GsFiler.h:118
virtual void clearSubstitutions(const void *pValue=NULL, OdUInt32 size=0)=0
static int compare(const DataTyp &t1, const DataTyp &t2)
std::map< ProcTyp, VoidArry > SubstMap
static void subst(OdGsFiler_SubstitutorImpl &impl, const void *pValue, void *pPlace, OdGsFiler::SubstitutionActuator *pAct, const void *pSubstitution, bool bClear)
std::map< ProcTyp, ProcTyp > RegMap
static void clear(OdGsFiler_SubstitutorImpl &impl, const void *pValue)
OdGsFiler_SubstitutorImpl::DataTyp< nBytes > ProcTyp
static void reg(OdGsFiler_SubstitutorImpl &impl, const void *pValue, const void *pSubstitution, bool bRegister, bool bImmediate)
static void runSubst(void *pPlace, const void *pSubstitution, OdGsFiler::SubstitutionActuator *pActuator)
static void req(OdGsFiler_SubstitutorImpl &impl, void *pPlace, OdGsFiler::SubstitutionActuator *pAct, const void *pValue, bool bRegister, bool bImmediate)
static void makeSubst(void *pPlace, const void *pSubstitution)
void add(void *pVoid, OdGsFiler::SubstitutionActuator *pAct)
OdGsFiler::SubstitutionActuator * m_pAct
std::map< OdUInt32, AbstractTyp > SubstsMap
virtual void requestSubstitution(void *pPlace, OdGsFiler::SubstitutionActuator *pActuator, const void *pValue, OdUInt32 size=sizeof(OdIntPtr), bool bRegister=true, bool bImmediate=true)
virtual void requestSubstitution(OdBaseObjectPtr *pPlace, const void *pValue, bool bRegister=true, bool bImmediate=true)
virtual void registerSubstitution(const void *pValue, const void *pSubstitution, OdUInt32 size=sizeof(OdIntPtr), bool bRegister=true, bool bImmediate=false)
virtual void runSubstitutions(const void *pValue=NULL, OdUInt32 size=0, bool bClear=true)
std::map< OdUInt32, AbstractTyp > RegsMap
virtual void requestSubstitution(void *pPlace, const void *pValue, OdUInt32 size=sizeof(OdIntPtr), bool bRegister=true, bool bImmediate=true)
virtual void clearSubstitutions(const void *pValue=NULL, OdUInt32 size=0)
static OdGsFiler::SubstitutionActuator g_defActuator
WrSectionData(OdGsFiler::Section section, OdUInt32 tell)