1 // Created on: 2002-10-30
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BinObjMgt_Persistent.hxx>
18 #include <FSD_FileHeader.hxx>
19 #include <Standard_GUID.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <TCollection_ExtendedString.hxx>
22 #include <TColStd_ListIteratorOfListOfInteger.hxx>
23 #include <TColStd_ListOfInteger.hxx>
24 #include <TDF_Data.hxx>
25 #include <TDF_Label.hxx>
26 #include <TDF_Tool.hxx>
28 #define BP_INTSIZE ((Standard_Integer)sizeof(Standard_Integer))
29 #define BP_EXTCHARSIZE ((Standard_Integer)sizeof(Standard_ExtCharacter))
30 #define BP_REALSIZE ((Standard_Integer)sizeof(Standard_Real))
31 #define BP_SHORTREALSIZE ((Standard_Integer)sizeof(Standard_ShortReal))
32 #define BP_UUIDSIZE ((Standard_Integer)sizeof(BinObjMgt_UUID))
34 // We define a GUID structure that is different from Standard_UUID because
35 // the latter contains a 'unsigned long' member that has variables size
36 // (4 or 8 bits) thus making the persistent files non-portable.
37 // This structure below ensures the portability.
39 unsigned int Data1 ; // 4-bytes long on all OS
40 unsigned short Data2 ; // 2-bytes long on all OS
41 unsigned short Data3 ; // 2-bytes long on all OS
42 unsigned char Data4[8] ; // 8-bytes long on all OS
45 //=======================================================================
46 //function : BinObjMgt_Persistent
47 //purpose : Empty constructor
48 //=======================================================================
50 BinObjMgt_Persistent::BinObjMgt_Persistent ()
52 myOffset(BP_HEADSIZE),
54 myIsError (Standard_False)
59 //=======================================================================
61 //purpose : Initializes me to reuse again
62 //=======================================================================
64 void BinObjMgt_Persistent::Init ()
66 if (myData.IsEmpty()) {
67 Standard_Address aPiece = Standard::Allocate (BP_PIECESIZE);
68 myData.Append (aPiece);
70 Standard_Integer *aData = (Standard_Integer*) myData(1);
71 aData[0] = 0; // Type Id
72 aData[1] = 0; // Object Id
73 aData[2] = 0; // Data length
75 myOffset = BP_HEADSIZE;
77 myIsError = Standard_False;
80 //=======================================================================
82 //purpose : Stores <me> to the stream.
83 // inline Standard_OStream& operator<< (Standard_OStream&,
84 // const BinObjMgt_Persistent&) is also available
85 //=======================================================================
87 Standard_OStream& BinObjMgt_Persistent::Write (Standard_OStream& theOS)
89 Standard_Integer nbWritten = 0;
90 Standard_Integer *aData = (Standard_Integer*) myData(1);
92 aData[2] = mySize - BP_HEADSIZE;
94 aData[0] = InverseInt (aData[0]);
95 aData[1] = InverseInt (aData[1]);
96 aData[2] = InverseInt (aData[2]);
98 for (Standard_Integer i=1;
99 theOS && nbWritten < mySize && i <= myData.Length();
101 Standard_Integer nbToWrite = Min (mySize - nbWritten, BP_PIECESIZE);
102 theOS.write ((char*)myData(i), nbToWrite);
103 nbWritten += nbToWrite;
106 myOffset = BP_HEADSIZE;
107 mySize = BP_HEADSIZE;
108 myIsError = Standard_False;
112 //=======================================================================
114 //purpose : Retrieves <me> from the stream.
115 // inline Standard_IStream& operator>> (Standard_IStream&,
116 // BinObjMgt_Persistent&) is also available
117 //=======================================================================
119 Standard_IStream& BinObjMgt_Persistent::Read (Standard_IStream& theIS)
122 myOffset = BP_HEADSIZE;
123 mySize = BP_HEADSIZE;
124 myIsError = Standard_False;
126 Standard_Integer *aData = (Standard_Integer*) myData(1);
127 aData[0] = 0; // Type Id
128 aData[1] = 0; // Object Id
129 aData[2] = 0; // Data length
132 theIS.read ((char*) &aData[0], BP_INTSIZE);
134 aData[0] = InverseInt (aData[0]);
136 if (theIS && aData[0] > 0) {
137 // read Id and Length
138 theIS.read ((char*)&aData[1], 2 * BP_INTSIZE);
140 aData[1] = InverseInt (aData[1]);
141 aData[2] = InverseInt (aData[2]);
143 if (theIS && aData[1] > 0 && aData[2] > 0) {
145 // read remaining data
146 Standard_Integer nbRead = BP_HEADSIZE;
147 for (Standard_Integer i=1;
148 theIS && nbRead < mySize;
150 if (i > myData.Length()) {
151 // grow myData dynamically
152 Standard_Address aPiece = Standard::Allocate (BP_PIECESIZE);
153 myData.Append (aPiece);
155 Standard_Integer nbToRead = Min (mySize - nbRead, BP_PIECESIZE);
156 char *ptr = (char*)myData(i);
158 // 1st piece: reduce the number of bytes by header size
160 if (nbToRead == BP_PIECESIZE) nbToRead -= BP_HEADSIZE;
162 theIS.read (ptr, nbToRead);
172 //=======================================================================
174 //purpose : Frees the allocated memory
175 //=======================================================================
177 void BinObjMgt_Persistent::Destroy ()
179 for (Standard_Integer i=1; i <= myData.Length(); i++) {
180 Standard::Free (myData(i));
183 myIndex = myOffset = mySize = 0;
186 //=======================================================================
187 //function : incrementData
188 //purpose : Allocates theNbPieces more pieces
189 //=======================================================================
191 void BinObjMgt_Persistent::incrementData
192 (const Standard_Integer theNbPieces)
194 for (Standard_Integer i=1; i <= theNbPieces; i++) {
195 Standard_Address aPiece = Standard::Allocate (BP_PIECESIZE);
196 myData.Append (aPiece);
200 //=======================================================================
201 //function : PutCharacter
203 //=======================================================================
205 BinObjMgt_Persistent& BinObjMgt_Persistent::PutCharacter
206 (const Standard_Character theValue)
210 Standard_Character *aData = (Standard_Character*) myData(myIndex) + myOffset;
216 //=======================================================================
219 //=======================================================================
221 BinObjMgt_Persistent& BinObjMgt_Persistent::PutByte
222 (const Standard_Byte theValue)
226 Standard_Byte *aData = (Standard_Byte*) myData(myIndex) + myOffset;
232 //=======================================================================
233 //function : PutExtCharacter
235 //=======================================================================
237 BinObjMgt_Persistent& BinObjMgt_Persistent::PutExtCharacter
238 (const Standard_ExtCharacter theValue)
240 alignOffset (BP_EXTCHARSIZE, Standard_True);
241 prepareForPut (BP_EXTCHARSIZE);
242 Standard_ExtCharacter *aData =
243 (Standard_ExtCharacter*) ((char*)myData(myIndex) + myOffset);
245 *aData = InverseExtChar (theValue);
249 myOffset += BP_EXTCHARSIZE;
253 //=======================================================================
254 //function : PutInteger
256 //=======================================================================
258 BinObjMgt_Persistent& BinObjMgt_Persistent::PutInteger
259 (const Standard_Integer theValue)
261 alignOffset (BP_INTSIZE, Standard_True);
262 prepareForPut (BP_INTSIZE);
263 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
265 *aData = InverseInt (theValue);
269 myOffset += BP_INTSIZE;
273 //=======================================================================
276 //=======================================================================
278 BinObjMgt_Persistent& BinObjMgt_Persistent::PutReal
279 (const Standard_Real theValue)
281 alignOffset (BP_INTSIZE, Standard_True);
282 Standard_Integer nbPieces = prepareForPut (BP_REALSIZE);
284 // the value intersects a piece boundary => go a long way
286 Standard_Integer aStartIndex = myIndex;
287 Standard_Integer aStartOffset = myOffset;
289 putArray ((void*) &theValue, BP_REALSIZE);
291 inverseRealData (aStartIndex, aStartOffset, BP_REALSIZE);
295 // the value fits in the current piece => put it quickly
296 Standard_Real *aData = (Standard_Real*) ((char*)myData(myIndex) + myOffset);
298 *aData = InverseReal (theValue);
302 myOffset += BP_REALSIZE;
307 //=======================================================================
308 //function : PutShortReal
310 //=======================================================================
312 BinObjMgt_Persistent& BinObjMgt_Persistent::PutShortReal
313 (const Standard_ShortReal theValue)
315 alignOffset (BP_INTSIZE, Standard_True);
316 prepareForPut (BP_SHORTREALSIZE);
317 Standard_ShortReal *aData = (Standard_ShortReal*) ((char*)myData(myIndex) + myOffset);
319 *aData = InverseShortReal (theValue);
323 myOffset += BP_SHORTREALSIZE;
327 //=======================================================================
328 //function : PutCString
329 //purpose : Offset in output buffer is not aligned
330 //=======================================================================
332 BinObjMgt_Persistent& BinObjMgt_Persistent::PutCString
333 (const Standard_CString theValue)
336 Standard_Integer aSize = (Standard_Integer)(strlen (theValue) + 1);
337 prepareForPut (aSize);
338 putArray ((void* const)theValue, aSize);
342 //=======================================================================
343 //function : PutAsciiString
344 //purpose : Offset in output buffer is word-aligned
345 //=======================================================================
347 BinObjMgt_Persistent& BinObjMgt_Persistent::PutAsciiString
348 (const TCollection_AsciiString& theValue)
350 alignOffset (BP_INTSIZE, Standard_True);
351 Standard_Integer aSize = theValue.Length() + 1;
352 prepareForPut (aSize);
353 putArray ((void* const)theValue.ToCString(), aSize);
357 //=======================================================================
358 //function : PutExtendedString
359 //purpose : Offset in output buffer is word-aligned
360 //=======================================================================
362 BinObjMgt_Persistent& BinObjMgt_Persistent::PutExtendedString
363 (const TCollection_ExtendedString& theValue)
365 alignOffset (BP_INTSIZE, Standard_True);
366 Standard_Integer aSize = (theValue.Length() + 1) * BP_EXTCHARSIZE;
367 prepareForPut (aSize);
369 Standard_Integer aStartIndex = myIndex;
370 Standard_Integer aStartOffset = myOffset;
372 putArray ((void* const)theValue.ToExtString(), aSize);
374 inverseExtCharData (aStartIndex, aStartOffset, aSize - BP_EXTCHARSIZE);
379 //=======================================================================
380 //function : PutLabel
382 //=======================================================================
384 BinObjMgt_Persistent& BinObjMgt_Persistent::PutLabel
385 (const TDF_Label& theValue)
387 alignOffset (BP_INTSIZE, Standard_True);
388 Standard_Integer aLen = (theValue.IsNull() ? 0 : theValue.Depth()+1);
389 prepareForPut ((aLen + 1) * BP_INTSIZE);
390 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
393 *aData++ = InverseInt (aLen);
397 myOffset += BP_INTSIZE;
398 if (!theValue.IsNull()) {
399 TColStd_ListOfInteger aTagList;
400 TDF_Tool::TagList (theValue, aTagList);
401 TColStd_ListIteratorOfListOfInteger itTag(aTagList);
402 for (; itTag.More(); itTag.Next()) {
403 if (myOffset >= BP_PIECESIZE) {
406 aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
409 *aData++ = InverseInt (itTag.Value());
411 *aData++ = itTag.Value();
413 myOffset += BP_INTSIZE;
419 //=======================================================================
422 //=======================================================================
424 BinObjMgt_Persistent& BinObjMgt_Persistent::PutGUID
425 (const Standard_GUID& theValue)
427 alignOffset (BP_INTSIZE, Standard_True);
428 prepareForPut (BP_UUIDSIZE);
429 const Standard_UUID aStandardUUID = theValue.ToUUID();
430 BinObjMgt_UUID anUUID;
431 anUUID.Data1 = (unsigned int) aStandardUUID.Data1;
432 anUUID.Data2 = (unsigned short) aStandardUUID.Data2;
433 anUUID.Data3 = (unsigned short) aStandardUUID.Data3;
434 anUUID.Data4[0] = aStandardUUID.Data4[0];
435 anUUID.Data4[1] = aStandardUUID.Data4[1];
436 anUUID.Data4[2] = aStandardUUID.Data4[2];
437 anUUID.Data4[3] = aStandardUUID.Data4[3];
438 anUUID.Data4[4] = aStandardUUID.Data4[4];
439 anUUID.Data4[5] = aStandardUUID.Data4[5];
440 anUUID.Data4[6] = aStandardUUID.Data4[6];
441 anUUID.Data4[7] = aStandardUUID.Data4[7];
443 anUUID.Data1 = (unsigned int) InverseInt (anUUID.Data1);
444 anUUID.Data2 = (unsigned short) InverseExtChar (anUUID.Data2);
445 anUUID.Data3 = (unsigned short) InverseExtChar (anUUID.Data3);
447 putArray (&anUUID, BP_UUIDSIZE);
451 //=======================================================================
452 //function : PutCharArray
453 //purpose : Put C array of char, theLength is the number of elements
454 //=======================================================================
456 BinObjMgt_Persistent& BinObjMgt_Persistent::PutCharArray
457 (const BinObjMgt_PChar theArray,
458 const Standard_Integer theLength)
461 prepareForPut (theLength);
462 putArray (theArray, theLength);
466 //=======================================================================
467 //function : PutByteArray
468 //purpose : Put C array of byte, theLength is the number of elements
469 //=======================================================================
471 BinObjMgt_Persistent& BinObjMgt_Persistent::PutByteArray
472 (const BinObjMgt_PByte theArray,
473 const Standard_Integer theLength)
476 prepareForPut (theLength);
477 putArray (theArray, theLength);
481 //=======================================================================
482 //function : PutExtCharArray
483 //purpose : Put C array of ExtCharacter, theLength is the number of elements
484 //=======================================================================
486 BinObjMgt_Persistent& BinObjMgt_Persistent::PutExtCharArray
487 (const BinObjMgt_PExtChar theArray,
488 const Standard_Integer theLength)
490 alignOffset (BP_EXTCHARSIZE, Standard_True);
491 Standard_Integer aSize = theLength * BP_EXTCHARSIZE;
492 prepareForPut (aSize);
494 Standard_Integer aStartIndex = myIndex;
495 Standard_Integer aStartOffset = myOffset;
497 putArray (theArray, aSize);
499 inverseExtCharData (aStartIndex, aStartOffset, aSize);
504 //=======================================================================
505 //function : PutIntArray
506 //purpose : Put C array of int, theLength is the number of elements
507 //=======================================================================
509 BinObjMgt_Persistent& BinObjMgt_Persistent::PutIntArray
510 (const BinObjMgt_PInteger theArray,
511 const Standard_Integer theLength)
513 alignOffset (BP_INTSIZE, Standard_True);
514 Standard_Integer aSize = theLength * BP_INTSIZE;
515 prepareForPut (aSize);
517 Standard_Integer aStartIndex = myIndex;
518 Standard_Integer aStartOffset = myOffset;
520 putArray (theArray, aSize);
522 inverseIntData (aStartIndex, aStartOffset, aSize);
527 //=======================================================================
528 //function : PutRealArray
529 //purpose : Put C array of double, theLength is the number of elements
530 //=======================================================================
532 BinObjMgt_Persistent& BinObjMgt_Persistent::PutRealArray
533 (const BinObjMgt_PReal theArray,
534 const Standard_Integer theLength)
536 alignOffset (BP_INTSIZE, Standard_True);
537 Standard_Integer aSize = theLength * BP_REALSIZE;
538 prepareForPut (aSize);
540 Standard_Integer aStartIndex = myIndex;
541 Standard_Integer aStartOffset = myOffset;
543 putArray (theArray, aSize);
545 inverseRealData (aStartIndex, aStartOffset, aSize);
550 //=======================================================================
551 //function : PutShortRealArray
552 //purpose : Put C array of float, theLength is the number of elements
553 //=======================================================================
555 BinObjMgt_Persistent& BinObjMgt_Persistent::PutShortRealArray
556 (const BinObjMgt_PShortReal theArray,
557 const Standard_Integer theLength)
559 alignOffset (BP_INTSIZE, Standard_True);
560 Standard_Integer aSize = theLength * BP_SHORTREALSIZE;
561 prepareForPut (aSize);
563 Standard_Integer aStartIndex = myIndex;
564 Standard_Integer aStartOffset = myOffset;
566 putArray (theArray, aSize);
568 inverseShortRealData (aStartIndex, aStartOffset, aSize);
573 //=======================================================================
574 //function : GetCharacter
576 //=======================================================================
578 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetCharacter
579 (Standard_Character& theValue) const
582 if (noMoreData (1)) return *this;
583 Standard_Character *aData = (Standard_Character*) myData(myIndex) + myOffset;
585 ((BinObjMgt_Persistent*)this)->myOffset++;
589 //=======================================================================
592 //=======================================================================
594 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetByte
595 (Standard_Byte& theValue) const
598 if (noMoreData (1)) return *this;
599 Standard_Byte *aData = (Standard_Byte*) myData(myIndex) + myOffset;
601 ((BinObjMgt_Persistent*)this)->myOffset++;
605 //=======================================================================
606 //function : GetExtCharacter
608 //=======================================================================
610 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetExtCharacter
611 (Standard_ExtCharacter& theValue) const
613 alignOffset (BP_EXTCHARSIZE);
614 if (noMoreData (BP_EXTCHARSIZE)) return *this;
615 Standard_ExtCharacter *aData =
616 (Standard_ExtCharacter*) ((char*)myData(myIndex) + myOffset);
618 theValue = InverseExtChar (*aData);
622 ((BinObjMgt_Persistent*)this)->myOffset += BP_EXTCHARSIZE;
626 //=======================================================================
627 //function : GetInteger
629 //=======================================================================
631 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetInteger
632 (Standard_Integer& theValue) const
634 alignOffset (BP_INTSIZE);
635 if (noMoreData (BP_INTSIZE)) return *this;
636 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
638 theValue = InverseInt (*aData);
642 ((BinObjMgt_Persistent*)this)->myOffset += BP_INTSIZE;
646 //=======================================================================
649 //=======================================================================
651 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetReal
652 (Standard_Real& theValue) const
654 alignOffset (BP_INTSIZE);
655 if (noMoreData (BP_REALSIZE)) return *this;
656 Standard_Integer nbPieces = (myOffset + BP_REALSIZE - 1) / BP_PIECESIZE;
658 // the value intersects a piece boundary => go a long way
659 getArray ((void*) &theValue, BP_REALSIZE);
662 // the value fits in the current piece => get it quickly
663 Standard_Real *aData = (Standard_Real*) ((char*)myData(myIndex) + myOffset);
665 ((BinObjMgt_Persistent*)this)->myOffset += BP_REALSIZE;
668 theValue = InverseReal (theValue);
673 //=======================================================================
674 //function : GetShortReal
676 //=======================================================================
678 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetShortReal
679 (Standard_ShortReal& theValue) const
681 alignOffset (BP_INTSIZE);
682 if (noMoreData (BP_SHORTREALSIZE)) return *this;
683 Standard_ShortReal *aData = (Standard_ShortReal*) ((char*)myData(myIndex) + myOffset);
685 theValue = InverseShortReal (*aData);
689 ((BinObjMgt_Persistent*)this)->myOffset += BP_SHORTREALSIZE;
693 //=======================================================================
694 //function : GetAsciiString
696 //=======================================================================
698 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetAsciiString
699 (TCollection_AsciiString& theValue) const
701 alignOffset (BP_INTSIZE);
702 Standard_Integer aStartIndex = myIndex;
703 Standard_Integer aStartOffset = myOffset;
704 BinObjMgt_Persistent* me = (BinObjMgt_Persistent*)this;
705 char *aData = (char*) myData(myIndex) + myOffset;
707 // count the string length
708 while (!noMoreData (1) && *aData++) {
710 if (myOffset >= BP_PIECESIZE) {
712 aData = (char*) myData(++me->myIndex);
716 me->myIndex = aStartIndex;
717 me->myOffset = aStartOffset;
720 me->myOffset++; // count the end null char
722 if (myIndex == aStartIndex) {
723 // all string is in one piece => simply copy
724 theValue = aData - myOffset + aStartOffset;
727 // work through buffer string
728 Standard_Integer aSize = (myIndex - aStartIndex) * BP_PIECESIZE +
729 myOffset - aStartOffset;
730 Standard_Address aString = Standard::Allocate (aSize);
731 me->myIndex = aStartIndex;
732 me->myOffset = aStartOffset;
733 getArray (aString, aSize);
734 theValue = (char*) aString;
735 Standard::Free (aString);
741 //=======================================================================
742 //function : GetExtendedString
744 //=======================================================================
746 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetExtendedString
747 (TCollection_ExtendedString& theValue) const
749 alignOffset (BP_INTSIZE);
750 Standard_Integer aStartIndex = myIndex;
751 Standard_Integer aStartOffset = myOffset;
752 BinObjMgt_Persistent* me = (BinObjMgt_Persistent*)this;
753 Standard_ExtCharacter *aData =
754 (Standard_ExtCharacter*) ((char*)myData(myIndex) + myOffset);
756 // count the string length
757 while (!noMoreData (1) && *aData++) {
758 me->myOffset += BP_EXTCHARSIZE;
759 if (myOffset >= BP_PIECESIZE) {
761 aData = (Standard_ExtCharacter*) myData(++me->myIndex);
765 me->myIndex = aStartIndex;
766 me->myOffset = aStartOffset;
769 me->myOffset += BP_EXTCHARSIZE; // count the end null char
771 if (myIndex == aStartIndex) {
772 // all string is in one piece => simply copy
773 theValue = aData - (myOffset - aStartOffset) / BP_EXTCHARSIZE;
776 // work through buffer string
777 Standard_Integer aSize = (myIndex - aStartIndex) * BP_PIECESIZE +
778 (myOffset - aStartOffset);
779 Standard_Address aString = Standard::Allocate (aSize);
780 me->myIndex = aStartIndex;
781 me->myOffset = aStartOffset;
782 getArray (aString, aSize);
783 theValue = (Standard_ExtCharacter*) aString;
784 Standard::Free (aString);
787 Standard_PExtCharacter aString = (Standard_PExtCharacter)theValue.ToExtString();
788 for (Standard_Integer i=0; i < theValue.Length(); i++)
789 aString[i] = InverseExtChar (aString[i]);
795 //=======================================================================
796 //function : GetLabel
798 //=======================================================================
800 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetLabel
801 (const Handle(TDF_Data)& theDS,
802 TDF_Label& theValue) const
805 alignOffset (BP_INTSIZE);
806 if (noMoreData (BP_INTSIZE)) return *this;
807 BinObjMgt_Persistent* me = (BinObjMgt_Persistent*)this;
808 // retrieve nb of tags
809 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
810 Standard_Integer aLen = *aData++;
812 aLen = InverseInt (aLen);
814 me->myOffset += BP_INTSIZE;
815 if (noMoreData (aLen * BP_INTSIZE)) return *this;
819 TColStd_ListOfInteger aTagList;
821 if (myOffset >= BP_PIECESIZE) {
824 aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
827 aTagList.Append (InverseInt (*aData++));
829 aTagList.Append (*aData++);
831 me->myOffset += BP_INTSIZE;
834 // find label by entry
835 TDF_Tool::Label (theDS, aTagList, theValue, Standard_True);
840 //=======================================================================
843 //=======================================================================
845 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetGUID
846 (Standard_GUID& theValue) const
848 alignOffset (BP_INTSIZE);
849 if (noMoreData (BP_UUIDSIZE))
851 BinObjMgt_UUID anUUID;
852 getArray (&anUUID, BP_UUIDSIZE);
854 anUUID.Data1 = (unsigned int) InverseInt (anUUID.Data1);
855 anUUID.Data2 = (unsigned short) InverseExtChar (anUUID.Data2);
856 anUUID.Data3 = (unsigned short) InverseExtChar (anUUID.Data3);
858 theValue = Standard_GUID (anUUID.Data1, anUUID.Data2, anUUID.Data3,
859 ((anUUID.Data4[0] << 8) | (anUUID.Data4[1])),
860 anUUID.Data4[2], anUUID.Data4[3], anUUID.Data4[4],
861 anUUID.Data4[5], anUUID.Data4[6], anUUID.Data4[7]);
865 //=======================================================================
866 //function : GetCharArray
867 //purpose : Get C array of char, theLength is the number of elements;
868 // theArray must point to a
869 // space enough to place theLength elements
870 //=======================================================================
872 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetCharArray
873 (const BinObjMgt_PChar theArray,
874 const Standard_Integer theLength) const
877 if (noMoreData (theLength)) return *this;
878 getArray (theArray, theLength);
882 //=======================================================================
883 //function : GetByteArray
884 //purpose : Get C array of unsigned chars, theLength is the number of elements;
885 // theArray must point to a
886 // space enough to place theLength elements
887 //=======================================================================
889 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetByteArray
890 (const BinObjMgt_PByte theArray,
891 const Standard_Integer theLength) const
894 if (noMoreData (theLength)) return *this;
895 getArray (theArray, theLength);
899 //=======================================================================
900 //function : GetExtCharArray
901 //purpose : Get C array of ExtCharacter, theLength is the number of elements;
902 // theArray must point to a
903 // space enough to place theLength elements
904 //=======================================================================
906 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetExtCharArray
907 (const BinObjMgt_PExtChar theArray,
908 const Standard_Integer theLength) const
910 alignOffset (BP_EXTCHARSIZE, Standard_True);
911 Standard_Integer aSize = theLength * BP_EXTCHARSIZE;
912 if (noMoreData (aSize)) return *this;
913 getArray (theArray, aSize);
915 for (Standard_Integer i=0; i < theLength; i++)
916 theArray[i] = InverseExtChar (theArray[i]);
921 //=======================================================================
922 //function : GetIntArray
923 //purpose : Get C array of int, theLength is the number of elements;
924 // theArray must point to a
925 // space enough to place theLength elements
926 //=======================================================================
928 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetIntArray
929 (const BinObjMgt_PInteger theArray,
930 const Standard_Integer theLength) const
932 alignOffset (BP_INTSIZE, Standard_True);
933 Standard_Integer aSize = theLength * BP_INTSIZE;
934 if (noMoreData (aSize)) return *this;
935 getArray (theArray, aSize);
937 for (Standard_Integer i=0; i < theLength; i++)
938 theArray[i] = InverseInt (theArray[i]);
943 //=======================================================================
944 //function : GetRealArray
945 //purpose : Get C array of double, theLength is the number of elements;
946 // theArray must point to a
947 // space enough to place theLength elements
948 //=======================================================================
950 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetRealArray
951 (const BinObjMgt_PReal theArray,
952 const Standard_Integer theLength) const
954 alignOffset (BP_INTSIZE, Standard_True);
955 Standard_Integer aSize = theLength * BP_REALSIZE;
956 if (noMoreData (aSize)) return *this;
957 getArray (theArray, aSize);
959 for (Standard_Integer i=0; i < theLength; i++)
960 theArray[i] = InverseReal (theArray[i]);
965 //=======================================================================
966 //function : GetShortRealArray
967 //purpose : Get C array of float, theLength is the number of elements;
968 // theArray must point to a
969 // space enough to place theLength elements
970 //=======================================================================
972 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetShortRealArray
973 (const BinObjMgt_PShortReal theArray,
974 const Standard_Integer theLength) const
976 alignOffset (BP_INTSIZE, Standard_True);
977 Standard_Integer aSize = theLength * BP_SHORTREALSIZE;
978 if (noMoreData (aSize)) return *this;
979 getArray (theArray, aSize);
981 for (Standard_Integer i=0; i < theLength; i++)
982 theArray[i] = InverseShortReal (theArray[i]);
987 //=======================================================================
988 //function : putArray
989 //purpose : Puts theSize bytes from theArray
990 //=======================================================================
992 void BinObjMgt_Persistent::putArray
993 (const Standard_Address theArray,
994 const Standard_Integer theSize)
996 char *aPtr = (char*) theArray;
997 Standard_Integer aLen = theSize;
999 if (myOffset >= BP_PIECESIZE) {
1003 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - myOffset);
1004 char *aData = (char*) myData(myIndex) + myOffset;
1005 memcpy (aData, aPtr, aLenInPiece);
1006 aLen -= aLenInPiece;
1007 aPtr += aLenInPiece;
1008 myOffset += aLenInPiece;
1012 //=======================================================================
1013 //function : getArray
1014 //purpose : Gets theLength bytes into theArray
1015 //=======================================================================
1017 void BinObjMgt_Persistent::getArray
1018 (const Standard_Address theArray,
1019 const Standard_Integer theSize) const
1021 char *aPtr = (char*) theArray;
1022 Standard_Integer aLen = theSize;
1023 BinObjMgt_Persistent *me = (BinObjMgt_Persistent*) this;
1025 if (myOffset >= BP_PIECESIZE) {
1029 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - myOffset);
1030 char *aData = (char*) myData(myIndex) + myOffset;
1031 memcpy (aPtr, aData, aLenInPiece);
1032 aLen -= aLenInPiece;
1033 aPtr += aLenInPiece;
1034 me->myOffset += aLenInPiece;
1038 //=======================================================================
1039 //function : inverseExtCharData
1040 //purpose : Inverses bytes in the data addressed by the given values
1041 //=======================================================================
1043 void BinObjMgt_Persistent::inverseExtCharData
1044 (const Standard_Integer theIndex,
1045 const Standard_Integer theOffset,
1046 const Standard_Integer theSize)
1048 Standard_Integer anIndex = theIndex;
1049 Standard_Integer anOffset = theOffset;
1050 Standard_Integer aLen = theSize;
1052 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1053 Standard_ExtCharacter *aData = (Standard_ExtCharacter*)
1054 ( (char*) myData(anIndex) + anOffset);
1055 for (Standard_Integer i=0; i < aLenInPiece / BP_EXTCHARSIZE; i++)
1056 aData[i] = InverseExtChar (aData[i]);
1057 aLen -= aLenInPiece;
1058 anOffset += aLenInPiece;
1059 if (anOffset >= BP_PIECESIZE) {
1066 //=======================================================================
1067 //function : inverseIntData
1068 //purpose : Inverses bytes in the data addressed by the given values
1069 //=======================================================================
1071 void BinObjMgt_Persistent::inverseIntData
1072 (const Standard_Integer theIndex,
1073 const Standard_Integer theOffset,
1074 const Standard_Integer theSize)
1076 Standard_Integer anIndex = theIndex;
1077 Standard_Integer anOffset = theOffset;
1078 Standard_Integer aLen = theSize;
1080 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1081 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(anIndex) + anOffset);
1082 for (Standard_Integer i=0; i < aLenInPiece / BP_INTSIZE; i++)
1083 aData[i] = InverseInt (aData[i]);
1084 aLen -= aLenInPiece;
1085 anOffset += aLenInPiece;
1086 if (anOffset >= BP_PIECESIZE) {
1093 //=======================================================================
1094 //function : inverseRealData
1095 //purpose : Inverses bytes in the data addressed by the given values
1096 //=======================================================================
1098 void BinObjMgt_Persistent::inverseRealData
1099 (const Standard_Integer theIndex,
1100 const Standard_Integer theOffset,
1101 const Standard_Integer theSize)
1103 Standard_Integer anIndex = theIndex;
1104 Standard_Integer anOffset = theOffset;
1105 Standard_Integer aLen = theSize;
1108 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1109 Standard_Real *aData = (Standard_Real*) ((char*)myData(anIndex) + anOffset);
1111 Standard_Integer aTmp;
1112 aTmp = InverseInt (*(Standard_Integer*)aPrevPtr);
1113 *(Standard_Integer*)aPrevPtr = InverseInt (*(Standard_Integer*)aData);
1114 *(Standard_Integer*)aData = aTmp;
1115 ((Standard_Integer*&)aData)++;
1118 for (Standard_Integer i=0; i < aLenInPiece / BP_REALSIZE; i++)
1119 aData[i] = InverseReal (aData[i]);
1120 if (aLenInPiece % BP_REALSIZE)
1121 aPrevPtr = &aData[aLenInPiece / BP_REALSIZE];
1122 aLen -= aLenInPiece;
1123 anOffset += aLenInPiece;
1124 if (anOffset >= BP_PIECESIZE) {
1131 //=======================================================================
1132 //function : inverseShortRealData
1133 //purpose : Inverses bytes in the data addressed by the given values
1134 //=======================================================================
1136 void BinObjMgt_Persistent::inverseShortRealData
1137 (const Standard_Integer theIndex,
1138 const Standard_Integer theOffset,
1139 const Standard_Integer theSize)
1141 Standard_Integer anIndex = theIndex;
1142 Standard_Integer anOffset = theOffset;
1143 Standard_Integer aLen = theSize;
1145 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1146 Standard_ShortReal *aData =
1147 (Standard_ShortReal *) ((char *)myData(anIndex) + anOffset);
1148 for (Standard_Integer i=0; i < aLenInPiece / BP_INTSIZE; i++)
1149 aData[i] = InverseShortReal (aData[i]);
1150 aLen -= aLenInPiece;
1151 anOffset += aLenInPiece;
1152 if (anOffset >= BP_PIECESIZE) {