Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 1996-11-29
0002 // Created by: Christophe LEYNADIER
0003 // Copyright (c) 1996-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _FSD_BinaryFile_HeaderFile
0018 #define _FSD_BinaryFile_HeaderFile
0019 
0020 #include <FSD_BStream.hxx>
0021 #include <FSD_FileHeader.hxx>
0022 #include <Storage_BaseDriver.hxx>
0023 #include <Storage_Error.hxx>
0024 #include <Storage_OpenMode.hxx>
0025 #include <Storage_Data.hxx>
0026 #include <Storage_Position.hxx>
0027 #include <Standard_Integer.hxx>
0028 #include <TColStd_SequenceOfAsciiString.hxx>
0029 #include <TColStd_SequenceOfExtendedString.hxx>
0030 
0031 class TCollection_AsciiString;
0032 class TCollection_ExtendedString;
0033 class Storage_HeaderData;
0034 
0035 // Macro that tells if bytes must be reversed when read/write 
0036 // data to/from a binary file. It is needed to provide binary file compatibility
0037 // between little and big endian platforms.
0038 #ifndef OCCT_BINARY_FILE_DO_INVERSE
0039 #if defined ( SOLARIS ) || defined ( IRIX )
0040 // Do inverse on big endian platform
0041 #define OCCT_BINARY_FILE_DO_INVERSE 1
0042 #else
0043 #define OCCT_BINARY_FILE_DO_INVERSE 0
0044 #endif
0045 #endif
0046 
0047 DEFINE_STANDARD_HANDLE(FSD_BinaryFile,Storage_BaseDriver)
0048 
0049 class FSD_BinaryFile  : public Storage_BaseDriver
0050 {
0051 public:
0052   DEFINE_STANDARD_RTTIEXT(FSD_BinaryFile,Storage_BaseDriver)
0053 
0054 public:
0055 
0056   Standard_EXPORT FSD_BinaryFile();
0057   
0058   Standard_EXPORT Storage_Error Open (const TCollection_AsciiString& aName, const Storage_OpenMode aMode) Standard_OVERRIDE;
0059   
0060   Standard_EXPORT Standard_Boolean IsEnd() Standard_OVERRIDE;
0061   
0062   //! return position in the file. Return -1 upon error.
0063   Standard_EXPORT Storage_Position Tell() Standard_OVERRIDE;
0064   
0065   Standard_EXPORT static Storage_Error IsGoodFileType (const TCollection_AsciiString& aName);
0066   
0067   Standard_EXPORT Storage_Error BeginWriteInfoSection() Standard_OVERRIDE;
0068 
0069   Standard_EXPORT static Standard_Integer WriteInfo (Standard_OStream& theOStream,
0070                                                      const Standard_Integer nbObj,
0071                                                      const TCollection_AsciiString& dbVersion,
0072                                                      const TCollection_AsciiString& date,
0073                                                      const TCollection_AsciiString& schemaName,
0074                                                      const TCollection_AsciiString& schemaVersion,
0075                                                      const TCollection_ExtendedString& appName,
0076                                                      const TCollection_AsciiString& appVersion,
0077                                                      const TCollection_ExtendedString& objectType,
0078                                                      const TColStd_SequenceOfAsciiString& userInfo,
0079                                                      const Standard_Boolean theOnlyCount = Standard_False);
0080   
0081   Standard_EXPORT void WriteInfo (const Standard_Integer nbObj, 
0082                                   const TCollection_AsciiString& dbVersion, 
0083                                   const TCollection_AsciiString& date, 
0084                                   const TCollection_AsciiString& schemaName, 
0085                                   const TCollection_AsciiString& schemaVersion, 
0086                                   const TCollection_ExtendedString& appName, 
0087                                   const TCollection_AsciiString& appVersion, 
0088                                   const TCollection_ExtendedString& objectType, 
0089                                   const TColStd_SequenceOfAsciiString& userInfo) Standard_OVERRIDE;
0090   
0091   Standard_EXPORT Storage_Error EndWriteInfoSection() Standard_OVERRIDE;
0092 
0093   Standard_EXPORT Storage_Error EndWriteInfoSection(Standard_OStream& theOStream);
0094   
0095   Standard_EXPORT Storage_Error BeginReadInfoSection() Standard_OVERRIDE;
0096   
0097   Standard_EXPORT void ReadInfo (Standard_Integer& nbObj, 
0098                                  TCollection_AsciiString& dbVersion, 
0099                                  TCollection_AsciiString& date, 
0100                                  TCollection_AsciiString& schemaName, 
0101                                  TCollection_AsciiString& schemaVersion, 
0102                                  TCollection_ExtendedString& appName, 
0103                                  TCollection_AsciiString& appVersion, 
0104                                  TCollection_ExtendedString& objectType, 
0105                                  TColStd_SequenceOfAsciiString& userInfo) Standard_OVERRIDE;
0106   
0107   Standard_EXPORT void ReadCompleteInfo (Standard_IStream& theIStream, Handle(Storage_Data)& theData) Standard_OVERRIDE;
0108 
0109   Standard_EXPORT Storage_Error EndReadInfoSection() Standard_OVERRIDE;
0110   
0111   Standard_EXPORT Storage_Error BeginWriteCommentSection() Standard_OVERRIDE;
0112   
0113   Standard_EXPORT Storage_Error BeginWriteCommentSection (Standard_OStream& theOStream);
0114   
0115   Standard_EXPORT void WriteComment (const TColStd_SequenceOfExtendedString& userComments) Standard_OVERRIDE;
0116   
0117   Standard_EXPORT static Standard_Integer WriteComment (Standard_OStream& theOStream,
0118                                                         const TColStd_SequenceOfExtendedString& theComments,
0119                                                         const Standard_Boolean theOnlyCount = Standard_False);
0120   
0121   Standard_EXPORT Storage_Error EndWriteCommentSection() Standard_OVERRIDE;
0122 
0123   Standard_EXPORT Storage_Error EndWriteCommentSection (Standard_OStream& theOStream);
0124   
0125   Standard_EXPORT Storage_Error BeginReadCommentSection() Standard_OVERRIDE;
0126   
0127   Standard_EXPORT void ReadComment (TColStd_SequenceOfExtendedString& userComments) Standard_OVERRIDE;
0128 
0129   Standard_EXPORT static void ReadComment (Standard_IStream& theIStream, TColStd_SequenceOfExtendedString& userComments);
0130   
0131   Standard_EXPORT Storage_Error EndReadCommentSection() Standard_OVERRIDE;
0132   
0133   Standard_EXPORT Storage_Error BeginWriteTypeSection() Standard_OVERRIDE;
0134   
0135   Standard_EXPORT void SetTypeSectionSize (const Standard_Integer aSize) Standard_OVERRIDE;
0136   
0137   Standard_EXPORT void WriteTypeInformations (const Standard_Integer typeNum, const TCollection_AsciiString& typeName) Standard_OVERRIDE;
0138   
0139   Standard_EXPORT Storage_Error EndWriteTypeSection() Standard_OVERRIDE;
0140   
0141   Standard_EXPORT Storage_Error BeginReadTypeSection() Standard_OVERRIDE;
0142   
0143   Standard_EXPORT Standard_Integer TypeSectionSize() Standard_OVERRIDE;
0144 
0145   Standard_EXPORT static Standard_Integer TypeSectionSize(Standard_IStream& theIStream);
0146   
0147   Standard_EXPORT void ReadTypeInformations (Standard_Integer& typeNum, TCollection_AsciiString& typeName) Standard_OVERRIDE;
0148 
0149   Standard_EXPORT static void ReadTypeInformations (Standard_IStream& theIStream, 
0150                                                     Standard_Integer& typeNum, 
0151                                                     TCollection_AsciiString& typeName);
0152   
0153   Standard_EXPORT Storage_Error EndReadTypeSection() Standard_OVERRIDE;
0154   
0155   Standard_EXPORT Storage_Error BeginWriteRootSection() Standard_OVERRIDE;
0156   
0157   Standard_EXPORT void SetRootSectionSize (const Standard_Integer aSize) Standard_OVERRIDE;
0158   
0159   Standard_EXPORT void WriteRoot (const TCollection_AsciiString& rootName, 
0160                                   const Standard_Integer aRef, 
0161                                   const TCollection_AsciiString& aType) Standard_OVERRIDE;
0162   
0163   Standard_EXPORT Storage_Error EndWriteRootSection() Standard_OVERRIDE;
0164   
0165   Standard_EXPORT Storage_Error BeginReadRootSection() Standard_OVERRIDE;
0166   
0167   Standard_EXPORT Standard_Integer RootSectionSize() Standard_OVERRIDE;
0168   
0169   Standard_EXPORT static Standard_Integer RootSectionSize(Standard_IStream& theIStream);
0170   
0171   Standard_EXPORT void ReadRoot (TCollection_AsciiString& rootName, 
0172                                  Standard_Integer& aRef, 
0173                                  TCollection_AsciiString& aType) Standard_OVERRIDE;
0174 
0175   Standard_EXPORT static void ReadRoot (Standard_IStream& theIStream, 
0176                                         TCollection_AsciiString& rootName, 
0177                                         Standard_Integer& aRef, 
0178                                         TCollection_AsciiString& aType);
0179   
0180   Standard_EXPORT Storage_Error EndReadRootSection() Standard_OVERRIDE;
0181   
0182   Standard_EXPORT Storage_Error BeginWriteRefSection() Standard_OVERRIDE;
0183   
0184   Standard_EXPORT void SetRefSectionSize (const Standard_Integer aSize) Standard_OVERRIDE;
0185   
0186   Standard_EXPORT void WriteReferenceType (const Standard_Integer reference, const Standard_Integer typeNum) Standard_OVERRIDE;
0187   
0188   Standard_EXPORT Storage_Error EndWriteRefSection() Standard_OVERRIDE;
0189   
0190   Standard_EXPORT Storage_Error BeginReadRefSection() Standard_OVERRIDE;
0191   
0192   Standard_EXPORT Standard_Integer RefSectionSize() Standard_OVERRIDE;
0193 
0194   Standard_EXPORT static Standard_Integer RefSectionSize(Standard_IStream& theIStream);
0195   
0196   Standard_EXPORT void ReadReferenceType (Standard_Integer& reference, Standard_Integer& typeNum) Standard_OVERRIDE;
0197 
0198   Standard_EXPORT static void ReadReferenceType (Standard_IStream& theIStream, 
0199                                                  Standard_Integer& reference, 
0200                                                  Standard_Integer& typeNum);
0201   
0202   Standard_EXPORT Storage_Error EndReadRefSection() Standard_OVERRIDE;
0203   
0204   Standard_EXPORT Storage_Error BeginWriteDataSection() Standard_OVERRIDE;
0205   
0206   Standard_EXPORT void WritePersistentObjectHeader (const Standard_Integer aRef, const Standard_Integer aType) Standard_OVERRIDE;
0207   
0208   Standard_EXPORT void BeginWritePersistentObjectData() Standard_OVERRIDE;
0209   
0210   Standard_EXPORT void BeginWriteObjectData() Standard_OVERRIDE;
0211   
0212   Standard_EXPORT void EndWriteObjectData() Standard_OVERRIDE;
0213   
0214   Standard_EXPORT void EndWritePersistentObjectData() Standard_OVERRIDE;
0215   
0216   Standard_EXPORT Storage_Error EndWriteDataSection() Standard_OVERRIDE;
0217   
0218   Standard_EXPORT Storage_Error BeginReadDataSection() Standard_OVERRIDE;
0219   
0220   Standard_EXPORT void ReadPersistentObjectHeader (Standard_Integer& aRef, Standard_Integer& aType) Standard_OVERRIDE;
0221   
0222   Standard_EXPORT void BeginReadPersistentObjectData() Standard_OVERRIDE;
0223   
0224   Standard_EXPORT void BeginReadObjectData() Standard_OVERRIDE;
0225   
0226   Standard_EXPORT void EndReadObjectData() Standard_OVERRIDE;
0227   
0228   Standard_EXPORT void EndReadPersistentObjectData() Standard_OVERRIDE;
0229   
0230   Standard_EXPORT Storage_Error EndReadDataSection() Standard_OVERRIDE;
0231   
0232   Standard_EXPORT void SkipObject() Standard_OVERRIDE;
0233   
0234   Standard_EXPORT Storage_BaseDriver& PutReference (const Standard_Integer aValue) Standard_OVERRIDE;
0235   
0236   Standard_EXPORT Storage_BaseDriver& PutCharacter (const Standard_Character aValue) Standard_OVERRIDE;
0237   
0238   Standard_EXPORT Storage_BaseDriver& PutExtCharacter (const Standard_ExtCharacter aValue) Standard_OVERRIDE;
0239   
0240   Standard_EXPORT static Standard_Integer PutInteger (Standard_OStream& theOStream,
0241                                                       const Standard_Integer aValue,
0242                                                       const Standard_Boolean theOnlyCount = Standard_False);
0243 
0244   Standard_EXPORT Storage_BaseDriver& PutInteger (const Standard_Integer aValue) Standard_OVERRIDE;
0245   
0246   Standard_EXPORT Storage_BaseDriver& PutBoolean (const Standard_Boolean aValue) Standard_OVERRIDE;
0247   
0248   Standard_EXPORT Storage_BaseDriver& PutReal (const Standard_Real aValue) Standard_OVERRIDE;
0249   
0250   Standard_EXPORT Storage_BaseDriver& PutShortReal (const Standard_ShortReal aValue) Standard_OVERRIDE;
0251   
0252   Standard_EXPORT Storage_BaseDriver& GetReference (Standard_Integer& aValue) Standard_OVERRIDE;
0253   
0254   Standard_EXPORT Storage_BaseDriver& GetCharacter (Standard_Character& aValue) Standard_OVERRIDE;
0255 
0256   Standard_EXPORT static void GetReference (Standard_IStream& theIStream, Standard_Integer& aValue);
0257   
0258   Standard_EXPORT Storage_BaseDriver& GetExtCharacter (Standard_ExtCharacter& aValue) Standard_OVERRIDE;
0259   
0260   Standard_EXPORT Storage_BaseDriver& GetInteger (Standard_Integer& aValue) Standard_OVERRIDE;
0261 
0262   Standard_EXPORT static void GetInteger (Standard_IStream& theIStream, Standard_Integer& aValue);
0263   
0264   Standard_EXPORT Storage_BaseDriver& GetBoolean (Standard_Boolean& aValue) Standard_OVERRIDE;
0265   
0266   Standard_EXPORT Storage_BaseDriver& GetReal (Standard_Real& aValue) Standard_OVERRIDE;
0267   
0268   Standard_EXPORT Storage_BaseDriver& GetShortReal (Standard_ShortReal& aValue) Standard_OVERRIDE;
0269   
0270   Standard_EXPORT Storage_Error Close() Standard_OVERRIDE;
0271   
0272   Standard_EXPORT void Destroy();
0273 
0274   ~FSD_BinaryFile()
0275   {
0276     Destroy();
0277   }
0278 
0279 public:
0280   //!@name Own methods
0281 
0282   ///Inverse bytes in integer value
0283   static Standard_Integer InverseInt(const Standard_Integer theValue)
0284   {
0285     return (0 | (( theValue & 0x000000ff ) << 24 )
0286               | (( theValue & 0x0000ff00 ) << 8  )
0287               | (( theValue & 0x00ff0000 ) >> 8  )
0288               | (( theValue >> 24 ) & 0x000000ff ) );
0289   }
0290 
0291   ///Inverse bytes in extended character value
0292   static Standard_ExtCharacter InverseExtChar(const Standard_ExtCharacter theValue)
0293   {
0294     return (0 | (( theValue & 0x00ff ) << 8  )
0295             |   (( theValue & 0xff00 ) >> 8  ) );
0296   }
0297 
0298   ///Inverse bytes in real value
0299   Standard_EXPORT static Standard_Real InverseReal(const Standard_Real theValue);
0300 
0301   ///Inverse bytes in short real value
0302   Standard_EXPORT static Standard_ShortReal InverseShortReal(const Standard_ShortReal theValue);
0303 
0304   ///Inverse bytes in size value
0305   Standard_EXPORT static Standard_Size InverseSize(const Standard_Size theValue);
0306   ///Inverse bytes in 64bit unsigned int value
0307   Standard_EXPORT static uint64_t InverseUint64(const uint64_t theValue);
0308 
0309   Standard_EXPORT static void ReadHeader (Standard_IStream& theIStream, FSD_FileHeader& theFileHeader);
0310 
0311   Standard_EXPORT static void ReadHeaderData (Standard_IStream& theIStream, const Handle(Storage_HeaderData)& theHeaderData);
0312 
0313   Standard_EXPORT static void ReadString (Standard_IStream& theIStream, TCollection_AsciiString& buffer);
0314 
0315   Standard_EXPORT static void ReadExtendedString (Standard_IStream& theIStream, TCollection_ExtendedString& buffer);
0316 
0317   Standard_EXPORT static Standard_Integer WriteHeader (Standard_OStream&      theOStream, 
0318                                                        const FSD_FileHeader&  theHeader,
0319                                                        const Standard_Boolean theOnlyCount = Standard_False);
0320 
0321   Standard_EXPORT static Standard_CString MagicNumber();
0322 
0323 protected:
0324   
0325   //! read <rsize> character from the current position.
0326   Standard_EXPORT void ReadChar (TCollection_AsciiString& buffer, const Standard_Size rsize);
0327   
0328   //! read string from the current position.
0329   Standard_EXPORT void ReadString (TCollection_AsciiString& buffer);
0330   
0331   //! write string at the current position.
0332   Standard_EXPORT void WriteString (const TCollection_AsciiString& buffer);
0333 
0334   //! write string at the current position.
0335   Standard_EXPORT static Standard_Integer WriteString (Standard_OStream&              theOStream,
0336                                                        const TCollection_AsciiString& theString,
0337                                                        const Standard_Boolean         theOnlyCount = Standard_False);
0338   
0339   //! read string from the current position.
0340   Standard_EXPORT void ReadExtendedString (TCollection_ExtendedString& buffer);
0341   
0342   //! write string at the current position.
0343   Standard_EXPORT void WriteExtendedString (const TCollection_ExtendedString& buffer);
0344   
0345   //! write string at the current position.
0346   Standard_EXPORT static Standard_Integer WriteExtendedString (Standard_OStream& theOStream,
0347                                                                const TCollection_ExtendedString& theString,
0348                                                                const Standard_Boolean theOnlyCount = Standard_False);
0349 
0350 private:
0351   
0352   void WriteHeader();
0353   
0354   void ReadHeader();
0355   
0356 
0357 private:
0358 
0359   FSD_BStream myStream;
0360   FSD_FileHeader myHeader;
0361 };
0362 
0363 #endif // _FSD_BinaryFile_HeaderFile