CFx SDK Documentation  2023 SP0
daiWriteUtils.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2018, 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-2018 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 _WRITE_UTILS_H_
25 #define _WRITE_UTILS_H_
26 
27 #include "OdaCommon.h"
28 #include "DebugStuff.h"
29 
30 #include "OdStreamBuf.h"
31 #include "OdPlatformSettings.h"
32 #include "daiBuildOptions.h"
33 #include "StringArray.h"
34 
35 #define STL_USING_VECTOR
36 #define STL_USING_STRING
37 #include "OdaSTL.h"
38 
39 class OdDbHandle;
40 
41 namespace OdDAI
42 {
43  namespace WrUtils
44  {
45  const OdUInt32 writeErorCode = static_cast<OdUInt32>(-1);
46 
47  OdUInt32 writeValue(const OdDbHandle& valueToWrite, std::vector<OdUInt8>& writeBuffer);
48  OdUInt32 writeValue(const int valueToWrite, std::vector<OdUInt8>& writeBuffer);
49  OdUInt32 writeValue(const long int valueToWrite, std::vector<OdUInt8>& writeBuffer);
50  OdUInt32 writeValue(const OdUInt64& valueToWrite, std::vector<OdUInt8>& writeBuffer);
51  OdUInt32 writeValue(const double& valueToWrite, std::vector<OdUInt8>& writeBuffer);
52  OdUInt32 writeValue(const std::string& valueToWrite, std::vector<OdUInt8>& writeBuffer);
53  OdUInt32 writeValue(const OdAnsiString& valueToWrite, std::vector<OdUInt8>& writeBuffer);
54  OdUInt32 writeValue(const OdString& valueToWrite, std::vector<OdUInt8>& writeBuffer);
55  OdUInt32 writeValue(const char& valueToWrite, std::vector<OdUInt8>& writeBuffer);
56 
57  OdUInt32 appendValue(const OdDbHandle& valueToWrite, std::vector<OdUInt8>& writeBuffer);
58  OdUInt32 appendValue(int valueToWrite, std::vector<OdUInt8>& writeBuffer);
59  OdUInt32 appendValue(const OdUInt64& valueToWrite, std::vector<OdUInt8>& writeBuffer);
60  OdUInt32 appendValue(const double& valueToWrite, std::vector<OdUInt8>& writeBuffer);
61  OdUInt32 appendValue(const std::string& valueToWrite, std::vector<OdUInt8>& writeBuffer);
62  OdUInt32 appendValue(const OdString& valueToWrite, std::vector<OdUInt8>& writeBuffer);
63  OdUInt32 appendValue(const OdAnsiString& valueToWrite, std::vector<OdUInt8>& writeBuffer);
64  OdUInt32 appendValue(const char& valueToWrite, std::vector<OdUInt8>& writeBuffer);
65  void appendValue(const char* bufferToWrite, OdUInt32 sizeBuffer, std::vector<OdUInt8>& writeBuffer);
66 
67  template<class ValueType, class BufferType>
68  inline OdUInt32 writeValue(const ValueType& valueToWrite, BufferType& writeBuffer, const OdUInt64& writeBufferSize, const char* printfTemplate)
69  {
70 #if defined(_MSC_VER) && _MSC_VER < 1900
71  return _snprintf(reinterpret_cast<char* const>(&writeBuffer[0]), writeBufferSize, printfTemplate, valueToWrite);
72 #else
73  return snprintf(reinterpret_cast<char* const>(&writeBuffer[0]), writeBufferSize, printfTemplate, valueToWrite);
74 #endif
75  }
76 
77  template<class ValueType, OdUInt64 writeBufferSize>
78  inline OdUInt32 appendValue(const ValueType& valueToWrite, std::vector<OdUInt8>& writeBuffer, const char* printfTemplate)
79  {
80  OdUInt8* appendBuffer[writeBufferSize + 1] = { 0 };
81  OdUInt32 countWrite = writeValue(valueToWrite, appendBuffer, writeBufferSize + 1, printfTemplate);
82 
83  if (countWrite == writeErorCode)
84  {
85  return writeErorCode;
86  }
87 
88  OdUInt64 insertionIndex = writeBuffer.size();
89  writeBuffer.resize(insertionIndex + countWrite);
90  memcpy(&writeBuffer[insertionIndex], &appendBuffer[0], countWrite);
91 
92  return countWrite;
93  }
94 
95  template<class ValueType, OdUInt64 writeBufferSize>
96  inline OdUInt32 writeValue(const ValueType& valueToWrite, std::vector<OdUInt8>& writeBuffer, const char* printfTemplate)
97  {
98  return appendValue<ValueType, writeBufferSize>(valueToWrite, writeBuffer, printfTemplate);
99  }
100 
101  template<class ValueType, OdUInt64 writeBufferSize>
102  inline OdUInt32 writeValue(const ValueType& valueToWrite, OdUInt8* writeBuffer, const char* printfTemplate)
103  {
104  return writeValue(valueToWrite, writeBuffer, writeBufferSize, printfTemplate);
105  }
106  }
107 }
108 
109 #endif
110 
unsigned int OdUInt32
unsigned char OdUInt8
GLsizei const GLchar *const * string
Definition: gles2_ext.h:292
const OdUInt32 writeErorCode
Definition: daiWriteUtils.h:45
OdUInt32 appendValue(const OdDbHandle &valueToWrite, std::vector< OdUInt8 > &writeBuffer)
OdUInt32 writeValue(const OdDbHandle &valueToWrite, std::vector< OdUInt8 > &writeBuffer)