CFx SDK Documentation  2022 SP0
TrVisMetafileAnalyzer.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 metafile parser and comparator
24 
25 #ifndef ODTRVISMETAFILEANALYZER
26 #define ODTRVISMETAFILEANALYZER
27 
28 #include "TD_PackPush.h"
29 
30 #include "TrVisDefs.h"
31 #include "TrVisMetafileStream.h"
32 
41 {
42  public:
43  enum VarType
44  {
48  kTypeInt8 = 2,
57  kTypeFVec2 = 11,
58  kTypeDVec2 = 12,
59  kTypeFVec3 = 13,
60  kTypeDVec3 = 14,
61  kTypeFVec4 = 15,
62  kTypeDVec4 = 16,
63  kTypeFMat3 = 17,
64  kTypeDMat3 = 18,
65  kTypeFMat4 = 19,
66  kTypeDMat4 = 20,
67 
68  kNTypes
69  };
71  {
78 
80  };
81  struct VarState
82  {
84  VarType m_varType; // Type of current variable
85  OdUInt32 m_nVar; // Number of variable under chunk
86  const void * m_pVar; // Pointer onto variable
87 
91  , m_nVar(0)
92  , m_pVar(NULL)
93  { }
94 
96  bool isEOF() const { return m_chunk == OdTrVisMetaRecType_NTypes; }
97 
98  OdUInt8 asUInt8() const ;
99  OdInt8 asInt8() const ;
100  OdUInt16 asUInt16() const ;
101  OdInt16 asInt16() const ;
102  OdUInt32 asUInt32() const ;
103  OdInt32 asInt32() const ;
104  OdUInt64 asUInt64() const ;
105  OdInt64 asInt64() const ;
106  float asFloat() const ;
107  double asDouble() const ;
108  const float *asFVec() const ;
109  const double *asDVec() const ;
110  const OdGeVector2d &asDVec2() const ;
111  const OdGePoint2d &asDPoint2() const ;
112  const OdGeVector3d &asDVec3() const ;
113  const OdGePoint3d &asDPoint3() const ;
114  const OdGeMatrix3d &asDMatrix3d() const;
115  };
116  static struct TypeSpec
117  {
118  OdUInt32 m_typeSize;
119  OdUInt32 m_typeNumber;
120  OdUInt32 m_basisType;
122  static struct BasisFuncs
123  {
124  void (*m_pLRegFunc)(OdUInt32 &lReg, const VarState &varState);
125  bool (*m_pCompFunc)(const void *pStream1, const void *pStream2, OdUInt32 nVars);
128  {
129  kOpSkip = 0, // Skip until next chunk
130  kOpProcess = 1 // Process normally
131  };
132  enum Scheme
133  {
134  kSmBasic = 0, // Basic stream scheme
135  kSmStandalone, // Standalone stream scheme
136  kNumSchemes // Number of stream schemes
137  };
138  protected:
139  static struct RecScheme
140  {
141  const char *m_pSpec[kNumSchemes];
144  {
150 
152  : m_pDataCont(NULL)
154  , m_nStreamSize(0)
156  , m_pStreamEnd(NULL)
157  { }
160  {
162  const char *m_pLogicalCur;
163 
165  : m_pStreamCur(NULL)
167  { }
168  void logicalCopyIn(const StreamMarker &sm2) { m_pLogicalCur = sm2.m_pLogicalCur - 2; }
170  };
172  {
173  kLogicInit = (1 << 0),
174  kLogicExclusive = (1 << 1),
175  kLogicLoopSkip = (1 << 2),
176  kLogicSkip = (1 << 3),
177  kLogicSkipByMask = (1 << 4)
178  };
180  {
186 
188  : m_logicalReg(0)
189  , m_logicalFlags(0)
190  { }
193  public:
194  OdTrVisMetafileParser(const OdBaseMetafileContainer *pContainer = NULL, Scheme streamScheme = kSmBasic)
195  : m_skipMask(0)
196  {
197  initialize(pContainer, streamScheme);
198  }
199 
203 
205 
206  void initialize(const OdBaseMetafileContainer *pContainer, Scheme streamScheme = kSmBasic);
207  void reset();
208 
209  void rewind();
210 
212  protected:
213  static void lRegFuncUInt8(OdUInt32 &lReg, const VarState &varState);
214  static void lRegFuncUInt16(OdUInt32 &lReg, const VarState &varState);
215  static void lRegFuncUInt32(OdUInt32 &lReg, const VarState &varState);
216  static void lRegFuncStub(OdUInt32 &lReg, const VarState &varState);
217 };
218 
227 {
228  protected:
230  static bool (*s_pCompArrayFunc[OdTrVisArrayWrapper::Type_Marker + 1])(const void *pArray1, const void *pArray2, OdUInt32 nSize);
231  public:
232  OdTrVisMetafileComparator(const OdBaseMetafileContainer *pContainer1 = NULL, const OdBaseMetafileContainer *pContainer2 = NULL, OdTrVisMetafileParser::Scheme streamScheme = OdTrVisMetafileParser::kSmBasic)
233  : m_par1(pContainer1, streamScheme)
234  , m_par2(pContainer2, streamScheme)
235  {
236  }
237 
238  bool compare();
239  bool compare(const OdBaseMetafileContainer *pContainer1, const OdBaseMetafileContainer *pContainer2, OdTrVisMetafileParser::Scheme streamScheme = OdTrVisMetafileParser::kSmBasic);
240  protected:
241  friend class OdTrVisMetafileParser;
242  static bool compFuncUInt8(const void *pStream1, const void *pStream2, OdUInt32 nVars);
243  static bool compFuncUInt16(const void *pStream1, const void *pStream2, OdUInt32 nVars);
244  static bool compFuncUInt32(const void *pStream1, const void *pStream2, OdUInt32 nVars);
245  static bool compFuncUInt64(const void *pStream1, const void *pStream2, OdUInt32 nVars);
246  static bool compFuncFloat(const void *pStream1, const void *pStream2, OdUInt32 nVars);
247  static bool compFuncDouble(const void *pStream1, const void *pStream2, OdUInt32 nVars);
248 
249  static bool compFuncArrayVertex(const void *pArray1, const void *pArray2, OdUInt32 nSize);
250  static bool compFuncArrayNormal(const void *pArray1, const void *pArray2, OdUInt32 nSize);
251  static bool compFuncArrayColor(const void *pArray1, const void *pArray2, OdUInt32 nSize);
252  static bool compFuncArrayTexCoord(const void *pArray1, const void *pArray2, OdUInt32 nSize);
253  static bool compFuncArrayIndex(const void *pArray1, const void *pArray2, OdUInt32 nSize);
254  static bool compFuncArrayMarker(const void *pArray1, const void *pArray2, OdUInt32 nSize);
255 };
256 
258 inline OdInt8 OdTrVisMetafileParser::VarState::asInt8() const { return *(const OdInt8*) m_pVar; }
259 
260 #ifdef TD_STRICT_ALIGNMENT
261 
262 template <class T> T align(const void* ptr) { T res; memcpy(&res, ptr, sizeof(T)); return res; }
263 
264 inline OdUInt16 OdTrVisMetafileParser::VarState::asUInt16() const { return align<OdUInt16>(m_pVar); }
265 inline OdInt16 OdTrVisMetafileParser::VarState::asInt16() const { return align<OdInt16 >(m_pVar); }
266 inline OdUInt32 OdTrVisMetafileParser::VarState::asUInt32() const { return align<OdUInt32>(m_pVar); }
267 inline OdInt32 OdTrVisMetafileParser::VarState::asInt32() const { return align<OdInt32 >(m_pVar); }
268 inline OdUInt64 OdTrVisMetafileParser::VarState::asUInt64() const { return align<OdUInt64>(m_pVar); }
269 inline OdInt64 OdTrVisMetafileParser::VarState::asInt64() const { return align<OdInt64 >(m_pVar); }
270 inline float OdTrVisMetafileParser::VarState::asFloat() const { return align<float >(m_pVar); }
271 inline double OdTrVisMetafileParser::VarState::asDouble() const { return align<double >(m_pVar); }
272 inline const float* OdTrVisMetafileParser::VarState::asFVec() const { return align<const float* >(m_pVar); }
273 inline const double* OdTrVisMetafileParser::VarState::asDVec() const { return align<const double*>(m_pVar); }
274 inline const OdGeVector2d& OdTrVisMetafileParser::VarState::asDVec2() const { ODA_ASSERT(OdIntPtr(m_pVar)%8); return *(const OdGeVector2d*)m_pVar; }
275 inline const OdGePoint2d& OdTrVisMetafileParser::VarState::asDPoint2() const { ODA_ASSERT(OdIntPtr(m_pVar)%8); return *(const OdGePoint2d*)m_pVar; }
276 inline const OdGeVector3d& OdTrVisMetafileParser::VarState::asDVec3() const { ODA_ASSERT(OdIntPtr(m_pVar)%8); return *(const OdGeVector3d*)m_pVar; }
277 inline const OdGePoint3d& OdTrVisMetafileParser::VarState::asDPoint3() const { ODA_ASSERT(OdIntPtr(m_pVar)%8); return *(const OdGePoint3d*)m_pVar; }
278 inline const OdGeMatrix3d& OdTrVisMetafileParser::VarState::asDMatrix3d() const { ODA_ASSERT(OdIntPtr(m_pVar)%8); return *(const OdGeMatrix3d*)m_pVar; }
279 
280 #else
281 
282 inline OdUInt16 OdTrVisMetafileParser::VarState::asUInt16() const { return *(const OdUInt16*)m_pVar; }
283 inline OdInt16 OdTrVisMetafileParser::VarState::asInt16() const { return *(const OdInt16*)m_pVar; }
284 inline OdUInt32 OdTrVisMetafileParser::VarState::asUInt32() const { return *(const OdUInt32*)m_pVar; }
285 inline OdInt32 OdTrVisMetafileParser::VarState::asInt32() const { return *(const OdInt32*)m_pVar; }
286 inline OdUInt64 OdTrVisMetafileParser::VarState::asUInt64() const { return *(const OdUInt64*)m_pVar; }
287 inline OdInt64 OdTrVisMetafileParser::VarState::asInt64() const { return *(const OdInt64*)m_pVar; }
288 inline float OdTrVisMetafileParser::VarState::asFloat() const { return *(const float*)m_pVar; }
289 inline double OdTrVisMetafileParser::VarState::asDouble() const { return *(const double*)m_pVar; }
290 inline const float* OdTrVisMetafileParser::VarState::asFVec() const { return (const float*)m_pVar; }
291 inline const double* OdTrVisMetafileParser::VarState::asDVec() const { return (const double*)m_pVar; }
292 inline const OdGeVector2d& OdTrVisMetafileParser::VarState::asDVec2() const { return *(const OdGeVector2d*)m_pVar; }
293 inline const OdGePoint2d& OdTrVisMetafileParser::VarState::asDPoint2() const { return *(const OdGePoint2d*)m_pVar; }
294 inline const OdGeVector3d& OdTrVisMetafileParser::VarState::asDVec3() const { return *(const OdGeVector3d*)m_pVar; }
295 inline const OdGePoint3d& OdTrVisMetafileParser::VarState::asDPoint3() const { return *(const OdGePoint3d*)m_pVar; }
296 inline const OdGeMatrix3d& OdTrVisMetafileParser::VarState::asDMatrix3d() const { return *(const OdGeMatrix3d*)m_pVar; }
297 
298 #endif
299 
300 #include "TD_PackPop.h"
301 
302 #endif // ODTRVISMETAFILEANALYZER
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
#define NULL
Definition: GsProperties.h:177
unsigned int OdUInt32
short OdInt16
signed char OdInt8
unsigned short OdUInt16
int OdInt32
unsigned char OdUInt8
ptrdiff_t OdIntPtr
OdTrVisMetaRecType
@ OdTrVisMetaRecType_NTypes
Definition: Int64.h:43
static bool compFuncArrayMarker(const void *pArray1, const void *pArray2, OdUInt32 nSize)
static bool compFuncArrayTexCoord(const void *pArray1, const void *pArray2, OdUInt32 nSize)
static bool compFuncArrayNormal(const void *pArray1, const void *pArray2, OdUInt32 nSize)
static bool compFuncUInt64(const void *pStream1, const void *pStream2, OdUInt32 nVars)
static bool compFuncArrayVertex(const void *pArray1, const void *pArray2, OdUInt32 nSize)
static bool compFuncFloat(const void *pStream1, const void *pStream2, OdUInt32 nVars)
static bool compFuncDouble(const void *pStream1, const void *pStream2, OdUInt32 nVars)
static bool compFuncArrayColor(const void *pArray1, const void *pArray2, OdUInt32 nSize)
OdTrVisMetafileParser m_par1
static bool(* s_pCompArrayFunc[OdTrVisArrayWrapper::Type_Marker+1])(const void *pArray1, const void *pArray2, OdUInt32 nSize)
static bool compFuncUInt32(const void *pStream1, const void *pStream2, OdUInt32 nVars)
static bool compFuncUInt16(const void *pStream1, const void *pStream2, OdUInt32 nVars)
OdTrVisMetafileComparator(const OdBaseMetafileContainer *pContainer1=NULL, const OdBaseMetafileContainer *pContainer2=NULL, OdTrVisMetafileParser::Scheme streamScheme=OdTrVisMetafileParser::kSmBasic)
OdTrVisMetafileParser m_par2
bool compare(const OdBaseMetafileContainer *pContainer1, const OdBaseMetafileContainer *pContainer2, OdTrVisMetafileParser::Scheme streamScheme=OdTrVisMetafileParser::kSmBasic)
static bool compFuncUInt8(const void *pStream1, const void *pStream2, OdUInt32 nVars)
static bool compFuncArrayIndex(const void *pArray1, const void *pArray2, OdUInt32 nSize)
const OdTrVisFlatMetafileContainer * metafileContainer() const
static void lRegFuncUInt32(OdUInt32 &lReg, const VarState &varState)
const VarState & nextStep(NextStepOp op=kOpProcess)
OdTrVisMetafileParser(const OdBaseMetafileContainer *pContainer=NULL, Scheme streamScheme=kSmBasic)
struct OdTrVisMetafileParser::InitialState m_initState
static struct OdTrVisMetafileParser::TypeSpec s_typeSpec[kNTypes]
static struct OdTrVisMetafileParser::RecScheme s_schemes[OdTrVisMetaRecType_NTypes]
static void lRegFuncUInt16(OdUInt32 &lReg, const VarState &varState)
void initialize(const OdBaseMetafileContainer *pContainer, Scheme streamScheme=kSmBasic)
static void lRegFuncUInt8(OdUInt32 &lReg, const VarState &varState)
struct OdTrVisMetafileParser::CurrentState m_curState
static struct OdTrVisMetafileParser::BasisFuncs s_basisFunc[kNBasisTypes]
static void lRegFuncStub(OdUInt32 &lReg, const VarState &varState)
const OdUInt8 *& userEntryCurProc()
typedef void(APIENTRYP PFNGLACTIVETEXTUREPROC)(GLenum texture)
const OdTrVisFlatMetafileContainer * m_pDataCont
void logicalCopyIn(const StreamMarker &sm2)
const OdGePoint3d & asDPoint3() const
const OdGePoint2d & asDPoint2() const
const OdGeVector2d & asDVec2() const
const OdGeMatrix3d & asDMatrix3d() const
const OdGeVector3d & asDVec3() const
OdTrVisMetaRecType asChunk() const