Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:59

0001 // Copyright (c) 2015 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 
0015 #ifndef _StdLPersistent_NamedData_HeaderFile
0016 #define _StdLPersistent_NamedData_HeaderFile
0017 
0018 #include <StdObjMgt_Attribute.hxx>
0019 #include <StdLPersistent_HArray1.hxx>
0020 #include <StdLPersistent_HArray2.hxx>
0021 
0022 #include <TDataStd_NamedData.hxx>
0023 #include <TCollection_HExtendedString.hxx>
0024 
0025 class StdLPersistent_NamedData : public StdObjMgt_Attribute<TDataStd_NamedData>
0026 {
0027   template <class HValuesArray>
0028   class pMapData
0029   {
0030   public:
0031     typedef typename HValuesArray::ValueType ValueType;
0032 
0033     inline void Read (StdObjMgt_ReadData& theReadData)
0034       { theReadData >> myKeys >> myValues; }
0035     inline void Write (StdObjMgt_WriteData& theWriteData) const
0036       { theWriteData << myKeys << myValues; }
0037 
0038     inline operator bool() const
0039       { return !myKeys.IsNull(); }
0040 
0041     const TCollection_ExtendedString& Key (Standard_Integer theIndex) const
0042       { return myKeys->Array()->Value(theIndex)->ExtString()->String(); }
0043 
0044     ValueType Value (Standard_Integer theIndex) const
0045       { return myValues ? myValues->Array()->Value(theIndex) : 0; }
0046 
0047   private:
0048     Handle(StdLPersistent_HArray1::Persistent) myKeys;
0049     Handle(HValuesArray)                       myValues;
0050   };
0051 
0052 public:
0053   //! Read persistent data from a file.
0054   inline void Read (StdObjMgt_ReadData& theReadData)
0055   {
0056     theReadData >> myDimensions;
0057     myInts      .Read (theReadData);
0058     myReals     .Read (theReadData);
0059     myStrings   .Read (theReadData);
0060     myBytes     .Read (theReadData);
0061     myIntArrays .Read (theReadData);
0062     myRealArrays.Read (theReadData);
0063   }
0064 
0065   //! Write persistent data to a file.
0066   inline void Write (StdObjMgt_WriteData& theWriteData) const
0067   {
0068     theWriteData << myDimensions;
0069     myInts.Write(theWriteData);
0070     myReals.Write(theWriteData);
0071     myStrings.Write(theWriteData);
0072     myBytes.Write(theWriteData);
0073     myIntArrays.Write(theWriteData);
0074     myRealArrays.Write(theWriteData);
0075   }
0076 
0077   //! Gets persistent child objects
0078   void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
0079 
0080   //! Returns persistent type name
0081   Standard_CString PName() const { return "PDataStd_NamedData"; }
0082 
0083   //! Import transient attribute from the persistent data.
0084   void Import (const Handle(TDataStd_NamedData)& theAttribute) const;
0085 
0086 private:
0087   inline Standard_Integer lower (Standard_Integer theIndex) const;
0088   inline Standard_Integer upper (Standard_Integer theIndex) const;
0089 
0090 private:
0091   Handle(StdLPersistent_HArray2::Integer)      myDimensions;
0092   pMapData<StdLPersistent_HArray1::Integer>    myInts;
0093   pMapData<StdLPersistent_HArray1::Real>       myReals;
0094   pMapData<StdLPersistent_HArray1::Persistent> myStrings;
0095   pMapData<StdLPersistent_HArray1::Byte>       myBytes;
0096   pMapData<StdLPersistent_HArray1::Persistent> myIntArrays;
0097   pMapData<StdLPersistent_HArray1::Persistent> myRealArrays;
0098 };
0099 
0100 #endif