File indexing completed on 2026-09-23 09:18:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _StdLPersistent_HArray1_HeaderFile
0015 #define _StdLPersistent_HArray1_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_HArray1.hxx>
0025 #include <Standard_Integer.hxx>
0026 #include <NCollection_Array1.hxx>
0027
0028 class StdLPersistent_HArray1
0029 {
0030 class base : public StdObjMgt_Persistent
0031 {
0032 public:
0033
0034 Standard_EXPORT void Read(StdObjMgt_ReadData& theReadData) override;
0035
0036 Standard_EXPORT void Write(StdObjMgt_WriteData& theWriteData) const override;
0037
0038 protected:
0039 virtual int lowerBound() const = 0;
0040 virtual int upperBound() const = 0;
0041 virtual void createArray(const int theLowerBound, const int theUpperBound) = 0;
0042
0043 virtual void readValue(StdObjMgt_ReadData& theReadData, const int theIndex) = 0;
0044 virtual void writeValue(StdObjMgt_WriteData& theWriteData, const int theIndex) const = 0;
0045 };
0046
0047 protected:
0048 template <class ArrayClass>
0049 class instance : public base
0050 {
0051 friend class StdLPersistent_HArray1;
0052
0053 public:
0054 typedef occ::handle<ArrayClass> ArrayHandle;
0055 typedef typename ArrayClass::value_type ValueType;
0056 typedef typename ArrayClass::Iterator Iterator;
0057
0058 public:
0059
0060 const occ::handle<ArrayClass>& Array() const { return myArray; }
0061
0062 protected:
0063 int lowerBound() const override { return myArray->Lower(); }
0064
0065 int upperBound() const override { return myArray->Upper(); }
0066
0067 void createArray(const int theLowerBound, const int theUpperBound) override
0068 {
0069 myArray = new ArrayClass(theLowerBound, theUpperBound);
0070 }
0071
0072 void readValue(StdObjMgt_ReadData& theReadData, const int theIndex) override
0073 {
0074 theReadData >> myArray->ChangeValue(theIndex);
0075 }
0076
0077 void writeValue(StdObjMgt_WriteData& theWriteData, const int theIndex) const override
0078 {
0079 theWriteData << myArray->Value(theIndex);
0080 }
0081
0082 void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const override
0083 {
0084 return PChildrenT(theChildren);
0085 }
0086
0087 const char* PName() const override { return PNameT(); }
0088
0089 const char* PNameT() const
0090 {
0091 throw Standard_NotImplemented("StdLPersistent_HArray1::instance::PName - not implemented");
0092 }
0093
0094 void PChildrenT(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
0095
0096 protected:
0097 occ::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 const char* PName() const override
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(const char* thePName)
0115 : myPName(thePName)
0116 {
0117 }
0118
0119 const char* myPName;
0120 };
0121
0122 public:
0123 typedef instance<NCollection_HArray1<int>> Integer;
0124 typedef instance<NCollection_HArray1<double>> Real;
0125 typedef instance<NCollection_HArray1<uint8_t>> Byte;
0126 typedef instance<NCollection_HArray1<occ::handle<StdObjMgt_Persistent>>> Persistent;
0127
0128 public:
0129 template <class ArrayClass>
0130 static Handle(instance<ArrayClass>) Translate(const ArrayClass& theArray)
0131 {
0132 Handle(instance<ArrayClass>) aPArray = new instance<ArrayClass>;
0133 aPArray->myArray = new ArrayClass(theArray.Lower(), theArray.Upper());
0134 for (int i = theArray.Lower(); i <= theArray.Upper(); ++i)
0135 aPArray->myArray->ChangeValue(i) = theArray.Value(i);
0136 return aPArray;
0137 }
0138
0139 template <class ArrayClass>
0140 static Handle(instance<ArrayClass>) Translate(const char* thePName, const ArrayClass& theArray)
0141 {
0142 Handle(named_instance<ArrayClass>) aPArray = new named_instance<ArrayClass>(thePName);
0143 aPArray->myArray = new ArrayClass(theArray.Lower(), theArray.Upper());
0144 for (int i = theArray.Lower(); i <= theArray.Upper(); ++i)
0145 aPArray->myArray->ChangeValue(i) = theArray.Value(i);
0146 return aPArray;
0147 }
0148 };
0149
0150 template <>
0151 inline const char* StdLPersistent_HArray1::instance<NCollection_HArray1<int>>::PNameT() const
0152 {
0153 return "PColStd_HArray1OfInteger";
0154 }
0155
0156 template <>
0157 inline const char* StdLPersistent_HArray1::instance<NCollection_HArray1<double>>::PNameT() const
0158 {
0159 return "PColStd_HArray1OfReal";
0160 }
0161
0162 template <>
0163 inline const char* StdLPersistent_HArray1::instance<NCollection_HArray1<uint8_t>>::PNameT() const
0164 {
0165 return "PColStd_HArray1OfByte";
0166 }
0167
0168 inline StdObjMgt_ReadData& operator>>(StdObjMgt_ReadData& theReadData, uint8_t& theByte)
0169 {
0170 return theReadData >> reinterpret_cast<char&>(theByte);
0171 }
0172
0173 inline StdObjMgt_WriteData& operator>>(StdObjMgt_WriteData& theWriteData, const uint8_t& theByte)
0174 {
0175 return theWriteData << reinterpret_cast<const char&>(theByte);
0176 }
0177
0178 template <>
0179 inline void StdLPersistent_HArray1::
0180 instance<NCollection_HArray1<occ::handle<StdObjMgt_Persistent>>>::PChildrenT(
0181 StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0182 {
0183 for (int i = myArray->Lower(); i <= myArray->Upper(); ++i)
0184 theChildren.Append(myArray->Value(i));
0185 }
0186
0187 #endif