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.
14 #include <StdLPersistent_Collection.hxx>
16 #include <TColStd_HPackedMapOfInteger.hxx>
17 #include <TCollection_HExtendedString.hxx>
20 struct StdLPersistent_Collection::noConversion
22 noConversion (const Handle(TDF_Data)&) {}
25 Type operator() (Type theValue) const { return theValue; }
28 struct StdLPersistent_Collection::byteConverter
30 byteConverter (const Handle(TDF_Data)&) {}
32 Standard_Byte operator() (Standard_Integer theValue) const
33 { return static_cast<Standard_Byte> (theValue); }
36 struct StdLPersistent_Collection::boolConverter
38 boolConverter (const Handle(TDF_Data)&) {}
40 Standard_Boolean operator() (Standard_Integer theValue) const
41 { return theValue != 0; }
44 struct StdLPersistent_Collection::stringConverter
46 stringConverter (const Handle(TDF_Data)&) {}
48 const TCollection_ExtendedString& operator()
49 (const Handle(StdObjMgt_Persistent)& theValue) const
51 static TCollection_ExtendedString anEmptyString;
52 if (theValue.IsNull())
55 Handle(TCollection_HExtendedString) aString = theValue->ExtString();
56 return aString ? aString->String() : anEmptyString;
60 struct StdLPersistent_Collection::referenceConverter
62 referenceConverter (const Handle(TDF_Data)& theDF) : myDF (theDF) {}
64 TDF_Label operator() (const Handle(StdObjMgt_Persistent)& theValue) const
65 { return theValue->Label (myDF); }
68 Handle(TDF_Data) myDF;
71 //=======================================================================
73 //purpose : Read persistent data from a file
74 //=======================================================================
76 void StdLPersistent_Collection::booleanArrayBase<Base>::Read
77 (StdObjMgt_ReadData& theReadData)
79 Base::Read (theReadData);
80 theReadData >> myLower >> myUpper;
84 template <class ArrayHandle, class Converter>
85 void StdLPersistent_Collection::booleanArrayBase<Base>::import
86 (const ArrayHandle& theArray, Converter theConverter) const
88 Handle(TColStd_HArray1OfByte) aByteArray =
89 new TColStd_HArray1OfByte (theArray->Lower(), theArray->Upper());
91 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
92 aByteArray->SetValue (i, theConverter (theArray->Value(i)));
94 this->myTransient->Init (myLower, myUpper);
95 this->myTransient->SetInternalArray (aByteArray);
99 template <class ArrayHandle, class Converter>
100 void StdLPersistent_Collection::directArrayBase<Base>::import
101 (const ArrayHandle& theArray, Converter) const
103 this->myTransient->ChangeArray (theArray);
106 template <class Base>
107 template <class ArrayHandle, class Converter>
108 void StdLPersistent_Collection::arrayBase<Base>::import
109 (const ArrayHandle& theArray, Converter theConverter) const
111 this->myTransient->Init (theArray->Lower(), theArray->Upper());
112 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
113 this->myTransient->SetValue (i, theConverter (theArray->Value(i)));
116 template <class Base>
117 template <class ArrayHandle, class Converter>
118 void StdLPersistent_Collection::listBase<Base>::import
119 (const ArrayHandle& theArray, Converter theConverter) const
121 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
122 this->myTransient->Append (theConverter (theArray->Value(i)));
125 template <class Base>
126 template <class ArrayHandle, class Converter>
127 void StdLPersistent_Collection::mapBase<Base>::import
128 (const ArrayHandle& theArray, Converter theConverter) const
130 Handle(TColStd_HPackedMapOfInteger) anHMap = new TColStd_HPackedMapOfInteger;
131 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
132 anHMap->ChangeMap().Add (theConverter (theArray->Value(i)));
133 this->myTransient->ChangeMap (anHMap);
136 //=======================================================================
137 //function : ImportAttribute
138 //purpose : Import transient attribuite from the persistent data
139 //=======================================================================
140 template <template<class> class BaseT,
144 void StdLPersistent_Collection::
145 instance<BaseT, HArrayClass, AttribClass, Converter>::ImportAttribute()
147 Handle(HArrayClass) anHArray = Handle(HArrayClass)::DownCast (this->myData);
150 typename HArrayClass::ArrayHandle anArray = anHArray->Array();
152 this->import (anArray, Converter (this->myTransient->Label().Data()));
153 this->myData.Nullify();
157 //=======================================================================
159 //purpose : Read persistent data from a file
160 //=======================================================================
161 template <class Instance>
162 void StdLPersistent_Collection::instance_1<Instance>::Read
163 (StdObjMgt_ReadData& theReadData)
165 Instance::Read (theReadData);
166 theReadData >> myDelta;
169 //=======================================================================
170 //function : ImportAttribute
171 //purpose : Import transient attribuite from the persistent data
172 //=======================================================================
173 template <class Instance>
174 void StdLPersistent_Collection::instance_1<Instance>::ImportAttribute()
176 Instance::ImportAttribute();
177 this->myTransient->SetDelta (myDelta);
181 template class StdLPersistent_Collection::instance
182 <StdLPersistent_Collection::booleanArrayBase,
183 StdLPersistent_Collection::integer,
184 TDataStd_BooleanArray,
185 StdLPersistent_Collection::byteConverter>;
187 template class StdLPersistent_Collection::instance
188 <StdLPersistent_Collection::directArrayBase,
189 StdLPersistent_Collection::integer,
190 TDataStd_IntegerArray,
191 StdLPersistent_Collection::noConversion>;
193 template class StdLPersistent_Collection::instance
194 <StdLPersistent_Collection::directArrayBase,
195 StdLPersistent_Collection::real,
197 StdLPersistent_Collection::noConversion>;
199 template class StdLPersistent_Collection::instance
200 <StdLPersistent_Collection::arrayBase,
201 StdLPersistent_Collection::integer,
203 StdLPersistent_Collection::byteConverter>;
205 template class StdLPersistent_Collection::instance
206 <StdLPersistent_Collection::arrayBase,
207 StdLPersistent_Collection::persistent,
208 TDataStd_ExtStringArray,
209 StdLPersistent_Collection::stringConverter>;
211 template class StdLPersistent_Collection::instance
212 <StdLPersistent_Collection::arrayBase,
213 StdLPersistent_Collection::persistent,
214 TDataStd_ReferenceArray,
215 StdLPersistent_Collection::referenceConverter>;
217 template class StdLPersistent_Collection::instance
218 <StdLPersistent_Collection::listBase,
219 StdLPersistent_Collection::integer,
220 TDataStd_IntegerList,
221 StdLPersistent_Collection::noConversion>;
223 template class StdLPersistent_Collection::instance
224 <StdLPersistent_Collection::listBase,
225 StdLPersistent_Collection::real,
227 StdLPersistent_Collection::noConversion>;
229 template class StdLPersistent_Collection::instance
230 <StdLPersistent_Collection::listBase,
231 StdLPersistent_Collection::integer,
232 TDataStd_BooleanList,
233 StdLPersistent_Collection::boolConverter>;
235 template class StdLPersistent_Collection::instance
236 <StdLPersistent_Collection::listBase,
237 StdLPersistent_Collection::persistent,
238 TDataStd_ExtStringList,
239 StdLPersistent_Collection::stringConverter>;
241 template class StdLPersistent_Collection::instance
242 <StdLPersistent_Collection::listBase,
243 StdLPersistent_Collection::persistent,
244 TDataStd_ReferenceList,
245 StdLPersistent_Collection::referenceConverter>;
247 template class StdLPersistent_Collection::instance
248 <StdLPersistent_Collection::mapBase,
249 StdLPersistent_Collection::integer,
250 TDataStd_IntPackedMap,
251 StdLPersistent_Collection::noConversion>;
253 template class StdLPersistent_Collection::instance_1
254 <StdLPersistent_Collection::IntegerArray>;
256 template class StdLPersistent_Collection::instance_1
257 <StdLPersistent_Collection::RealArray>;
259 template class StdLPersistent_Collection::instance_1
260 <StdLPersistent_Collection::ByteArray>;
262 template class StdLPersistent_Collection::instance_1
263 <StdLPersistent_Collection::ExtStringArray>;
265 template class StdLPersistent_Collection::instance_1
266 <StdLPersistent_Collection::IntPackedMap>;