File indexing completed on 2026-05-07 08:46:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _StdLPersistent_HArray2_HeaderFile
0015 #define _StdLPersistent_HArray2_HeaderFile
0016
0017 #include <Standard_NotImplemented.hxx>
0018 #include <Standard_NullValue.hxx>
0019
0020 #include <StdObjMgt_Persistent.hxx>
0021 #include <StdObjMgt_ReadData.hxx>
0022 #include <StdObjMgt_WriteData.hxx>
0023
0024 #include <TColStd_HArray2OfInteger.hxx>
0025 #include <TColStd_HArray2OfReal.hxx>
0026
0027 DEFINE_HARRAY2(StdLPersistent_HArray2OfPersistent, NCollection_Array2<Handle(StdObjMgt_Persistent)>)
0028
0029 class StdLPersistent_HArray2
0030 {
0031 class base : public StdObjMgt_Persistent
0032 {
0033 public:
0034
0035 Standard_EXPORT virtual void Read(StdObjMgt_ReadData& theReadData);
0036
0037
0038 Standard_EXPORT virtual void Write(StdObjMgt_WriteData& theWriteData) const;
0039
0040 protected:
0041 virtual void lowerBound(Standard_Integer& theRow, Standard_Integer& theCol) const = 0;
0042 virtual void upperBound(Standard_Integer& theRow, Standard_Integer& theCol) const = 0;
0043 virtual void createArray(const Standard_Integer theLowerRow,
0044 const Standard_Integer theLowerCol,
0045 const Standard_Integer theUpperRow,
0046 const Standard_Integer theUpperCol) = 0;
0047
0048 virtual void readValue(StdObjMgt_ReadData& theReadData,
0049 const Standard_Integer theRow,
0050 const Standard_Integer theCol) = 0;
0051 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
0052 const Standard_Integer theRow,
0053 const Standard_Integer theCol) const = 0;
0054 };
0055
0056 protected:
0057 template <class ArrayClass>
0058 class instance : public base
0059 {
0060 friend class StdLPersistent_HArray2;
0061
0062 public:
0063 typedef Handle(ArrayClass) ArrayHandle;
0064
0065 public:
0066
0067 const Handle(ArrayClass)& Array() const { return myArray; }
0068
0069 protected:
0070 virtual void lowerBound(Standard_Integer& theRow, Standard_Integer& theCol) const
0071 {
0072 theRow = myArray->LowerRow();
0073 theCol = myArray->LowerCol();
0074 }
0075
0076 virtual void upperBound(Standard_Integer& theRow, Standard_Integer& theCol) const
0077 {
0078 theRow = myArray->UpperRow();
0079 theCol = myArray->UpperCol();
0080 }
0081
0082 virtual void createArray(const Standard_Integer theLowerRow,
0083 const Standard_Integer theLowerCol,
0084 const Standard_Integer theUpperRow,
0085 const Standard_Integer theUpperCol)
0086 {
0087 myArray = new ArrayClass(theLowerRow, theUpperRow, theLowerCol, theUpperCol);
0088 }
0089
0090 virtual void readValue(StdObjMgt_ReadData& theReadData,
0091 const Standard_Integer theRow,
0092 const Standard_Integer theCol)
0093 {
0094 theReadData >> myArray->ChangeValue(theRow, theCol);
0095 }
0096
0097 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
0098 const Standard_Integer theRow,
0099 const Standard_Integer theCol) const
0100 {
0101 theWriteData << myArray->Value(theRow, theCol);
0102 }
0103
0104 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0105 {
0106 return PChildrenT(theChildren);
0107 }
0108
0109 virtual Standard_CString PName() const { return PNameT(); }
0110
0111 Standard_CString PNameT() const
0112 {
0113 Standard_NotImplemented::Raise("StdLPersistent_HArray2::instance::PName - not implemented");
0114 return "";
0115 }
0116
0117 void PChildrenT(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
0118
0119 protected:
0120 Handle(ArrayClass) myArray;
0121 };
0122
0123 template <class ArrayClass>
0124 class named_instance : public instance<ArrayClass>
0125 {
0126 friend class StdLPersistent_HArray2;
0127
0128 public:
0129 virtual Standard_CString PName() const
0130 {
0131 Standard_NullValue_Raise_if(!myPName,
0132 "StdLPersistent_HArray2::named_instance::PName - name not set");
0133 return myPName;
0134 }
0135
0136 protected:
0137 named_instance(Standard_CString thePName)
0138 : myPName(thePName)
0139 {
0140 }
0141
0142 Standard_CString myPName;
0143 };
0144
0145 public:
0146 typedef instance<TColStd_HArray2OfInteger> Integer;
0147 typedef instance<TColStd_HArray2OfReal> Real;
0148 typedef instance<StdLPersistent_HArray2OfPersistent> Persistent;
0149
0150 public:
0151 template <class ArrayClass>
0152 static Handle(instance<ArrayClass>) Translate(const ArrayClass& theArray)
0153 {
0154 Handle(instance<ArrayClass>) aPArray = new instance<ArrayClass>;
0155 aPArray->myArray = new ArrayClass(theArray.LowerRow(),
0156 theArray.UpperRow(),
0157 theArray.LowerCol(),
0158 theArray.UpperCol());
0159 for (Standard_Integer i = theArray.LowerRow(); i <= theArray.UpperRow(); ++i)
0160 for (Standard_Integer j = theArray.LowerCol(); j <= theArray.UpperCol(); ++j)
0161 aPArray->myArray->ChangeValue(i, j) = theArray.Value(i, j);
0162 return aPArray;
0163 }
0164
0165 template <class ArrayClass>
0166 static Handle(instance<ArrayClass>) Translate(Standard_CString thePName,
0167 const ArrayClass& theArray)
0168 {
0169 Handle(named_instance<ArrayClass>) aPArray = new named_instance<ArrayClass>(thePName);
0170 aPArray->myArray = new ArrayClass(theArray.LowerRow(),
0171 theArray.UpperRow(),
0172 theArray.LowerCol(),
0173 theArray.UpperCol());
0174 for (Standard_Integer i = theArray.LowerRow(); i <= theArray.UpperRow(); ++i)
0175 for (Standard_Integer j = theArray.LowerCol(); j <= theArray.UpperCol(); ++j)
0176 aPArray->myArray->ChangeValue(i, j) = theArray.Value(i, j);
0177 return aPArray;
0178 }
0179 };
0180
0181 template <>
0182 inline Standard_CString StdLPersistent_HArray2::instance<TColStd_HArray2OfInteger>::PNameT() const
0183 {
0184 return "PColStd_HArray2OfInteger";
0185 }
0186
0187 template <>
0188 inline Standard_CString StdLPersistent_HArray2::instance<TColStd_HArray2OfReal>::PNameT() const
0189 {
0190 return "PColStd_HArray2OfReal";
0191 }
0192
0193 template <>
0194 inline void StdLPersistent_HArray2::instance<StdLPersistent_HArray2OfPersistent>::PChildrenT(
0195 StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0196 {
0197 for (Standard_Integer i = myArray->LowerRow(); i <= myArray->UpperRow(); ++i)
0198 for (Standard_Integer j = myArray->LowerCol(); j <= myArray->UpperCol(); ++j)
0199 theChildren.Append(myArray->Value(i, j));
0200 }
0201
0202 #endif