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