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