Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:00

0001 // Created on: 2002-10-30
0002 // Created by: Michael SAZONOV
0003 // Copyright (c) 2002-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BinObjMgt_Persistent_HeaderFile
0017 #define _BinObjMgt_Persistent_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 #include <Standard_Handle.hxx>
0022 
0023 #include <TColStd_SequenceOfAddress.hxx>
0024 #include <Standard_Integer.hxx>
0025 #include <Standard_ShortReal.hxx>
0026 #include <BinObjMgt_PChar.hxx>
0027 #include <BinObjMgt_PByte.hxx>
0028 #include <BinObjMgt_PExtChar.hxx>
0029 #include <BinObjMgt_PInteger.hxx>
0030 #include <BinObjMgt_PReal.hxx>
0031 #include <BinObjMgt_PShortReal.hxx>
0032 #include <BinObjMgt_Position.hxx>
0033 #include <Standard_OStream.hxx>
0034 #include <Standard_IStream.hxx>
0035 class TCollection_AsciiString;
0036 class TCollection_ExtendedString;
0037 class TDF_Label;
0038 class Standard_GUID;
0039 class TDF_Data;
0040 
0041 
0042 //! Binary persistent representation of an object.
0043 //! Really it is used as a buffer for read/write an object.
0044 //!
0045 //! It takes care of Little/Big endian by inversing bytes
0046 //! in objects of standard types (see FSD_FileHeader.hxx
0047 //! for the default value of DO_INVERSE).
0048 class BinObjMgt_Persistent 
0049 {
0050 public:
0051 
0052   DEFINE_STANDARD_ALLOC
0053 
0054   
0055   //! Empty constructor
0056   Standard_EXPORT BinObjMgt_Persistent();
0057   
0058   Standard_EXPORT BinObjMgt_Persistent& PutCharacter (const Standard_Character theValue);
0059 BinObjMgt_Persistent& operator << (const Standard_Character theValue)
0060 {
0061   return PutCharacter(theValue);
0062 }
0063   
0064   Standard_EXPORT BinObjMgt_Persistent& PutByte (const Standard_Byte theValue);
0065 BinObjMgt_Persistent& operator << (const Standard_Byte theValue)
0066 {
0067   return PutByte(theValue);
0068 }
0069   
0070   Standard_EXPORT BinObjMgt_Persistent& PutExtCharacter (const Standard_ExtCharacter theValue);
0071 BinObjMgt_Persistent& operator << (const Standard_ExtCharacter theValue)
0072 {
0073   return PutExtCharacter(theValue);
0074 }
0075   
0076   Standard_EXPORT BinObjMgt_Persistent& PutInteger (const Standard_Integer theValue);
0077 BinObjMgt_Persistent& operator << (const Standard_Integer theValue)
0078 {
0079   return PutInteger(theValue);
0080 }
0081   
0082     BinObjMgt_Persistent& PutBoolean (const Standard_Boolean theValue);
0083   BinObjMgt_Persistent& operator << (const Standard_Boolean theValue)
0084 {
0085   return PutBoolean(theValue);
0086 }
0087   
0088   Standard_EXPORT BinObjMgt_Persistent& PutReal (const Standard_Real theValue);
0089 BinObjMgt_Persistent& operator << (const Standard_Real theValue)
0090 {
0091   return PutReal(theValue);
0092 }
0093   
0094   Standard_EXPORT BinObjMgt_Persistent& PutShortReal (const Standard_ShortReal theValue);
0095 BinObjMgt_Persistent& operator << (const Standard_ShortReal theValue)
0096 {
0097   return PutShortReal(theValue);
0098 }
0099   
0100   //! Offset in output buffer is not aligned
0101   Standard_EXPORT BinObjMgt_Persistent& PutCString (const Standard_CString theValue);
0102 BinObjMgt_Persistent& operator << (const Standard_CString theValue)
0103 {
0104   return PutCString(theValue);
0105 }
0106   
0107   //! Offset in output buffer is word-aligned
0108   Standard_EXPORT BinObjMgt_Persistent& PutAsciiString (const TCollection_AsciiString& theValue);
0109 BinObjMgt_Persistent& operator << (const TCollection_AsciiString& theValue)
0110 {
0111   return PutAsciiString(theValue);
0112 }
0113   
0114   //! Offset in output buffer is word-aligned
0115   Standard_EXPORT BinObjMgt_Persistent& PutExtendedString (const TCollection_ExtendedString& theValue);
0116 BinObjMgt_Persistent& operator << (const TCollection_ExtendedString& theValue)
0117 {
0118   return PutExtendedString(theValue);
0119 }
0120   
0121   Standard_EXPORT BinObjMgt_Persistent& PutLabel (const TDF_Label& theValue);
0122 BinObjMgt_Persistent& operator << (const TDF_Label& theValue)
0123 {
0124   return PutLabel(theValue);
0125 }
0126   
0127   Standard_EXPORT BinObjMgt_Persistent& PutGUID (const Standard_GUID& theValue);
0128 BinObjMgt_Persistent& operator << (const Standard_GUID& theValue)
0129 {
0130   return PutGUID(theValue);
0131 }
0132   
0133   //! Put C array of char, theLength is the number of elements
0134   Standard_EXPORT BinObjMgt_Persistent& PutCharArray (const BinObjMgt_PChar theArray, const Standard_Integer theLength);
0135   
0136   //! Put C array of unsigned chars, theLength is the number of elements
0137   Standard_EXPORT BinObjMgt_Persistent& PutByteArray (const BinObjMgt_PByte theArray, const Standard_Integer theLength);
0138   
0139   //! Put C array of ExtCharacter, theLength is the number of elements
0140   Standard_EXPORT BinObjMgt_Persistent& PutExtCharArray (const BinObjMgt_PExtChar theArray, const Standard_Integer theLength);
0141   
0142   //! Put C array of int, theLength is the number of elements
0143   Standard_EXPORT BinObjMgt_Persistent& PutIntArray (const BinObjMgt_PInteger theArray, const Standard_Integer theLength);
0144   
0145   //! Put C array of double, theLength is the number of elements
0146   Standard_EXPORT BinObjMgt_Persistent& PutRealArray (const BinObjMgt_PReal theArray, const Standard_Integer theLength);
0147   
0148   //! Put C array of float, theLength is the number of elements
0149   Standard_EXPORT BinObjMgt_Persistent& PutShortRealArray (const BinObjMgt_PShortReal theArray, const Standard_Integer theLength);
0150   
0151   Standard_EXPORT const BinObjMgt_Persistent& GetCharacter (Standard_Character& theValue) const;
0152 const BinObjMgt_Persistent& operator >> (Standard_Character& theValue) const
0153 {
0154   return GetCharacter(theValue);
0155 }
0156   
0157   Standard_EXPORT const BinObjMgt_Persistent& GetByte (Standard_Byte& theValue) const;
0158 const BinObjMgt_Persistent& operator >> (Standard_Byte& theValue) const
0159 {
0160   return GetByte(theValue);
0161 }
0162   
0163   Standard_EXPORT const BinObjMgt_Persistent& GetExtCharacter (Standard_ExtCharacter& theValue) const;
0164 const BinObjMgt_Persistent& operator >> (Standard_ExtCharacter& theValue) const
0165 {
0166   return GetExtCharacter(theValue);
0167 }
0168   
0169   Standard_EXPORT const BinObjMgt_Persistent& GetInteger (Standard_Integer& theValue) const;
0170 const BinObjMgt_Persistent& operator >> (Standard_Integer& theValue) const
0171 {
0172   return GetInteger(theValue);
0173 }
0174   
0175     const BinObjMgt_Persistent& GetBoolean (Standard_Boolean& theValue) const;
0176   const BinObjMgt_Persistent& operator >> (Standard_Boolean& theValue) const
0177 {
0178   return GetBoolean(theValue);
0179 }
0180   
0181   Standard_EXPORT const BinObjMgt_Persistent& GetReal (Standard_Real& theValue) const;
0182 const BinObjMgt_Persistent& operator >> (Standard_Real& theValue) const
0183 {
0184   return GetReal(theValue);
0185 }
0186   
0187   Standard_EXPORT const BinObjMgt_Persistent& GetShortReal (Standard_ShortReal& theValue) const;
0188 const BinObjMgt_Persistent& operator >> (Standard_ShortReal& theValue) const
0189 {
0190   return GetShortReal(theValue);
0191 }
0192   
0193   Standard_EXPORT const BinObjMgt_Persistent& GetAsciiString (TCollection_AsciiString& theValue) const;
0194 const BinObjMgt_Persistent& operator >> (TCollection_AsciiString& theValue) const
0195 {
0196   return GetAsciiString(theValue);
0197 }
0198   
0199   Standard_EXPORT const BinObjMgt_Persistent& GetExtendedString (TCollection_ExtendedString& theValue) const;
0200 const BinObjMgt_Persistent& operator >> (TCollection_ExtendedString& theValue) const
0201 {
0202   return GetExtendedString(theValue);
0203 }
0204   
0205   Standard_EXPORT const BinObjMgt_Persistent& GetLabel (const Handle(TDF_Data)& theDS, TDF_Label& theValue) const;
0206   
0207   Standard_EXPORT const BinObjMgt_Persistent& GetGUID (Standard_GUID& theValue) const;
0208 const BinObjMgt_Persistent& operator >> (Standard_GUID& theValue) const
0209 {
0210   return GetGUID(theValue);
0211 }
0212   
0213   //! Get C array of char, theLength is the number of elements;
0214   //! theArray must point to a
0215   //! space enough to place theLength elements
0216   Standard_EXPORT const BinObjMgt_Persistent& GetCharArray (const BinObjMgt_PChar theArray, const Standard_Integer theLength) const;
0217   
0218   //! Get C array of unsigned chars, theLength is the number of elements;
0219   //! theArray must point to a
0220   //! space enough to place theLength elements
0221   Standard_EXPORT const BinObjMgt_Persistent& GetByteArray (const BinObjMgt_PByte theArray, const Standard_Integer theLength) const;
0222   
0223   //! Get C array of ExtCharacter, theLength is the number of elements;
0224   //! theArray must point to a
0225   //! space enough to place theLength elements
0226   Standard_EXPORT const BinObjMgt_Persistent& GetExtCharArray (const BinObjMgt_PExtChar theArray, const Standard_Integer theLength) const;
0227   
0228   //! Get C array of int, theLength is the number of elements;
0229   //! theArray must point to a
0230   //! space enough to place theLength elements
0231   Standard_EXPORT const BinObjMgt_Persistent& GetIntArray (const BinObjMgt_PInteger theArray, const Standard_Integer theLength) const;
0232   
0233   //! Get C array of double, theLength is the number of elements;
0234   //! theArray must point to a
0235   //! space enough to place theLength elements
0236   Standard_EXPORT const BinObjMgt_Persistent& GetRealArray (const BinObjMgt_PReal theArray, const Standard_Integer theLength) const;
0237   
0238   //! Get C array of float, theLength is the number of elements;
0239   //! theArray must point to a
0240   //! space enough to place theLength elements
0241   Standard_EXPORT const BinObjMgt_Persistent& GetShortRealArray (const BinObjMgt_PShortReal theArray, const Standard_Integer theLength) const;
0242   
0243   //! Tells the current position for get/put
0244     Standard_Integer Position() const;
0245   
0246   //! Sets the current position for get/put.
0247   //! Resets an error state depending on the validity of thePos.
0248   //! Returns the new state (value of IsOK())
0249     Standard_Boolean SetPosition (const Standard_Integer thePos) const;
0250   
0251   //! Truncates the buffer by current position,
0252   //! i.e. updates mySize
0253     void Truncate();
0254   
0255   //! Indicates an error after Get methods or SetPosition
0256     Standard_Boolean IsError() const;
0257   Standard_Boolean operator !() const
0258   {
0259     return IsError();
0260   }
0261   
0262   //! Indicates a good state after Get methods or SetPosition
0263     Standard_Boolean IsOK() const;
0264   operator Standard_Boolean () const { return IsOK(); }
0265   
0266   //! Initializes me to reuse again
0267   Standard_EXPORT void Init();
0268   
0269   //! Sets the Id of the object
0270     void SetId (const Standard_Integer theId);
0271   
0272   //! Sets the Id of the type of the object
0273     void SetTypeId (const Standard_Integer theId);
0274   
0275   //! Returns the Id of the object
0276     Standard_Integer Id() const;
0277   
0278   //! Returns the Id of the type of the object
0279     Standard_Integer TypeId() const;
0280   
0281   //! Returns the length of data
0282     Standard_Integer Length() const;
0283   
0284   //! Stores <me> to the stream.
0285   //! inline Standard_OStream& operator<< (Standard_OStream&,
0286   //! BinObjMgt_Persistent&) is also available.
0287   //! If theDirectStream is true, after this data the direct stream data is stored.
0288   Standard_EXPORT Standard_OStream& Write (Standard_OStream& theOS, const Standard_Boolean theDirectStream = Standard_False);
0289   
0290   //! Retrieves <me> from the stream.
0291   //! inline Standard_IStream& operator>> (Standard_IStream&,
0292   //! BinObjMgt_Persistent&) is also available
0293   Standard_EXPORT Standard_IStream& Read (Standard_IStream& theIS);
0294   
0295   //! Frees the allocated memory;
0296   //! This object can be reused after call to Init
0297   Standard_EXPORT void Destroy();
0298   ~BinObjMgt_Persistent()
0299   {
0300     Destroy();
0301   }
0302 
0303   //! Sets the stream for direct writing
0304   Standard_EXPORT void SetOStream (Standard_OStream& theStream) { myOStream = &theStream; }
0305   //! Sets the stream for direct reading
0306   Standard_EXPORT void SetIStream (Standard_IStream& theStream) { myIStream = &theStream; }
0307   //! Gets the stream for and enables direct writing
0308   Standard_EXPORT Standard_OStream* GetOStream();
0309   //! Gets the stream for and enables direct reading
0310   Standard_EXPORT Standard_IStream* GetIStream();
0311   //! Returns true if after this record a direct writing to the stream is performed.
0312   Standard_EXPORT Standard_Boolean IsDirect() { return myDirectWritingIsEnabled; }
0313   //! Returns the start position of the direct writing in the stream
0314   Standard_EXPORT Handle(BinObjMgt_Position) StreamStart() { return myStreamStart; }
0315 
0316 private:
0317 
0318   
0319   //! Aligns myOffset to the given size;
0320   //! enters the next piece if the end of the current one is reached;
0321   //! toClear==true means to fill unused space by 0
0322     void alignOffset (const Standard_Integer theSize, const Standard_Boolean toClear = Standard_False) const;
0323   
0324   //! Prepares the room for theSize bytes;
0325   //! returns the number of pieces except for the current one
0326   //! are to be occupied
0327     Standard_Integer prepareForPut (const Standard_Integer theSize);
0328   
0329   //! Allocates theNbPieces more pieces
0330   Standard_EXPORT void incrementData (const Standard_Integer theNbPieces);
0331   
0332   //! Checks if there is no more data of the given size starting
0333   //! from the current position in myData
0334     Standard_Boolean noMoreData (const Standard_Integer theSize) const;
0335   
0336   //! Puts theLength bytes from theArray
0337   Standard_EXPORT void putArray (const Standard_Address theArray, const Standard_Integer theSize);
0338   
0339   //! Gets theLength bytes into theArray
0340   Standard_EXPORT void getArray (const Standard_Address theArray, const Standard_Integer theSize) const;
0341   
0342   //! Inverses bytes in the data addressed by the given values
0343   Standard_EXPORT void inverseExtCharData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
0344   
0345   //! Inverses bytes in the data addressed by the given values
0346   Standard_EXPORT void inverseIntData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
0347   
0348   //! Inverses bytes in the data addressed by the given values
0349   Standard_EXPORT void inverseRealData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
0350   
0351   //! Inverses bytes in the data addressed by the given values
0352   Standard_EXPORT void inverseShortRealData (const Standard_Integer theIndex, const Standard_Integer theOffset, const Standard_Integer theSize);
0353 
0354 
0355   TColStd_SequenceOfAddress myData;
0356   Standard_Integer myIndex;
0357   Standard_Integer myOffset;
0358   Standard_Integer mySize;
0359   Standard_Boolean myIsError;
0360   Standard_OStream* myOStream; ///< stream to write in case direct writing is enabled
0361   Standard_IStream* myIStream; ///< stream to write in case direct reading is enabled
0362   Standard_Boolean myDirectWritingIsEnabled;
0363   Handle(BinObjMgt_Position) myStreamStart; ///< position where the direct writing to the script is started
0364 };
0365 
0366 
0367 #include <BinObjMgt_Persistent.lxx>
0368 
0369 
0370 
0371 
0372 
0373 #endif // _BinObjMgt_Persistent_HeaderFile