1 // Copyright (c) 2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #ifndef _StdLPersistent_HArray2_HeaderFile
16 #define _StdLPersistent_HArray2_HeaderFile
18 #include <Standard_NotImplemented.hxx>
19 #include <Standard_NullValue.hxx>
21 #include <StdObjMgt_Persistent.hxx>
22 #include <StdObjMgt_ReadData.hxx>
23 #include <StdObjMgt_WriteData.hxx>
25 #include <NCollection_DefineHArray2.hxx>
27 #include <TColStd_HArray2OfInteger.hxx>
28 #include <TColStd_HArray2OfReal.hxx>
31 DEFINE_HARRAY2 (StdLPersistent_HArray2OfPersistent,
32 NCollection_Array2<Handle(StdObjMgt_Persistent)>)
35 class StdLPersistent_HArray2
37 class base : public StdObjMgt_Persistent
40 //! Read persistent data from a file.
41 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
43 //! Read persistent data from a file.
44 Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
47 virtual void lowerBound(Standard_Integer& theRow,
48 Standard_Integer& theCol) const = 0;
49 virtual void upperBound(Standard_Integer& theRow,
50 Standard_Integer& theCol) const = 0;
51 virtual void createArray(
52 const Standard_Integer theLowerRow, const Standard_Integer theLowerCol,
53 const Standard_Integer theUpperRow, const Standard_Integer theUpperCol)
56 virtual void readValue (StdObjMgt_ReadData& theReadData,
57 const Standard_Integer theRow,
58 const Standard_Integer theCol) = 0;
59 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
60 const Standard_Integer theRow,
61 const Standard_Integer theCol) const = 0;
65 template <class ArrayClass>
66 class instance : public base
68 friend class StdLPersistent_HArray2;
71 typedef Handle(ArrayClass) ArrayHandle;
75 const Handle(ArrayClass)& Array() const { return myArray; }
78 virtual void lowerBound(Standard_Integer& theRow,
79 Standard_Integer& theCol) const
81 theRow = myArray->LowerRow();
82 theCol = myArray->LowerCol();
84 virtual void upperBound(Standard_Integer& theRow,
85 Standard_Integer& theCol) const
87 theRow = myArray->UpperRow();
88 theCol = myArray->UpperCol();
90 virtual void createArray(
91 const Standard_Integer theLowerRow, const Standard_Integer theLowerCol,
92 const Standard_Integer theUpperRow, const Standard_Integer theUpperCol)
94 myArray = new ArrayClass (theLowerRow, theUpperRow,
95 theLowerCol, theUpperCol);
97 virtual void readValue (StdObjMgt_ReadData& theReadData,
98 const Standard_Integer theRow,
99 const Standard_Integer theCol)
100 { theReadData >> myArray->ChangeValue (theRow, theCol); }
101 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
102 const Standard_Integer theRow,
103 const Standard_Integer theCol) const
105 theWriteData << myArray->Value(theRow, theCol);
107 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
108 { return PChildrenT(theChildren); }
109 virtual Standard_CString PName() const
111 Standard_CString PNameT() const
113 Standard_NotImplemented::Raise("StdLPersistent_HArray2::instance::PName - not implemented");
116 void PChildrenT(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
119 Handle(ArrayClass) myArray;
122 template <class ArrayClass>
123 class named_instance : public instance<ArrayClass>
125 friend class StdLPersistent_HArray2;
128 virtual Standard_CString PName() const
130 Standard_NullValue_Raise_if(!myPName,
131 "StdLPersistent_HArray2::named_instance::PName - name not set");
136 named_instance(Standard_CString thePName) : myPName(thePName) {}
138 Standard_CString myPName;
142 typedef instance<TColStd_HArray2OfInteger> Integer;
143 typedef instance<TColStd_HArray2OfReal> Real;
144 typedef instance<StdLPersistent_HArray2OfPersistent> Persistent;
147 template <class ArrayClass>
148 static Handle(instance<ArrayClass>) Translate(const ArrayClass& theArray)
150 Handle(instance<ArrayClass>) aPArray = new instance<ArrayClass>;
151 aPArray->myArray = new ArrayClass(theArray.LowerRow(), theArray.UpperRow(),
152 theArray.LowerCol(), theArray.UpperCol());
153 for (Standard_Integer i = theArray.LowerRow(); i <= theArray.UpperRow(); ++i)
154 for (Standard_Integer j = theArray.LowerCol(); j <= theArray.UpperCol(); ++j)
155 aPArray->myArray->ChangeValue(i, j) = theArray.Value(i, j);
158 template <class ArrayClass>
159 static Handle(instance<ArrayClass>) Translate(Standard_CString thePName, const ArrayClass& theArray)
161 Handle(named_instance<ArrayClass>) aPArray = new named_instance<ArrayClass>(thePName);
162 aPArray->myArray = new ArrayClass(theArray.LowerRow(), theArray.UpperRow(),
163 theArray.LowerCol(), theArray.UpperCol());
164 for (Standard_Integer i = theArray.LowerRow(); i <= theArray.UpperRow(); ++i)
165 for (Standard_Integer j = theArray.LowerCol(); j <= theArray.UpperCol(); ++j)
166 aPArray->myArray->ChangeValue(i, j) = theArray.Value(i, j);
172 inline Standard_CString StdLPersistent_HArray2::instance<TColStd_HArray2OfInteger>::PNameT() const
173 { return "PColStd_HArray2OfInteger"; }
176 inline Standard_CString StdLPersistent_HArray2::instance<TColStd_HArray2OfReal>::PNameT() const
177 { return "PColStd_HArray2OfReal"; }
180 inline void StdLPersistent_HArray2::instance<StdLPersistent_HArray2OfPersistent>::PChildrenT
181 (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
183 for (Standard_Integer i = myArray->LowerRow(); i <= myArray->UpperRow(); ++i)
184 for (Standard_Integer j = myArray->LowerCol(); j <= myArray->UpperCol(); ++j)
185 theChildren.Append(myArray->Value(i, j));