0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BinObjMgt / BinObjMgt_Persistent.hxx
CommitLineData
42cf5bc1 1// Created on: 2002-10-30
2// Created by: Michael SAZONOV
3// Copyright (c) 2002-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _BinObjMgt_Persistent_HeaderFile
17#define _BinObjMgt_Persistent_HeaderFile
18
19#include <Standard.hxx>
20#include <Standard_DefineAlloc.hxx>
21#include <Standard_Handle.hxx>
22
23#include <TColStd_SequenceOfAddress.hxx>
24#include <Standard_Integer.hxx>
25#include <Standard_Boolean.hxx>
26#include <Standard_Character.hxx>
27#include <Standard_Byte.hxx>
28#include <Standard_ExtCharacter.hxx>
29#include <Standard_Real.hxx>
30#include <Standard_ShortReal.hxx>
31#include <Standard_CString.hxx>
32#include <BinObjMgt_PChar.hxx>
33#include <BinObjMgt_PByte.hxx>
34#include <BinObjMgt_PExtChar.hxx>
35#include <BinObjMgt_PInteger.hxx>
36#include <BinObjMgt_PReal.hxx>
37#include <BinObjMgt_PShortReal.hxx>
38#include <Standard_OStream.hxx>
39#include <Standard_IStream.hxx>
40#include <Standard_Address.hxx>
41class TCollection_AsciiString;
42class TCollection_ExtendedString;
43class TDF_Label;
44class Standard_GUID;
45class TDF_Data;
46
47
48//! Binary persistent representation of an object.
49//! Really it is used as a buffer for read/write an object.
50//!
51//! It takes care of Little/Big endian by inversing bytes
52//! in objects of standard types (see FSD_FileHeader.hxx
53//! for the default value of DO_INVERSE).
54class BinObjMgt_Persistent
55{
56public:
57
58 DEFINE_STANDARD_ALLOC
59
60
61 //! Empty constructor
62 Standard_EXPORT BinObjMgt_Persistent();
63
64 Standard_EXPORT BinObjMgt_Persistent& PutCharacter (const Standard_Character theValue);
65BinObjMgt_Persistent& operator << (const Standard_Character theValue)
66{
67 return PutCharacter(theValue);
68}
69
70 Standard_EXPORT BinObjMgt_Persistent& PutByte (const Standard_Byte theValue);
71BinObjMgt_Persistent& operator << (const Standard_Byte theValue)
72{
73 return PutByte(theValue);
74}
75
76 Standard_EXPORT BinObjMgt_Persistent& PutExtCharacter (const Standard_ExtCharacter theValue);
77BinObjMgt_Persistent& operator << (const Standard_ExtCharacter theValue)
78{
79 return PutExtCharacter(theValue);
80}
81
82 Standard_EXPORT BinObjMgt_Persistent& PutInteger (const Standard_Integer theValue);
83BinObjMgt_Persistent& operator << (const Standard_Integer theValue)
84{
85 return PutInteger(theValue);
86}
87
88 BinObjMgt_Persistent& PutBoolean (const Standard_Boolean theValue);
89 BinObjMgt_Persistent& operator << (const Standard_Boolean theValue)
90{
91 return PutBoolean(theValue);
92}
93
94 Standard_EXPORT BinObjMgt_Persistent& PutReal (const Standard_Real theValue);
95BinObjMgt_Persistent& operator << (const Standard_Real theValue)
96{
97 return PutReal(theValue);
98}
99
100 Standard_EXPORT BinObjMgt_Persistent& PutShortReal (const Standard_ShortReal theValue);
101BinObjMgt_Persistent& operator << (const Standard_ShortReal theValue)
102{
103 return PutShortReal(theValue);
104}
105
106 //! Offset in output buffer is not aligned
107 Standard_EXPORT BinObjMgt_Persistent& PutCString (const Standard_CString theValue);
108BinObjMgt_Persistent& operator << (const Standard_CString theValue)
109{
110 return PutCString(theValue);
111}
112
113 //! Offset in output buffer is word-aligned
114 Standard_EXPORT BinObjMgt_Persistent& PutAsciiString (const TCollection_AsciiString& theValue);
115BinObjMgt_Persistent& operator << (const TCollection_AsciiString& theValue)
116{
117 return PutAsciiString(theValue);
118}
119
120 //! Offset in output buffer is word-aligned
121 Standard_EXPORT BinObjMgt_Persistent& PutExtendedString (const TCollection_ExtendedString& theValue);
122BinObjMgt_Persistent& operator << (const TCollection_ExtendedString& theValue)
123{
124 return PutExtendedString(theValue);
125}
126
127 Standard_EXPORT BinObjMgt_Persistent& PutLabel (const TDF_Label& theValue);
128BinObjMgt_Persistent& operator << (const TDF_Label& theValue)
129{
130 return PutLabel(theValue);
131}
132
133 Standard_EXPORT BinObjMgt_Persistent& PutGUID (const Standard_GUID& theValue);
134BinObjMgt_Persistent& operator << (const Standard_GUID& theValue)
135{
136 return PutGUID(theValue);
137}
138
139 //! Put C array of char, theLength is the number of elements
140 Standard_EXPORT BinObjMgt_Persistent& PutCharArray (const BinObjMgt_PChar theArray, const Standard_Integer theLength);
141
142 //! Put C array of unsigned chars, theLength is the number of elements
143 Standard_EXPORT BinObjMgt_Persistent& PutByteArray (const BinObjMgt_PByte theArray, const Standard_Integer theLength);
144
145 //! Put C array of ExtCharacter, theLength is the number of elements
146 Standard_EXPORT BinObjMgt_Persistent& PutExtCharArray (const BinObjMgt_PExtChar theArray, const Standard_Integer theLength);
147
148 //! Put C array of int, theLength is the number of elements
149 Standard_EXPORT BinObjMgt_Persistent& PutIntArray (const BinObjMgt_PInteger theArray, const Standard_Integer theLength);
150
151 //! Put C array of double, theLength is the number of elements
152 Standard_EXPORT BinObjMgt_Persistent& PutRealArray (const BinObjMgt_PReal theArray, const Standard_Integer theLength);
153
154 //! Put C array of float, theLength is the number of elements
155 Standard_EXPORT BinObjMgt_Persistent& PutShortRealArray (const BinObjMgt_PShortReal theArray, const Standard_Integer theLength);
156
157 Standard_EXPORT const BinObjMgt_Persistent& GetCharacter (Standard_Character& theValue) const;
158const BinObjMgt_Persistent& operator >> (Standard_Character& theValue) const
159{
160 return GetCharacter(theValue);
161}
162
163 Standard_EXPORT const BinObjMgt_Persistent& GetByte (Standard_Byte& theValue) const;
164const BinObjMgt_Persistent& operator >> (Standard_Byte& theValue) const
165{
166 return GetByte(theValue);
167}
168
169 Standard_EXPORT const BinObjMgt_Persistent& GetExtCharacter (Standard_ExtCharacter& theValue) const;
170const BinObjMgt_Persistent& operator >> (Standard_ExtCharacter& theValue) const
171{
172 return GetExtCharacter(theValue);
173}
174
175 Standard_EXPORT const BinObjMgt_Persistent& GetInteger (Standard_Integer& theValue) const;
176const BinObjMgt_Persistent& operator >> (Standard_Integer& theValue) const
177{
178 return GetInteger(theValue);
179}
180
181 const BinObjMgt_Persistent& GetBoolean (Standard_Boolean& theValue) const;
182 const BinObjMgt_Persistent& operator >> (Standard_Boolean& theValue) const
183{
184 return GetBoolean(theValue);
185}
186
187 Standard_EXPORT const BinObjMgt_Persistent& GetReal (Standard_Real& theValue) const;
188const BinObjMgt_Persistent& operator >> (Standard_Real& theValue) const
189{
190 return GetReal(theValue);
191}
192
193 Standard_EXPORT const BinObjMgt_Persistent& GetShortReal (Standard_ShortReal& theValue) const;
194const BinObjMgt_Persistent& operator >> (Standard_ShortReal& theValue) const
195{
196 return GetShortReal(theValue);
197}
198
199 Standard_EXPORT const BinObjMgt_Persistent& GetAsciiString (TCollection_AsciiString& theValue) const;
200const BinObjMgt_Persistent& operator >> (TCollection_AsciiString& theValue) const
201{
202 return GetAsciiString(theValue);
203}
204
205 Standard_EXPORT const BinObjMgt_Persistent& GetExtendedString (TCollection_ExtendedString& theValue) const;
206const BinObjMgt_Persistent& operator >> (TCollection_ExtendedString& theValue) const
207{
208 return GetExtendedString(theValue);
209}
210
211 Standard_EXPORT const BinObjMgt_Persistent& GetLabel (const Handle(TDF_Data)& theDS, TDF_Label& theValue) const;
212
213 Standard_EXPORT const BinObjMgt_Persistent& GetGUID (Standard_GUID& theValue) const;
214const BinObjMgt_Persistent& operator >> (Standard_GUID& theValue) const
215{
216 return GetGUID(theValue);
217}
218
219 //! Get C array of char, theLength is the number of elements;
220 //! theArray must point to a
221 //! space enough to place theLength elements
222 Standard_EXPORT const BinObjMgt_Persistent& GetCharArray (const BinObjMgt_PChar theArray, const Standard_Integer theLength) const;
223
224 //! Get C array of unsigned chars, theLength is the number of elements;
225 //! theArray must point to a
226 //! space enough to place theLength elements
227 Standard_EXPORT const BinObjMgt_Persistent& GetByteArray (const BinObjMgt_PByte theArray, const Standard_Integer theLength) const;
228
229 //! Get C array of ExtCharacter, theLength is the number of elements;
230 //! theArray must point to a
231 //! space enough to place theLength elements
232 Standard_EXPORT const BinObjMgt_Persistent& GetExtCharArray (const BinObjMgt_PExtChar theArray, const Standard_Integer theLength) const;
233
234 //! Get C array of int, theLength is the number of elements;
235 //! theArray must point to a
236 //! space enough to place theLength elements
237 Standard_EXPORT const BinObjMgt_Persistent& GetIntArray (const BinObjMgt_PInteger theArray, const Standard_Integer theLength) const;
238
239 //! Get C array of double, theLength is the number of elements;
240 //! theArray must point to a
241 //! space enough to place theLength elements
242 Standard_EXPORT const BinObjMgt_Persistent& GetRealArray (const BinObjMgt_PReal theArray, const Standard_Integer theLength) const;
243
244 //! Get C array of float, theLength is the number of elements;
245 //! theArray must point to a
246 //! space enough to place theLength elements
247 Standard_EXPORT const BinObjMgt_Persistent& GetShortRealArray (const BinObjMgt_PShortReal theArray, const Standard_Integer theLength) const;
248
249 //! Tells the current position for get/put
250 Standard_Integer Position() const;
251
252 //! Sets the current position for get/put.
253 //! Resets an error state depending on the validity of thePos.
254 //! Returns the new state (value of IsOK())
255 Standard_Boolean SetPosition (const Standard_Integer thePos) const;
256
257 //! Truncates the buffer by current position,
258 //! i.e. updates mySize
259 void Truncate();
260
261 //! Indicates an error after Get methods or SetPosition
262 Standard_Boolean IsError() const;
263 Standard_Boolean operator !() const
264{
265 return IsError();
266}
267
268 //! Indicates a good state after Get methods or SetPosition
269 Standard_Boolean IsOK() const;
270operator Standard_Boolean () const { return IsOK(); }
271
272 //! Initializes me to reuse again
273 Standard_EXPORT void Init();
274
275 //! Sets the Id of the object
276 void SetId (const Standard_Integer theId);
277
278 //! Sets the Id of the type of the object
279 void SetTypeId (const Standard_Integer theId);
280
281 //! Returns the Id of the object
282 Standard_Integer Id() const;
283
284 //! Returns the Id of the type of the object
285 Standard_Integer TypeId() const;
286
287 //! Returns the length of data
288 Standard_Integer Length() const;
289
290 //! Stores <me> to the stream.
291 //! inline Standard_OStream& operator<< (Standard_OStream&,
292 //! BinObjMgt_Persistent&) is also available
293 Standard_EXPORT Standard_OStream& Write (Standard_OStream& theOS);
294
295 //! Retrieves <me> from the stream.
296 //! inline Standard_IStream& operator>> (Standard_IStream&,
297 //! BinObjMgt_Persistent&) is also available
298 Standard_EXPORT Standard_IStream& Read (Standard_IStream& theIS);
299
300 //! Frees the allocated memory;
301 //! This object can be reused after call to Init
302 Standard_EXPORT void Destroy();
303~BinObjMgt_Persistent()
304{
305 Destroy();
306}
307
308
309
310
311protected:
312
313
314
315
316
317private:
318
319
320 //! Aligns myOffset to the given size;
321 //! enters the next piece if the end of the current one is reached;
322 //! toClear==true means to fill unused space by 0
323 void alignOffset (const Standard_Integer theSize, const Standard_Boolean toClear = Standard_False) const;
324
325 //! Prepares the room for theSize bytes;
326 //! returns the number of pieces except for the current one
327 //! are to be occupied
328 Standard_Integer prepareForPut (const Standard_Integer theSize);
329
330 //! Allocates theNbPieces more pieces
331 Standard_EXPORT void incrementData (const Standard_Integer theNbPieces);
332
333 //! Checks if there is no more data of the given size starting
334 //! from the current position in myData
335 Standard_Boolean noMoreData (const Standard_Integer theSize) const;
336
337 //! Puts theLength bytes from theArray
338 Standard_EXPORT void putArray (const Standard_Address theArray, const Standard_Integer theSize);
339
340 //! Gets theLength bytes into theArray
341 Standard_EXPORT void getArray (const Standard_Address theArray, const Standard_Integer theSize) const;
342
343 //! Inverses bytes in the data addressed by the given values
344 Standard_EXPORT void inverseExtCharData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
345
346 //! Inverses bytes in the data addressed by the given values
347 Standard_EXPORT void inverseIntData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
348
349 //! Inverses bytes in the data addressed by the given values
350 Standard_EXPORT void inverseRealData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
351
352 //! Inverses bytes in the data addressed by the given values
353 Standard_EXPORT void inverseShortRealData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
354
355
356 TColStd_SequenceOfAddress myData;
357 Standard_Integer myIndex;
358 Standard_Integer myOffset;
359 Standard_Integer mySize;
360 Standard_Boolean myIsError;
361
362
363};
364
365
366#include <BinObjMgt_Persistent.lxx>
367
368
369
370
371
372#endif // _BinObjMgt_Persistent_HeaderFile