CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
ArraysIO.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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-2024 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 _ARRAYREAD_H_
25#define _ARRAYREAD_H_
26
27#include "DbFiler.h"
28#include "Ge/GePoint2d.h"
29#include "Ge/GeVector2d.h"
30#include "Ge/GePoint3d.h"
31#include "Ge/GeVector3d.h"
32//#error
33
37namespace OdDbRdArray
38{
39 // Note: Direct using of arr.resize(pFiler->rdInt32())
40 // produce memory allocation error in case of invalid size value.
41 // So read data in parts to get exception with invalid data.
42 //
43 // Example:
44 // Instead of
45 // m_Bulges.resize(numBulges); // Out of Memory exception may happen
46 // for (i = 0; i < numBulges; i++)
47 // {
48 // pBulges[i] = pFiler->rdDouble();
49 // }
50 // Use
51 // OdDbRdArray::rdArray<OdDbRdArray::Double>(pFiler, numBulges, m_Bulges);
52
53 // Custom read
54 // Instead of
55 // m_Bulges.resize(numBulges); // Out of Memory exception may happen
56 // for (i = 0; i < numBulges; i++)
57 // {
58 // pBulges[i] = pFiler->rdDouble();
59 // if( fabs( pBulges[i] ) >= 1.0e16)
60 // pBulges[i] = 0;
61 // }
62 // Use
63 // namespace OdPolyline
64 // {
65 // struct Bulge
66 // {
67 // static void read(OdDbDwgFiler* pFiler, double& val)
68 // {
69 // val = pFiler->rdDouble();
70 // if (fabs(val) >= 1.0e16)
71 // val = 0;
72 // }
73 // static void write(OdDbDwgFiler* pFiler, const double& val)
74 // {
75 // pFiler->wrDouble(val);
76 // }
77 // };
78 // }
79 // ...
80 // OdDbRdArray::rdArray<OdPolyline::Bulge>(pFiler, numBulges, m_Bulges);
81 //
82 // Below find implementations of read/write functions for
83 // OdInt8, OdInt16, Odint32, double, OdGePoint2d, OdGeVector2d, OdGePoint3d, OdGeVector3d
84
85#define ODA_ARRREAD_PAGESIZE 0xffff
86
87
88
90 template <class R, class A>
91 inline void rdArray(OdDbDwgFiler* pFiler, OdUInt32 nSize, A& arr)
92 {
93 if (pFiler->filerType() != OdDbFiler::kFileFiler)
94 {
95 arr.resize(nSize);
96 typename A::iterator pCurr = arr.begin();
97 for (unsigned i = 0; i < nSize; ++i)
98 {
99 R::read(pFiler, *pCurr++);
100 }
101 }
102 else
103 {
104 arr.resize(0);
105 OdUInt32 nPagedSize = 0, nIndex = 0;
106 typename A::value_type val;
107 do
108 {
109 nPagedSize = odmin(nPagedSize + ODA_ARRREAD_PAGESIZE, nSize);
110 arr.reserve(nPagedSize);
111 for (; nIndex < nPagedSize; ++nIndex)
112 {
113 R::read(pFiler, val);
114 arr.push_back( std::move( val ) );
115 }
116 } while (nPagedSize < nSize);
117 }
118 }
119
120 template< class R, class A>
121 inline void wrArray(OdDbDwgFiler* pFiler, const A& arr)
122 {
123 typename A::const_iterator pCurr = arr.begin();
124 unsigned long i = arr.size();
125
126 while (i--)
127 R::write(pFiler, *pCurr++);
128 }
129
131 struct Int8
132 {
133 static void read(OdDbDwgFiler* pFiler, OdInt8& val)
134 {
135 val = pFiler->rdInt8();
136 }
137 static void write(OdDbDwgFiler* pFiler, const OdInt8& val)
138 {
139 pFiler->wrInt8(val);
140 }
141 };
142
143 struct Int16
144 {
145 static void read(OdDbDwgFiler* pFiler, OdInt16& val)
146 {
147 val = pFiler->rdInt16();
148 }
149 static void write(OdDbDwgFiler* pFiler, const OdInt16& val)
150 {
151 pFiler->wrInt16(val);
152 }
153 };
154
155 struct Int32
156 {
157 static void read(OdDbDwgFiler* pFiler, OdInt32& val)
158 {
159 val = pFiler->rdInt32();
160 }
161 static void write(OdDbDwgFiler* pFiler, const OdInt32& val)
162 {
163 pFiler->wrInt32(val);
164 }
165 };
166
167 struct Double
168 {
169 static void read(OdDbDwgFiler* pFiler, double& val)
170 {
171 val = pFiler->rdDouble();
172 }
173 static void write(OdDbDwgFiler* pFiler, const double& val)
174 {
175 pFiler->wrDouble(val);
176 }
177 };
178
180 struct Point2d
181 {
182 static void read(OdDbDwgFiler* pFiler, OdGePoint2d& val)
183 {
184 val = pFiler->rdPoint2d();
185 }
186 static void write(OdDbDwgFiler* pFiler, const OdGePoint2d& val)
187 {
188 pFiler->wrPoint2d(val);
189 }
190 };
191
192 struct Vector2d
193 {
194 static void read(OdDbDwgFiler* pFiler, OdGeVector2d& val)
195 {
196 val = pFiler->rdVector2d();
197 }
198 static void write(OdDbDwgFiler* pFiler, const OdGeVector2d& val)
199 {
200 pFiler->wrVector2d(val);
201 }
202 };
203
204 struct Point3d
205 {
206 static void read(OdDbDwgFiler* pFiler, OdGePoint3d& val)
207 {
208 val = pFiler->rdPoint3d();
209 }
210 static void write(OdDbDwgFiler* pFiler, const OdGePoint3d& val)
211 {
212 pFiler->wrPoint3d(val);
213 }
214 };
215
216 struct Vector3d
217 {
218 static void read(OdDbDwgFiler* pFiler, OdGeVector3d& val)
219 {
220 val = pFiler->rdVector3d();
221 }
222 static void write(OdDbDwgFiler* pFiler, const OdGeVector3d& val)
223 {
224 pFiler->wrVector3d(val);
225 }
226 };
227}
228#endif //_ARRAYREAD_H_
#define ODA_ARRREAD_PAGESIZE
Definition ArraysIO.h:85
ODRX_CONSTEXPR const T & odmin(const T &a, const T &b)
Definition OdPlatform.h:64
unsigned int OdUInt32
short OdInt16
signed char OdInt8
int OdInt32
virtual void wrInt32(OdInt32 value)=0
virtual OdGeVector2d rdVector2d()=0
virtual void wrDouble(double value)=0
virtual OdGePoint3d rdPoint3d()=0
virtual OdInt32 rdInt32()=0
virtual void wrPoint2d(const OdGePoint2d &value)=0
virtual OdInt8 rdInt8()=0
virtual void wrInt8(OdInt8 value)=0
virtual void wrVector2d(const OdGeVector2d &value)=0
virtual double rdDouble()=0
virtual void wrInt16(OdInt16 value)=0
virtual OdGePoint2d rdPoint2d()=0
virtual OdInt16 rdInt16()=0
virtual void wrVector3d(const OdGeVector3d &value)=0
virtual void wrPoint3d(const OdGePoint3d &value)=0
virtual OdGeVector3d rdVector3d()=0
virtual FilerType filerType() const =0
@ kFileFiler
Definition DbFiler.h:83
void wrArray(OdDbDwgFiler *pFiler, const A &arr)
Definition ArraysIO.h:121
void rdArray(OdDbDwgFiler *pFiler, OdUInt32 nSize, A &arr)
Definition ArraysIO.h:91
static void read(OdDbDwgFiler *pFiler, double &val)
Definition ArraysIO.h:169
static void write(OdDbDwgFiler *pFiler, const double &val)
Definition ArraysIO.h:173
static void write(OdDbDwgFiler *pFiler, const OdInt16 &val)
Definition ArraysIO.h:149
static void read(OdDbDwgFiler *pFiler, OdInt16 &val)
Definition ArraysIO.h:145
static void read(OdDbDwgFiler *pFiler, OdInt32 &val)
Definition ArraysIO.h:157
static void write(OdDbDwgFiler *pFiler, const OdInt32 &val)
Definition ArraysIO.h:161
static void read(OdDbDwgFiler *pFiler, OdInt8 &val)
Definition ArraysIO.h:133
static void write(OdDbDwgFiler *pFiler, const OdInt8 &val)
Definition ArraysIO.h:137
static void write(OdDbDwgFiler *pFiler, const OdGePoint2d &val)
Definition ArraysIO.h:186
static void read(OdDbDwgFiler *pFiler, OdGePoint2d &val)
Definition ArraysIO.h:182
static void read(OdDbDwgFiler *pFiler, OdGePoint3d &val)
Definition ArraysIO.h:206
static void write(OdDbDwgFiler *pFiler, const OdGePoint3d &val)
Definition ArraysIO.h:210
static void write(OdDbDwgFiler *pFiler, const OdGeVector2d &val)
Definition ArraysIO.h:198
static void read(OdDbDwgFiler *pFiler, OdGeVector2d &val)
Definition ArraysIO.h:194
static void read(OdDbDwgFiler *pFiler, OdGeVector3d &val)
Definition ArraysIO.h:218
static void write(OdDbDwgFiler *pFiler, const OdGeVector3d &val)
Definition ArraysIO.h:222