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_HArray1_HeaderFile
16 #define _StdLPersistent_HArray1_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_DefineHArray1.hxx>
27 #include <TColStd_HArray1OfInteger.hxx>
28 #include <TColStd_HArray1OfReal.hxx>
29 #include <TColStd_HArray1OfByte.hxx>
31 class TCollection_HExtendedString;
36 DEFINE_HARRAY1 (StdLPersistent_HArray1OfPersistent,
37 NCollection_Array1<Handle(StdObjMgt_Persistent)>)
40 class StdLPersistent_HArray1
42 class base : public StdObjMgt_Persistent
45 //! Read persistent data from a file.
46 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
47 //! Write persistent data to a file.
48 Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
51 virtual Standard_Integer lowerBound() const = 0;
52 virtual Standard_Integer upperBound() const = 0;
53 virtual void createArray (const Standard_Integer theLowerBound,
54 const Standard_Integer theUpperBound) = 0;
56 virtual void readValue (StdObjMgt_ReadData& theReadData,
57 const Standard_Integer theIndex) = 0;
58 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
59 const Standard_Integer theIndex) const = 0;
63 template <class ArrayClass>
64 class instance : public base
66 friend class StdLPersistent_HArray1;
69 typedef Handle(ArrayClass) ArrayHandle;
70 typedef typename ArrayClass::value_type ValueType;
71 typedef typename ArrayClass::Iterator Iterator;
75 const Handle(ArrayClass)& Array() const { return myArray; }
78 virtual Standard_Integer lowerBound() const { return myArray->Lower(); }
79 virtual Standard_Integer upperBound() const { return myArray->Upper(); }
80 virtual void createArray(const Standard_Integer theLowerBound,
81 const Standard_Integer theUpperBound)
82 { myArray = new ArrayClass (theLowerBound, theUpperBound); }
84 virtual void readValue (StdObjMgt_ReadData& theReadData,
85 const Standard_Integer theIndex)
86 { theReadData >> myArray->ChangeValue (theIndex); }
87 virtual void writeValue(StdObjMgt_WriteData& theWriteData,
88 const Standard_Integer theIndex) const
89 { theWriteData << myArray->Value(theIndex); }
90 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
91 { return PChildrenT(theChildren); }
92 virtual Standard_CString PName() const
94 Standard_CString PNameT() const
96 Standard_NotImplemented::Raise("StdLPersistent_HArray1::instance::PName - not implemented");
99 void PChildrenT(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
102 Handle(ArrayClass) myArray;
105 template <class ArrayClass>
106 class named_instance : public instance<ArrayClass>
108 friend class StdLPersistent_HArray1;
111 virtual Standard_CString PName() const
113 Standard_NullValue_Raise_if(!myPName,
114 "StdLPersistent_HArray1::named_instance::PName - name not set");
119 named_instance(Standard_CString thePName) : myPName(thePName) {}
121 Standard_CString myPName;
125 typedef instance<TColStd_HArray1OfInteger> Integer;
126 typedef instance<TColStd_HArray1OfReal> Real;
127 typedef instance<TColStd_HArray1OfByte> Byte;
128 typedef instance<StdLPersistent_HArray1OfPersistent> Persistent;
131 template <class ArrayClass>
132 static Handle(instance<ArrayClass>) Translate(const ArrayClass& theArray)
134 Handle(instance<ArrayClass>) aPArray = new instance<ArrayClass>;
135 aPArray->myArray = new ArrayClass(theArray.Lower(), theArray.Upper());
136 for (Standard_Integer i = theArray.Lower(); i <= theArray.Upper(); ++i)
137 aPArray->myArray->ChangeValue(i) = theArray.Value(i);
140 template <class ArrayClass>
141 static Handle(instance<ArrayClass>) Translate(Standard_CString thePName, const ArrayClass& theArray)
143 Handle(named_instance<ArrayClass>) aPArray = new named_instance<ArrayClass>(thePName);
144 aPArray->myArray = new ArrayClass(theArray.Lower(), theArray.Upper());
145 for (Standard_Integer i = theArray.Lower(); i <= theArray.Upper(); ++i)
146 aPArray->myArray->ChangeValue(i) = theArray.Value(i);
152 inline Standard_CString StdLPersistent_HArray1::instance<TColStd_HArray1OfInteger>::PNameT() const
153 { return "PColStd_HArray1OfInteger"; }
156 inline Standard_CString StdLPersistent_HArray1::instance<TColStd_HArray1OfReal>::PNameT() const
157 { return "PColStd_HArray1OfReal"; }
160 inline Standard_CString StdLPersistent_HArray1::instance<TColStd_HArray1OfByte>::PNameT() const
161 { return "PColStd_HArray1OfByte"; }
163 inline StdObjMgt_ReadData& operator >>
164 (StdObjMgt_ReadData& theReadData, Standard_Byte& theByte)
165 { return theReadData >> reinterpret_cast<Standard_Character&> (theByte); }
167 inline StdObjMgt_WriteData& operator >>
168 (StdObjMgt_WriteData& theWriteData, const Standard_Byte& theByte)
169 { return theWriteData << reinterpret_cast<const Standard_Character&> (theByte); }
172 inline void StdLPersistent_HArray1::instance<StdLPersistent_HArray1OfPersistent>::PChildrenT
173 (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
175 for (Standard_Integer i = myArray->Lower(); i <= myArray->Upper(); ++i)
176 theChildren.Append(myArray->Value(i));