1 // File: BinObjMgt_Persistent.cxx
2 // Created: 30.10.02 10:14:33
3 // Author: Michael SAZONOV
4 // Copyright: Open CASCADE 2002
6 #include <BinObjMgt_Persistent.ixx>
7 #include <TColStd_ListOfInteger.hxx>
8 #include <TDF_Tool.hxx>
9 #include <TColStd_ListIteratorOfListOfInteger.hxx>
10 #include <FSD_FileHeader.hxx>
12 #define BP_INTSIZE ((Standard_Integer)sizeof(Standard_Integer))
13 #define BP_EXTCHARSIZE ((Standard_Integer)sizeof(Standard_ExtCharacter))
14 #define BP_REALSIZE ((Standard_Integer)sizeof(Standard_Real))
15 #define BP_SHORTREALSIZE ((Standard_Integer)sizeof(Standard_ShortReal))
16 #define BP_UUIDSIZE ((Standard_Integer)sizeof(BinObjMgt_UUID))
18 // We define a GUID structure that is different from Standard_UUID because
19 // the latter contains a 'unsigned long' member that has variables size
20 // (4 or 8 bits) thus making the persistent files non-portable.
21 // This structure below ensures the portability.
23 unsigned int Data1 ; // 4-bytes long on all OS
24 unsigned short Data2 ; // 2-bytes long on all OS
25 unsigned short Data3 ; // 2-bytes long on all OS
26 unsigned char Data4[8] ; // 8-bytes long on all OS
29 //=======================================================================
30 //function : BinObjMgt_Persistent
31 //purpose : Empty constructor
32 //=======================================================================
34 BinObjMgt_Persistent::BinObjMgt_Persistent ()
36 myOffset(BP_HEADSIZE),
38 myIsError (Standard_False)
43 //=======================================================================
45 //purpose : Initializes me to reuse again
46 //=======================================================================
48 void BinObjMgt_Persistent::Init ()
50 if (myData.IsEmpty()) {
51 Standard_Address aPiece = Standard::Allocate (BP_PIECESIZE);
52 myData.Append (aPiece);
54 Standard_Integer *aData = (Standard_Integer*) myData(1);
55 aData[0] = 0; // Type Id
56 aData[1] = 0; // Object Id
57 aData[2] = 0; // Data length
59 myOffset = BP_HEADSIZE;
61 myIsError = Standard_False;
64 //=======================================================================
66 //purpose : Stores <me> to the stream.
67 // inline Standard_OStream& operator<< (Standard_OStream&,
68 // const BinObjMgt_Persistent&) is also available
69 //=======================================================================
71 Standard_OStream& BinObjMgt_Persistent::Write (Standard_OStream& theOS)
73 Standard_Integer nbWritten = 0;
74 Standard_Integer *aData = (Standard_Integer*) myData(1);
76 aData[2] = mySize - BP_HEADSIZE;
78 aData[0] = InverseInt (aData[0]);
79 aData[1] = InverseInt (aData[1]);
80 aData[2] = InverseInt (aData[2]);
82 for (Standard_Integer i=1;
83 theOS && nbWritten < mySize && i <= myData.Length();
85 Standard_Integer nbToWrite = Min (mySize - nbWritten, BP_PIECESIZE);
86 theOS.write ((char*)myData(i), nbToWrite);
87 nbWritten += nbToWrite;
90 myOffset = BP_HEADSIZE;
92 myIsError = Standard_False;
96 //=======================================================================
98 //purpose : Retrieves <me> from the stream.
99 // inline Standard_IStream& operator>> (Standard_IStream&,
100 // BinObjMgt_Persistent&) is also available
101 //=======================================================================
103 Standard_IStream& BinObjMgt_Persistent::Read (Standard_IStream& theIS)
106 myOffset = BP_HEADSIZE;
107 mySize = BP_HEADSIZE;
108 myIsError = Standard_False;
110 Standard_Integer *aData = (Standard_Integer*) myData(1);
111 aData[0] = 0; // Type Id
112 aData[1] = 0; // Object Id
113 aData[2] = 0; // Data length
116 theIS.read ((char*) &aData[0], BP_INTSIZE);
118 aData[0] = InverseInt (aData[0]);
120 if (theIS && aData[0] > 0) {
121 // read Id and Length
122 theIS.read ((char*)&aData[1], 2 * BP_INTSIZE);
124 aData[1] = InverseInt (aData[1]);
125 aData[2] = InverseInt (aData[2]);
127 if (theIS && aData[1] > 0 && aData[2] > 0) {
129 // read remaining data
130 Standard_Integer nbRead = BP_HEADSIZE;
131 for (Standard_Integer i=1;
132 theIS && nbRead < mySize;
134 if (i > myData.Length()) {
135 // grow myData dynamically
136 Standard_Address aPiece = Standard::Allocate (BP_PIECESIZE);
137 myData.Append (aPiece);
139 Standard_Integer nbToRead = Min (mySize - nbRead, BP_PIECESIZE);
140 char *ptr = (char*)myData(i);
142 // 1st piece: reduce the number of bytes by header size
144 if (nbToRead == BP_PIECESIZE) nbToRead -= BP_HEADSIZE;
146 theIS.read (ptr, nbToRead);
156 //=======================================================================
158 //purpose : Frees the allocated memory
159 //=======================================================================
161 void BinObjMgt_Persistent::Destroy ()
163 for (Standard_Integer i=1; i <= myData.Length(); i++) {
164 Standard::Free (myData(i));
167 myIndex = myOffset = mySize = 0;
170 //=======================================================================
171 //function : incrementData
172 //purpose : Allocates theNbPieces more pieces
173 //=======================================================================
175 void BinObjMgt_Persistent::incrementData
176 (const Standard_Integer theNbPieces)
178 for (Standard_Integer i=1; i <= theNbPieces; i++) {
179 Standard_Address aPiece = Standard::Allocate (BP_PIECESIZE);
180 myData.Append (aPiece);
184 //=======================================================================
185 //function : PutCharacter
187 //=======================================================================
189 BinObjMgt_Persistent& BinObjMgt_Persistent::PutCharacter
190 (const Standard_Character theValue)
194 Standard_Character *aData = (Standard_Character*) myData(myIndex) + myOffset;
200 //=======================================================================
203 //=======================================================================
205 BinObjMgt_Persistent& BinObjMgt_Persistent::PutByte
206 (const Standard_Byte theValue)
210 Standard_Byte *aData = (Standard_Byte*) myData(myIndex) + myOffset;
216 //=======================================================================
217 //function : PutExtCharacter
219 //=======================================================================
221 BinObjMgt_Persistent& BinObjMgt_Persistent::PutExtCharacter
222 (const Standard_ExtCharacter theValue)
224 alignOffset (BP_EXTCHARSIZE, Standard_True);
225 prepareForPut (BP_EXTCHARSIZE);
226 Standard_ExtCharacter *aData =
227 (Standard_ExtCharacter*) ((char*)myData(myIndex) + myOffset);
229 *aData = InverseExtChar (theValue);
233 myOffset += BP_EXTCHARSIZE;
237 //=======================================================================
238 //function : PutInteger
240 //=======================================================================
242 BinObjMgt_Persistent& BinObjMgt_Persistent::PutInteger
243 (const Standard_Integer theValue)
245 alignOffset (BP_INTSIZE, Standard_True);
246 prepareForPut (BP_INTSIZE);
247 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
249 *aData = InverseInt (theValue);
253 myOffset += BP_INTSIZE;
257 //=======================================================================
260 //=======================================================================
262 BinObjMgt_Persistent& BinObjMgt_Persistent::PutReal
263 (const Standard_Real theValue)
265 alignOffset (BP_INTSIZE, Standard_True);
266 Standard_Integer nbPieces = prepareForPut (BP_REALSIZE);
268 // the value intersects a piece boundary => go a long way
270 Standard_Integer aStartIndex = myIndex;
271 Standard_Integer aStartOffset = myOffset;
273 putArray ((void*) &theValue, BP_REALSIZE);
275 inverseRealData (aStartIndex, aStartOffset, BP_REALSIZE);
279 // the value fits in the current piece => put it quickly
280 Standard_Real *aData = (Standard_Real*) ((char*)myData(myIndex) + myOffset);
282 *aData = InverseReal (theValue);
286 myOffset += BP_REALSIZE;
291 //=======================================================================
292 //function : PutShortReal
294 //=======================================================================
296 BinObjMgt_Persistent& BinObjMgt_Persistent::PutShortReal
297 (const Standard_ShortReal theValue)
299 alignOffset (BP_INTSIZE, Standard_True);
300 prepareForPut (BP_SHORTREALSIZE);
301 Standard_ShortReal *aData = (Standard_ShortReal*) ((char*)myData(myIndex) + myOffset);
303 *aData = InverseShortReal (theValue);
307 myOffset += BP_SHORTREALSIZE;
311 //=======================================================================
312 //function : PutCString
313 //purpose : Offset in output buffer is not aligned
314 //=======================================================================
316 BinObjMgt_Persistent& BinObjMgt_Persistent::PutCString
317 (const Standard_CString theValue)
320 Standard_Integer aSize = strlen (theValue) + 1;
321 prepareForPut (aSize);
322 putArray ((void* const)theValue, aSize);
326 //=======================================================================
327 //function : PutAsciiString
328 //purpose : Offset in output buffer is word-aligned
329 //=======================================================================
331 BinObjMgt_Persistent& BinObjMgt_Persistent::PutAsciiString
332 (const TCollection_AsciiString& theValue)
334 alignOffset (BP_INTSIZE, Standard_True);
335 Standard_Integer aSize = theValue.Length() + 1;
336 prepareForPut (aSize);
337 putArray ((void* const)theValue.ToCString(), aSize);
341 //=======================================================================
342 //function : PutExtendedString
343 //purpose : Offset in output buffer is word-aligned
344 //=======================================================================
346 BinObjMgt_Persistent& BinObjMgt_Persistent::PutExtendedString
347 (const TCollection_ExtendedString& theValue)
349 alignOffset (BP_INTSIZE, Standard_True);
350 Standard_Integer aSize = (theValue.Length() + 1) * BP_EXTCHARSIZE;
351 prepareForPut (aSize);
353 Standard_Integer aStartIndex = myIndex;
354 Standard_Integer aStartOffset = myOffset;
356 putArray ((void* const)theValue.ToExtString(), aSize);
358 inverseExtCharData (aStartIndex, aStartOffset, aSize - BP_EXTCHARSIZE);
363 //=======================================================================
364 //function : PutLabel
366 //=======================================================================
368 BinObjMgt_Persistent& BinObjMgt_Persistent::PutLabel
369 (const TDF_Label& theValue)
371 alignOffset (BP_INTSIZE, Standard_True);
372 Standard_Integer aLen = (theValue.IsNull() ? 0 : theValue.Depth()+1);
373 prepareForPut ((aLen + 1) * BP_INTSIZE);
374 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
377 *aData++ = InverseInt (aLen);
381 myOffset += BP_INTSIZE;
382 if (!theValue.IsNull()) {
383 TColStd_ListOfInteger aTagList;
384 TDF_Tool::TagList (theValue, aTagList);
385 TColStd_ListIteratorOfListOfInteger itTag(aTagList);
386 for (; itTag.More(); itTag.Next()) {
387 if (myOffset >= BP_PIECESIZE) {
390 aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
393 *aData++ = InverseInt (itTag.Value());
395 *aData++ = itTag.Value();
397 myOffset += BP_INTSIZE;
403 //=======================================================================
406 //=======================================================================
408 BinObjMgt_Persistent& BinObjMgt_Persistent::PutGUID
409 (const Standard_GUID& theValue)
411 alignOffset (BP_INTSIZE, Standard_True);
412 prepareForPut (BP_UUIDSIZE);
413 const Standard_UUID aStandardUUID = theValue.ToUUID();
414 BinObjMgt_UUID anUUID;
415 anUUID.Data1 = (unsigned int) aStandardUUID.Data1;
416 anUUID.Data2 = (unsigned short) aStandardUUID.Data2;
417 anUUID.Data3 = (unsigned short) aStandardUUID.Data3;
418 anUUID.Data4[0] = aStandardUUID.Data4[0];
419 anUUID.Data4[1] = aStandardUUID.Data4[1];
420 anUUID.Data4[2] = aStandardUUID.Data4[2];
421 anUUID.Data4[3] = aStandardUUID.Data4[3];
422 anUUID.Data4[4] = aStandardUUID.Data4[4];
423 anUUID.Data4[5] = aStandardUUID.Data4[5];
424 anUUID.Data4[6] = aStandardUUID.Data4[6];
425 anUUID.Data4[7] = aStandardUUID.Data4[7];
427 anUUID.Data1 = (unsigned int) InverseInt (anUUID.Data1);
428 anUUID.Data2 = (unsigned short) InverseExtChar (anUUID.Data2);
429 anUUID.Data3 = (unsigned short) InverseExtChar (anUUID.Data3);
431 putArray (&anUUID, BP_UUIDSIZE);
435 //=======================================================================
436 //function : PutCharArray
437 //purpose : Put C array of char, theLength is the number of elements
438 //=======================================================================
440 BinObjMgt_Persistent& BinObjMgt_Persistent::PutCharArray
441 (const BinObjMgt_PChar theArray,
442 const Standard_Integer theLength)
445 prepareForPut (theLength);
446 putArray (theArray, theLength);
450 //=======================================================================
451 //function : PutByteArray
452 //purpose : Put C array of byte, theLength is the number of elements
453 //=======================================================================
455 BinObjMgt_Persistent& BinObjMgt_Persistent::PutByteArray
456 (const BinObjMgt_PByte theArray,
457 const Standard_Integer theLength)
460 prepareForPut (theLength);
461 putArray (theArray, theLength);
465 //=======================================================================
466 //function : PutExtCharArray
467 //purpose : Put C array of ExtCharacter, theLength is the number of elements
468 //=======================================================================
470 BinObjMgt_Persistent& BinObjMgt_Persistent::PutExtCharArray
471 (const BinObjMgt_PExtChar theArray,
472 const Standard_Integer theLength)
474 alignOffset (BP_EXTCHARSIZE, Standard_True);
475 Standard_Integer aSize = theLength * BP_EXTCHARSIZE;
476 prepareForPut (aSize);
478 Standard_Integer aStartIndex = myIndex;
479 Standard_Integer aStartOffset = myOffset;
481 putArray (theArray, aSize);
483 inverseExtCharData (aStartIndex, aStartOffset, aSize);
488 //=======================================================================
489 //function : PutIntArray
490 //purpose : Put C array of int, theLength is the number of elements
491 //=======================================================================
493 BinObjMgt_Persistent& BinObjMgt_Persistent::PutIntArray
494 (const BinObjMgt_PInteger theArray,
495 const Standard_Integer theLength)
497 alignOffset (BP_INTSIZE, Standard_True);
498 Standard_Integer aSize = theLength * BP_INTSIZE;
499 prepareForPut (aSize);
501 Standard_Integer aStartIndex = myIndex;
502 Standard_Integer aStartOffset = myOffset;
504 putArray (theArray, aSize);
506 inverseIntData (aStartIndex, aStartOffset, aSize);
511 //=======================================================================
512 //function : PutRealArray
513 //purpose : Put C array of double, theLength is the number of elements
514 //=======================================================================
516 BinObjMgt_Persistent& BinObjMgt_Persistent::PutRealArray
517 (const BinObjMgt_PReal theArray,
518 const Standard_Integer theLength)
520 alignOffset (BP_INTSIZE, Standard_True);
521 Standard_Integer aSize = theLength * BP_REALSIZE;
522 prepareForPut (aSize);
524 Standard_Integer aStartIndex = myIndex;
525 Standard_Integer aStartOffset = myOffset;
527 putArray (theArray, aSize);
529 inverseRealData (aStartIndex, aStartOffset, aSize);
534 //=======================================================================
535 //function : PutShortRealArray
536 //purpose : Put C array of float, theLength is the number of elements
537 //=======================================================================
539 BinObjMgt_Persistent& BinObjMgt_Persistent::PutShortRealArray
540 (const BinObjMgt_PShortReal theArray,
541 const Standard_Integer theLength)
543 alignOffset (BP_INTSIZE, Standard_True);
544 Standard_Integer aSize = theLength * BP_SHORTREALSIZE;
545 prepareForPut (aSize);
547 Standard_Integer aStartIndex = myIndex;
548 Standard_Integer aStartOffset = myOffset;
550 putArray (theArray, aSize);
552 inverseShortRealData (aStartIndex, aStartOffset, aSize);
557 //=======================================================================
558 //function : GetCharacter
560 //=======================================================================
562 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetCharacter
563 (Standard_Character& theValue) const
566 if (noMoreData (1)) return *this;
567 Standard_Character *aData = (Standard_Character*) myData(myIndex) + myOffset;
569 ((BinObjMgt_Persistent*)this)->myOffset++;
573 //=======================================================================
576 //=======================================================================
578 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetByte
579 (Standard_Byte& theValue) const
582 if (noMoreData (1)) return *this;
583 Standard_Byte *aData = (Standard_Byte*) myData(myIndex) + myOffset;
585 ((BinObjMgt_Persistent*)this)->myOffset++;
589 //=======================================================================
590 //function : GetExtCharacter
592 //=======================================================================
594 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetExtCharacter
595 (Standard_ExtCharacter& theValue) const
597 alignOffset (BP_EXTCHARSIZE);
598 if (noMoreData (BP_EXTCHARSIZE)) return *this;
599 Standard_ExtCharacter *aData =
600 (Standard_ExtCharacter*) ((char*)myData(myIndex) + myOffset);
602 theValue = InverseExtChar (*aData);
606 ((BinObjMgt_Persistent*)this)->myOffset += BP_EXTCHARSIZE;
610 //=======================================================================
611 //function : GetInteger
613 //=======================================================================
615 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetInteger
616 (Standard_Integer& theValue) const
618 alignOffset (BP_INTSIZE);
619 if (noMoreData (BP_INTSIZE)) return *this;
620 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
622 theValue = InverseInt (*aData);
626 ((BinObjMgt_Persistent*)this)->myOffset += BP_INTSIZE;
630 //=======================================================================
633 //=======================================================================
635 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetReal
636 (Standard_Real& theValue) const
638 alignOffset (BP_INTSIZE);
639 if (noMoreData (BP_REALSIZE)) return *this;
640 Standard_Integer nbPieces = (myOffset + BP_REALSIZE - 1) / BP_PIECESIZE;
642 // the value intersects a piece boundary => go a long way
643 getArray ((void*) &theValue, BP_REALSIZE);
646 // the value fits in the current piece => get it quickly
647 Standard_Real *aData = (Standard_Real*) ((char*)myData(myIndex) + myOffset);
649 ((BinObjMgt_Persistent*)this)->myOffset += BP_REALSIZE;
652 theValue = InverseReal (theValue);
657 //=======================================================================
658 //function : GetShortReal
660 //=======================================================================
662 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetShortReal
663 (Standard_ShortReal& theValue) const
665 alignOffset (BP_INTSIZE);
666 if (noMoreData (BP_SHORTREALSIZE)) return *this;
667 Standard_ShortReal *aData = (Standard_ShortReal*) ((char*)myData(myIndex) + myOffset);
669 theValue = InverseShortReal (*aData);
673 ((BinObjMgt_Persistent*)this)->myOffset += BP_SHORTREALSIZE;
677 //=======================================================================
678 //function : GetAsciiString
680 //=======================================================================
682 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetAsciiString
683 (TCollection_AsciiString& theValue) const
685 alignOffset (BP_INTSIZE);
686 Standard_Integer aStartIndex = myIndex;
687 Standard_Integer aStartOffset = myOffset;
688 BinObjMgt_Persistent* me = (BinObjMgt_Persistent*)this;
689 char *aData = (char*) myData(myIndex) + myOffset;
691 // count the string length
692 while (!noMoreData (1) && *aData++) {
694 if (myOffset >= BP_PIECESIZE) {
696 aData = (char*) myData(++me->myIndex);
700 me->myIndex = aStartIndex;
701 me->myOffset = aStartOffset;
704 me->myOffset++; // count the end null char
706 if (myIndex == aStartIndex) {
707 // all string is in one piece => simply copy
708 theValue = aData - myOffset + aStartOffset;
711 // work through buffer string
712 Standard_Integer aSize = (myIndex - aStartIndex) * BP_PIECESIZE +
713 myOffset - aStartOffset;
714 Standard_Address aString = Standard::Allocate (aSize);
715 me->myIndex = aStartIndex;
716 me->myOffset = aStartOffset;
717 getArray (aString, aSize);
718 theValue = (char*) aString;
719 Standard::Free (aString);
725 //=======================================================================
726 //function : GetExtendedString
728 //=======================================================================
730 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetExtendedString
731 (TCollection_ExtendedString& theValue) const
733 alignOffset (BP_INTSIZE);
734 Standard_Integer aStartIndex = myIndex;
735 Standard_Integer aStartOffset = myOffset;
736 BinObjMgt_Persistent* me = (BinObjMgt_Persistent*)this;
737 Standard_ExtCharacter *aData =
738 (Standard_ExtCharacter*) ((char*)myData(myIndex) + myOffset);
740 // count the string length
741 while (!noMoreData (1) && *aData++) {
742 me->myOffset += BP_EXTCHARSIZE;
743 if (myOffset >= BP_PIECESIZE) {
745 aData = (Standard_ExtCharacter*) myData(++me->myIndex);
749 me->myIndex = aStartIndex;
750 me->myOffset = aStartOffset;
753 me->myOffset += BP_EXTCHARSIZE; // count the end null char
755 if (myIndex == aStartIndex) {
756 // all string is in one piece => simply copy
757 theValue = aData - (myOffset - aStartOffset) / BP_EXTCHARSIZE;
760 // work through buffer string
761 Standard_Integer aSize = (myIndex - aStartIndex) * BP_PIECESIZE +
762 (myOffset - aStartOffset);
763 Standard_Address aString = Standard::Allocate (aSize);
764 me->myIndex = aStartIndex;
765 me->myOffset = aStartOffset;
766 getArray (aString, aSize);
767 theValue = (Standard_ExtCharacter*) aString;
768 Standard::Free (aString);
771 Standard_PExtCharacter aString = (Standard_PExtCharacter)theValue.ToExtString();
772 for (Standard_Integer i=0; i < theValue.Length(); i++)
773 aString[i] = InverseExtChar (aString[i]);
779 //=======================================================================
780 //function : GetLabel
782 //=======================================================================
784 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetLabel
785 (const Handle(TDF_Data)& theDS,
786 TDF_Label& theValue) const
789 alignOffset (BP_INTSIZE);
790 if (noMoreData (BP_INTSIZE)) return *this;
791 BinObjMgt_Persistent* me = (BinObjMgt_Persistent*)this;
792 // retrieve nb of tags
793 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
794 Standard_Integer aLen = *aData++;
796 aLen = InverseInt (aLen);
798 me->myOffset += BP_INTSIZE;
799 if (noMoreData (aLen * BP_INTSIZE)) return *this;
803 TColStd_ListOfInteger aTagList;
805 if (myOffset >= BP_PIECESIZE) {
808 aData = (Standard_Integer*) ((char*)myData(myIndex) + myOffset);
811 aTagList.Append (InverseInt (*aData++));
813 aTagList.Append (*aData++);
815 me->myOffset += BP_INTSIZE;
818 // find label by entry
819 TDF_Tool::Label (theDS, aTagList, theValue, Standard_True);
824 //=======================================================================
827 //=======================================================================
829 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetGUID
830 (Standard_GUID& theValue) const
832 alignOffset (BP_INTSIZE);
833 if (noMoreData (BP_UUIDSIZE))
835 BinObjMgt_UUID anUUID;
836 getArray (&anUUID, BP_UUIDSIZE);
838 anUUID.Data1 = (unsigned int) InverseInt (anUUID.Data1);
839 anUUID.Data2 = (unsigned short) InverseExtChar (anUUID.Data2);
840 anUUID.Data3 = (unsigned short) InverseExtChar (anUUID.Data3);
842 theValue = Standard_GUID (anUUID.Data1, anUUID.Data2, anUUID.Data3,
843 ((anUUID.Data4[0] << 8) | (anUUID.Data4[1])),
844 anUUID.Data4[2], anUUID.Data4[3], anUUID.Data4[4],
845 anUUID.Data4[5], anUUID.Data4[6], anUUID.Data4[7]);
849 //=======================================================================
850 //function : GetCharArray
851 //purpose : Get C array of char, theLength is the number of elements;
852 // theArray must point to a
853 // space enough to place theLength elements
854 //=======================================================================
856 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetCharArray
857 (const BinObjMgt_PChar theArray,
858 const Standard_Integer theLength) const
861 if (noMoreData (theLength)) return *this;
862 getArray (theArray, theLength);
866 //=======================================================================
867 //function : GetByteArray
868 //purpose : Get C array of unsigned chars, theLength is the number of elements;
869 // theArray must point to a
870 // space enough to place theLength elements
871 //=======================================================================
873 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetByteArray
874 (const BinObjMgt_PByte theArray,
875 const Standard_Integer theLength) const
878 if (noMoreData (theLength)) return *this;
879 getArray (theArray, theLength);
883 //=======================================================================
884 //function : GetExtCharArray
885 //purpose : Get C array of ExtCharacter, theLength is the number of elements;
886 // theArray must point to a
887 // space enough to place theLength elements
888 //=======================================================================
890 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetExtCharArray
891 (const BinObjMgt_PExtChar theArray,
892 const Standard_Integer theLength) const
894 alignOffset (BP_EXTCHARSIZE, Standard_True);
895 Standard_Integer aSize = theLength * BP_EXTCHARSIZE;
896 if (noMoreData (aSize)) return *this;
897 getArray (theArray, aSize);
899 for (Standard_Integer i=0; i < theLength; i++)
900 theArray[i] = InverseExtChar (theArray[i]);
905 //=======================================================================
906 //function : GetIntArray
907 //purpose : Get C array of int, theLength is the number of elements;
908 // theArray must point to a
909 // space enough to place theLength elements
910 //=======================================================================
912 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetIntArray
913 (const BinObjMgt_PInteger theArray,
914 const Standard_Integer theLength) const
916 alignOffset (BP_INTSIZE, Standard_True);
917 Standard_Integer aSize = theLength * BP_INTSIZE;
918 if (noMoreData (aSize)) return *this;
919 getArray (theArray, aSize);
921 for (Standard_Integer i=0; i < theLength; i++)
922 theArray[i] = InverseInt (theArray[i]);
927 //=======================================================================
928 //function : GetRealArray
929 //purpose : Get C array of double, theLength is the number of elements;
930 // theArray must point to a
931 // space enough to place theLength elements
932 //=======================================================================
934 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetRealArray
935 (const BinObjMgt_PReal theArray,
936 const Standard_Integer theLength) const
938 alignOffset (BP_INTSIZE, Standard_True);
939 Standard_Integer aSize = theLength * BP_REALSIZE;
940 if (noMoreData (aSize)) return *this;
941 getArray (theArray, aSize);
943 for (Standard_Integer i=0; i < theLength; i++)
944 theArray[i] = InverseReal (theArray[i]);
949 //=======================================================================
950 //function : GetShortRealArray
951 //purpose : Get C array of float, theLength is the number of elements;
952 // theArray must point to a
953 // space enough to place theLength elements
954 //=======================================================================
956 const BinObjMgt_Persistent& BinObjMgt_Persistent::GetShortRealArray
957 (const BinObjMgt_PShortReal theArray,
958 const Standard_Integer theLength) const
960 alignOffset (BP_INTSIZE, Standard_True);
961 Standard_Integer aSize = theLength * BP_SHORTREALSIZE;
962 if (noMoreData (aSize)) return *this;
963 getArray (theArray, aSize);
965 for (Standard_Integer i=0; i < theLength; i++)
966 theArray[i] = InverseShortReal (theArray[i]);
971 //=======================================================================
972 //function : putArray
973 //purpose : Puts theSize bytes from theArray
974 //=======================================================================
976 void BinObjMgt_Persistent::putArray
977 (const Standard_Address theArray,
978 const Standard_Integer theSize)
980 char *aPtr = (char*) theArray;
981 Standard_Integer aLen = theSize;
983 if (myOffset >= BP_PIECESIZE) {
987 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - myOffset);
988 char *aData = (char*) myData(myIndex) + myOffset;
989 memcpy (aData, aPtr, aLenInPiece);
992 myOffset += aLenInPiece;
996 //=======================================================================
997 //function : getArray
998 //purpose : Gets theLength bytes into theArray
999 //=======================================================================
1001 void BinObjMgt_Persistent::getArray
1002 (const Standard_Address theArray,
1003 const Standard_Integer theSize) const
1005 char *aPtr = (char*) theArray;
1006 Standard_Integer aLen = theSize;
1007 BinObjMgt_Persistent *me = (BinObjMgt_Persistent*) this;
1009 if (myOffset >= BP_PIECESIZE) {
1013 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - myOffset);
1014 char *aData = (char*) myData(myIndex) + myOffset;
1015 memcpy (aPtr, aData, aLenInPiece);
1016 aLen -= aLenInPiece;
1017 aPtr += aLenInPiece;
1018 me->myOffset += aLenInPiece;
1022 //=======================================================================
1023 //function : inverseExtCharData
1024 //purpose : Inverses bytes in the data addressed by the given values
1025 //=======================================================================
1027 void BinObjMgt_Persistent::inverseExtCharData
1028 (const Standard_Integer theIndex,
1029 const Standard_Integer theOffset,
1030 const Standard_Integer theSize)
1032 Standard_Integer anIndex = theIndex;
1033 Standard_Integer anOffset = theOffset;
1034 Standard_Integer aLen = theSize;
1036 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1037 Standard_ExtCharacter *aData = (Standard_ExtCharacter*)
1038 ( (char*) myData(anIndex) + anOffset);
1039 for (Standard_Integer i=0; i < aLenInPiece / BP_EXTCHARSIZE; i++)
1040 aData[i] = InverseExtChar (aData[i]);
1041 aLen -= aLenInPiece;
1042 anOffset += aLenInPiece;
1043 if (anOffset >= BP_PIECESIZE) {
1050 //=======================================================================
1051 //function : inverseIntData
1052 //purpose : Inverses bytes in the data addressed by the given values
1053 //=======================================================================
1055 void BinObjMgt_Persistent::inverseIntData
1056 (const Standard_Integer theIndex,
1057 const Standard_Integer theOffset,
1058 const Standard_Integer theSize)
1060 Standard_Integer anIndex = theIndex;
1061 Standard_Integer anOffset = theOffset;
1062 Standard_Integer aLen = theSize;
1064 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1065 Standard_Integer *aData = (Standard_Integer*) ((char*)myData(anIndex) + anOffset);
1066 for (Standard_Integer i=0; i < aLenInPiece / BP_INTSIZE; i++)
1067 aData[i] = InverseInt (aData[i]);
1068 aLen -= aLenInPiece;
1069 anOffset += aLenInPiece;
1070 if (anOffset >= BP_PIECESIZE) {
1077 //=======================================================================
1078 //function : inverseRealData
1079 //purpose : Inverses bytes in the data addressed by the given values
1080 //=======================================================================
1082 void BinObjMgt_Persistent::inverseRealData
1083 (const Standard_Integer theIndex,
1084 const Standard_Integer theOffset,
1085 const Standard_Integer theSize)
1087 Standard_Integer anIndex = theIndex;
1088 Standard_Integer anOffset = theOffset;
1089 Standard_Integer aLen = theSize;
1092 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1093 Standard_Real *aData = (Standard_Real*) ((char*)myData(anIndex) + anOffset);
1095 Standard_Integer aTmp;
1096 aTmp = InverseInt (*(Standard_Integer*)aPrevPtr);
1097 *(Standard_Integer*)aPrevPtr = InverseInt (*(Standard_Integer*)aData);
1098 *(Standard_Integer*)aData = aTmp;
1099 ((Standard_Integer*&)aData)++;
1102 for (Standard_Integer i=0; i < aLenInPiece / BP_REALSIZE; i++)
1103 aData[i] = InverseReal (aData[i]);
1104 if (aLenInPiece % BP_REALSIZE)
1105 aPrevPtr = &aData[aLenInPiece / BP_REALSIZE];
1106 aLen -= aLenInPiece;
1107 anOffset += aLenInPiece;
1108 if (anOffset >= BP_PIECESIZE) {
1115 //=======================================================================
1116 //function : inverseShortRealData
1117 //purpose : Inverses bytes in the data addressed by the given values
1118 //=======================================================================
1120 void BinObjMgt_Persistent::inverseShortRealData
1121 (const Standard_Integer theIndex,
1122 const Standard_Integer theOffset,
1123 const Standard_Integer theSize)
1125 Standard_Integer anIndex = theIndex;
1126 Standard_Integer anOffset = theOffset;
1127 Standard_Integer aLen = theSize;
1129 Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
1130 Standard_ShortReal *aData =
1131 (Standard_ShortReal *) ((char *)myData(anIndex) + anOffset);
1132 for (Standard_Integer i=0; i < aLenInPiece / BP_INTSIZE; i++)
1133 aData[i] = InverseShortReal (aData[i]);
1134 aLen -= aLenInPiece;
1135 anOffset += aLenInPiece;
1136 if (anOffset >= BP_PIECESIZE) {