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::stringConverter
38 stringConverter (const Handle(TDF_Data)&) {}
40 const TCollection_ExtendedString& operator()
41 (const Handle(StdObjMgt_Persistent)& theValue) const
43 static TCollection_ExtendedString anEmptyString;
44 if (theValue.IsNull())
47 Handle(TCollection_HExtendedString) aString = theValue->ExtString();
48 return aString ? aString->String() : anEmptyString;
52 struct StdLPersistent_Collection::referenceConverter
54 referenceConverter (const Handle(TDF_Data)& theDF) : myDF (theDF) {}
56 TDF_Label operator() (const Handle(StdObjMgt_Persistent)& theValue) const
57 { return theValue->Label (myDF); }
60 Handle(TDF_Data) myDF;
63 //=======================================================================
65 //purpose : Read persistent data from a file
66 //=======================================================================
68 void StdLPersistent_Collection::booleanArrayBase<Base>::Read
69 (StdObjMgt_ReadData& theReadData)
71 Base::Read (theReadData);
72 theReadData >> myLower >> myUpper;
76 template <class ArrayHandle, class Converter>
77 void StdLPersistent_Collection::booleanArrayBase<Base>::import
78 (const ArrayHandle& theArray, Converter theConverter) const
80 Handle(TColStd_HArray1OfByte) aByteArray =
81 new TColStd_HArray1OfByte (theArray->Lower(), theArray->Upper());
83 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
84 aByteArray->SetValue (i, theConverter (theArray->Value(i)));
86 this->myTransient->Init (myLower, myUpper);
87 this->myTransient->SetInternalArray (aByteArray);
91 template <class ArrayHandle, class Converter>
92 void StdLPersistent_Collection::directArrayBase<Base>::import
93 (const ArrayHandle& theArray, Converter) const
95 this->myTransient->ChangeArray (theArray);
99 template <class ArrayHandle, class Converter>
100 void StdLPersistent_Collection::arrayBase<Base>::import
101 (const ArrayHandle& theArray, Converter theConverter) const
103 this->myTransient->Init (theArray->Lower(), theArray->Upper());
104 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
105 this->myTransient->SetValue (i, theConverter (theArray->Value(i)));
108 template <class Base>
109 template <class ArrayHandle, class Converter>
110 void StdLPersistent_Collection::listBase<Base>::import
111 (const ArrayHandle& theArray, Converter theConverter) const
113 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
114 this->myTransient->Append (theConverter (theArray->Value(i)));
117 template <class Base>
118 template <class ArrayHandle, class Converter>
119 void StdLPersistent_Collection::mapBase<Base>::import
120 (const ArrayHandle& theArray, Converter theConverter) const
122 Handle(TColStd_HPackedMapOfInteger) anHMap = new TColStd_HPackedMapOfInteger;
123 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
124 anHMap->ChangeMap().Add (theConverter (theArray->Value(i)));
125 this->myTransient->ChangeMap (anHMap);
128 //=======================================================================
129 //function : ImportAttribute
130 //purpose : Import transient attribuite from the persistent data
131 //=======================================================================
132 template <template<class> class BaseT,
136 void StdLPersistent_Collection::
137 instance<BaseT, HArrayClass, AttribClass, Converter>::ImportAttribute()
139 Handle(HArrayClass) anHArray = Handle(HArrayClass)::DownCast (this->myData);
142 typename HArrayClass::ArrayHandle anArray = anHArray->Array();
144 this->import (anArray, Converter (this->myTransient->Label().Data()));
145 this->myData.Nullify();
149 //=======================================================================
151 //purpose : Read persistent data from a file
152 //=======================================================================
153 template <class Instance>
154 void StdLPersistent_Collection::instance_1<Instance>::Read
155 (StdObjMgt_ReadData& theReadData)
157 Instance::Read (theReadData);
158 theReadData >> myDelta;
161 //=======================================================================
162 //function : ImportAttribute
163 //purpose : Import transient attribuite from the persistent data
164 //=======================================================================
165 template <class Instance>
166 void StdLPersistent_Collection::instance_1<Instance>::ImportAttribute()
168 Instance::ImportAttribute();
169 this->myTransient->SetDelta (myDelta);
173 template class StdLPersistent_Collection::instance
174 <StdLPersistent_Collection::booleanArrayBase,
175 StdLPersistent_Collection::integer,
176 TDataStd_BooleanArray,
177 StdLPersistent_Collection::byteConverter>;
179 template class StdLPersistent_Collection::instance
180 <StdLPersistent_Collection::directArrayBase,
181 StdLPersistent_Collection::integer,
182 TDataStd_IntegerArray,
183 StdLPersistent_Collection::noConversion>;
185 template class StdLPersistent_Collection::instance
186 <StdLPersistent_Collection::directArrayBase,
187 StdLPersistent_Collection::real,
189 StdLPersistent_Collection::noConversion>;
191 template class StdLPersistent_Collection::instance
192 <StdLPersistent_Collection::arrayBase,
193 StdLPersistent_Collection::integer,
195 StdLPersistent_Collection::byteConverter>;
197 template class StdLPersistent_Collection::instance
198 <StdLPersistent_Collection::arrayBase,
199 StdLPersistent_Collection::persistent,
200 TDataStd_ExtStringArray,
201 StdLPersistent_Collection::stringConverter>;
203 template class StdLPersistent_Collection::instance
204 <StdLPersistent_Collection::arrayBase,
205 StdLPersistent_Collection::persistent,
206 TDataStd_ReferenceArray,
207 StdLPersistent_Collection::referenceConverter>;
209 template class StdLPersistent_Collection::instance
210 <StdLPersistent_Collection::listBase,
211 StdLPersistent_Collection::integer,
212 TDataStd_IntegerList,
213 StdLPersistent_Collection::noConversion>;
215 template class StdLPersistent_Collection::instance
216 <StdLPersistent_Collection::listBase,
217 StdLPersistent_Collection::real,
219 StdLPersistent_Collection::noConversion>;
221 template class StdLPersistent_Collection::instance
222 <StdLPersistent_Collection::listBase,
223 StdLPersistent_Collection::integer,
224 TDataStd_BooleanList,
225 StdLPersistent_Collection::noConversion>;
227 template class StdLPersistent_Collection::instance
228 <StdLPersistent_Collection::listBase,
229 StdLPersistent_Collection::persistent,
230 TDataStd_ExtStringList,
231 StdLPersistent_Collection::stringConverter>;
233 template class StdLPersistent_Collection::instance
234 <StdLPersistent_Collection::listBase,
235 StdLPersistent_Collection::persistent,
236 TDataStd_ReferenceList,
237 StdLPersistent_Collection::referenceConverter>;
239 template class StdLPersistent_Collection::instance
240 <StdLPersistent_Collection::mapBase,
241 StdLPersistent_Collection::integer,
242 TDataStd_IntPackedMap,
243 StdLPersistent_Collection::noConversion>;
245 template class StdLPersistent_Collection::instance_1
246 <StdLPersistent_Collection::IntegerArray>;
248 template class StdLPersistent_Collection::instance_1
249 <StdLPersistent_Collection::RealArray>;
251 template class StdLPersistent_Collection::instance_1
252 <StdLPersistent_Collection::ByteArray>;
254 template class StdLPersistent_Collection::instance_1
255 <StdLPersistent_Collection::ExtStringArray>;
257 template class StdLPersistent_Collection::instance_1
258 <StdLPersistent_Collection::IntPackedMap>;