Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:59:19

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 #ifndef _StdLPersistent_NamedData_HeaderFile
0015 #define _StdLPersistent_NamedData_HeaderFile
0016 
0017 #include <StdObjMgt_Attribute.hxx>
0018 #include <StdLPersistent_HArray1.hxx>
0019 #include <StdLPersistent_HArray2.hxx>
0020 
0021 #include <TDataStd_NamedData.hxx>
0022 #include <TCollection_HExtendedString.hxx>
0023 
0024 class StdLPersistent_NamedData : public StdObjMgt_Attribute<TDataStd_NamedData>
0025 {
0026   template <class HValuesArray>
0027   class pMapData
0028   {
0029   public:
0030     typedef typename HValuesArray::ValueType ValueType;
0031 
0032     inline void Read(StdObjMgt_ReadData& theReadData) { theReadData >> myKeys >> myValues; }
0033 
0034     inline void Write(StdObjMgt_WriteData& theWriteData) const
0035     {
0036       theWriteData << myKeys << myValues;
0037     }
0038 
0039     inline operator bool() const { return !myKeys.IsNull(); }
0040 
0041     const TCollection_ExtendedString& Key(int theIndex) const
0042     {
0043       return myKeys->Array()->Value(theIndex)->ExtString()->String();
0044     }
0045 
0046     ValueType Value(int theIndex) const
0047     {
0048       return myValues ? myValues->Array()->Value(theIndex) : ValueType{};
0049     }
0050 
0051   private:
0052     Handle(StdLPersistent_HArray1::Persistent) myKeys;
0053     occ::handle<HValuesArray>                  myValues;
0054   };
0055 
0056 public:
0057   //! Read persistent data from a file.
0058   inline void Read(StdObjMgt_ReadData& theReadData)
0059   {
0060     theReadData >> myDimensions;
0061     myInts.Read(theReadData);
0062     myReals.Read(theReadData);
0063     myStrings.Read(theReadData);
0064     myBytes.Read(theReadData);
0065     myIntArrays.Read(theReadData);
0066     myRealArrays.Read(theReadData);
0067   }
0068 
0069   //! Write persistent data to a file.
0070   inline void Write(StdObjMgt_WriteData& theWriteData) const
0071   {
0072     theWriteData << myDimensions;
0073     myInts.Write(theWriteData);
0074     myReals.Write(theWriteData);
0075     myStrings.Write(theWriteData);
0076     myBytes.Write(theWriteData);
0077     myIntArrays.Write(theWriteData);
0078     myRealArrays.Write(theWriteData);
0079   }
0080 
0081   //! Gets persistent child objects
0082   void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
0083 
0084   //! Returns persistent type name
0085   const char* PName() const { return "PDataStd_NamedData"; }
0086 
0087   //! Import transient attribute from the persistent data.
0088   void Import(const occ::handle<TDataStd_NamedData>& theAttribute) const;
0089 
0090 private:
0091   inline int lower(int theIndex) const;
0092   inline int upper(int theIndex) const;
0093 
0094 private:
0095   Handle(StdLPersistent_HArray2::Integer)      myDimensions;
0096   pMapData<StdLPersistent_HArray1::Integer>    myInts;
0097   pMapData<StdLPersistent_HArray1::Real>       myReals;
0098   pMapData<StdLPersistent_HArray1::Persistent> myStrings;
0099   pMapData<StdLPersistent_HArray1::Byte>       myBytes;
0100   pMapData<StdLPersistent_HArray1::Persistent> myIntArrays;
0101   pMapData<StdLPersistent_HArray1::Persistent> myRealArrays;
0102 };
0103 
0104 #endif