File indexing completed on 2025-01-18 10:04:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _StdLPersistent_HArray1_HeaderFile
0016 #define _StdLPersistent_HArray1_HeaderFile
0017
0018 #include <Standard_NotImplemented.hxx>
0019 #include <Standard_NullValue.hxx>
0020
0021 #include <StdObjMgt_Persistent.hxx>
0022 #include <StdObjMgt_ReadData.hxx>
0023 #include <StdObjMgt_WriteData.hxx>
0024
0025 #include <TColStd_HArray1OfInteger.hxx>
0026 #include <TColStd_HArray1OfReal.hxx>
0027 #include <TColStd_HArray1OfByte.hxx>
0028
0029
0030
0031 DEFINE_HARRAY1 (StdLPersistent_HArray1OfPersistent,
0032 NCollection_Array1<Handle(StdObjMgt_Persistent)>)
0033
0034
0035 class StdLPersistent_HArray1
0036 {
0037 class base : public StdObjMgt_Persistent
0038 {
0039 public:
0040
0041 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
0042
0043 Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
0044
0045 protected:
0046 virtual Standard_Integer lowerBound() const = 0;
0047 virtual Standard_Integer upperBound() const = 0;
0048 virtual void createArray (const Standard_Integer theLowerBound,
0049 const Standard_Integer theUpperBound) = 0;
0050
0051 virtual void readValue (StdObjMgt_ReadData& theReadData,
0052 const Standard_Integer theIndex) = 0;
0053 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
0054 const Standard_Integer theIndex) const = 0;
0055 };
0056
0057 protected:
0058 template <class ArrayClass>
0059 class instance : public base
0060 {
0061 friend class StdLPersistent_HArray1;
0062
0063 public:
0064 typedef Handle(ArrayClass) ArrayHandle;
0065 typedef typename ArrayClass::value_type ValueType;
0066 typedef typename ArrayClass::Iterator Iterator;
0067
0068 public:
0069
0070 const Handle(ArrayClass)& Array() const { return myArray; }
0071
0072 protected:
0073 virtual Standard_Integer lowerBound() const { return myArray->Lower(); }
0074 virtual Standard_Integer upperBound() const { return myArray->Upper(); }
0075 virtual void createArray(const Standard_Integer theLowerBound,
0076 const Standard_Integer theUpperBound)
0077 { myArray = new ArrayClass (theLowerBound, theUpperBound); }
0078
0079 virtual void readValue (StdObjMgt_ReadData& theReadData,
0080 const Standard_Integer theIndex)
0081 { theReadData >> myArray->ChangeValue (theIndex); }
0082 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
0083 const Standard_Integer theIndex) const
0084 { theWriteData << myArray->Value(theIndex); }
0085 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0086 { return PChildrenT(theChildren); }
0087 virtual Standard_CString PName() const
0088 { return PNameT(); }
0089 Standard_CString PNameT() const
0090 {
0091 Standard_NotImplemented::Raise("StdLPersistent_HArray1::instance::PName - not implemented");
0092 return "";
0093 }
0094 void PChildrenT(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
0095
0096 protected:
0097 Handle(ArrayClass) myArray;
0098 };
0099
0100 template <class ArrayClass>
0101 class named_instance : public instance<ArrayClass>
0102 {
0103 friend class StdLPersistent_HArray1;
0104
0105 public:
0106 virtual Standard_CString PName() const
0107 {
0108 Standard_NullValue_Raise_if(!myPName,
0109 "StdLPersistent_HArray1::named_instance::PName - name not set");
0110 return myPName;
0111 }
0112
0113 protected:
0114 named_instance(Standard_CString thePName) : myPName(thePName) {}
0115
0116 Standard_CString myPName;
0117 };
0118
0119 public:
0120 typedef instance<TColStd_HArray1OfInteger> Integer;
0121 typedef instance<TColStd_HArray1OfReal> Real;
0122 typedef instance<TColStd_HArray1OfByte> Byte;
0123 typedef instance<StdLPersistent_HArray1OfPersistent> Persistent;
0124
0125 public:
0126 template <class ArrayClass>
0127 static Handle(instance<ArrayClass>) Translate(const ArrayClass& theArray)
0128 {
0129 Handle(instance<ArrayClass>) aPArray = new instance<ArrayClass>;
0130 aPArray->myArray = new ArrayClass(theArray.Lower(), theArray.Upper());
0131 for (Standard_Integer i = theArray.Lower(); i <= theArray.Upper(); ++i)
0132 aPArray->myArray->ChangeValue(i) = theArray.Value(i);
0133 return aPArray;
0134 }
0135 template <class ArrayClass>
0136 static Handle(instance<ArrayClass>) Translate(Standard_CString thePName, const ArrayClass& theArray)
0137 {
0138 Handle(named_instance<ArrayClass>) aPArray = new named_instance<ArrayClass>(thePName);
0139 aPArray->myArray = new ArrayClass(theArray.Lower(), theArray.Upper());
0140 for (Standard_Integer i = theArray.Lower(); i <= theArray.Upper(); ++i)
0141 aPArray->myArray->ChangeValue(i) = theArray.Value(i);
0142 return aPArray;
0143 }
0144 };
0145
0146 template<>
0147 inline Standard_CString StdLPersistent_HArray1::instance<TColStd_HArray1OfInteger>::PNameT() const
0148 { return "PColStd_HArray1OfInteger"; }
0149
0150 template<>
0151 inline Standard_CString StdLPersistent_HArray1::instance<TColStd_HArray1OfReal>::PNameT() const
0152 { return "PColStd_HArray1OfReal"; }
0153
0154 template<>
0155 inline Standard_CString StdLPersistent_HArray1::instance<TColStd_HArray1OfByte>::PNameT() const
0156 { return "PColStd_HArray1OfByte"; }
0157
0158 inline StdObjMgt_ReadData& operator >>
0159 (StdObjMgt_ReadData& theReadData, Standard_Byte& theByte)
0160 { return theReadData >> reinterpret_cast<Standard_Character&> (theByte); }
0161
0162 inline StdObjMgt_WriteData& operator >>
0163 (StdObjMgt_WriteData& theWriteData, const Standard_Byte& theByte)
0164 { return theWriteData << reinterpret_cast<const Standard_Character&> (theByte); }
0165
0166 template<>
0167 inline void StdLPersistent_HArray1::instance<StdLPersistent_HArray1OfPersistent>::PChildrenT
0168 (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0169 {
0170 for (Standard_Integer i = myArray->Lower(); i <= myArray->Upper(); ++i)
0171 theChildren.Append(myArray->Value(i));
0172 }
0173
0174 #endif