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 Handle(TCollection_HExtendedString) aString = theValue->ExtString();
45 return aString->String();
48 static TCollection_ExtendedString anEmptyString;
54 struct StdLPersistent_Collection::referenceConverter
56 referenceConverter (const Handle(TDF_Data)& theDF) : myDF (theDF) {}
58 TDF_Label operator() (const Handle(StdObjMgt_Persistent)& theValue) const
59 { return theValue->Label (myDF); }
62 Handle(TDF_Data) myDF;
65 //=======================================================================
67 //purpose : Read persistent data from a file
68 //=======================================================================
69 template <class Persistent>
70 void StdLPersistent_Collection::booleanArrayBase<Persistent>::Read
71 (StdObjMgt_ReadData& theReadData)
73 StdLPersistent_Collection::booleanArrayBase<Persistent>::SingleRef::Read (theReadData);
74 theReadData >> myLower >> myUpper;
77 template <class Persistent>
78 template <class ArrayHandle, class Converter>
79 void StdLPersistent_Collection::booleanArrayBase<Persistent>::import
80 (const ArrayHandle& theArray, Converter theConverter) const
82 Handle(TColStd_HArray1OfByte) aByteArray =
83 new TColStd_HArray1OfByte (theArray->Lower(), theArray->Upper());
85 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
86 aByteArray->SetValue (i, theConverter (theArray->Value(i)));
88 this->myTransient->Init (myLower, myUpper);
89 this->myTransient->SetInternalArray (aByteArray);
92 template <class Persistent>
93 template <class ArrayHandle, class Converter>
94 void StdLPersistent_Collection::directArrayBase<Persistent>::import
95 (const ArrayHandle& theArray, Converter) const
97 this->myTransient->ChangeArray (theArray);
100 template <class Persistent>
101 template <class ArrayHandle, class Converter>
102 void StdLPersistent_Collection::arrayBase<Persistent>::import
103 (const ArrayHandle& theArray, Converter theConverter) const
105 this->myTransient->Init (theArray->Lower(), theArray->Upper());
106 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
107 this->myTransient->SetValue (i, theConverter (theArray->Value(i)));
110 template <class Persistent>
111 template <class ArrayHandle, class Converter>
112 void StdLPersistent_Collection::listBase<Persistent>::import
113 (const ArrayHandle& theArray, Converter theConverter) const
115 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
116 this->myTransient->Append (theConverter (theArray->Value(i)));
119 template <class Persistent>
120 template <class ArrayHandle, class Converter>
121 void StdLPersistent_Collection::mapBase<Persistent>::import
122 (const ArrayHandle& theArray, Converter theConverter) const
124 Handle(TColStd_HPackedMapOfInteger) anHMap = new TColStd_HPackedMapOfInteger;
125 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
126 anHMap->ChangeMap().Add (theConverter (theArray->Value(i)));
127 this->myTransient->ChangeMap (anHMap);
130 //=======================================================================
131 //function : ImportAttribute
132 //purpose : Import transient attribuite from the persistent data
133 //=======================================================================
134 template <template<class> class BaseT,
138 void StdLPersistent_Collection::
139 instance<BaseT, HArrayClass, AttribClass, Converter>::ImportAttribute()
141 Handle(HArrayClass) anHArray;
142 if (this->myData.Cast (anHArray))
144 typename HArrayClass::ArrayHandle anArray = anHArray->Array();
146 this->import (anArray, Converter (this->myTransient->Label().Data()));
147 this->myData.Nullify();
151 //=======================================================================
153 //purpose : Read persistent data from a file
154 //=======================================================================
155 template <class Instance>
156 void StdLPersistent_Collection::instance_1<Instance>::Read
157 (StdObjMgt_ReadData& theReadData)
159 Instance::Read (theReadData);
160 theReadData >> myDelta;
163 //=======================================================================
164 //function : ImportAttribute
165 //purpose : Import transient attribuite from the persistent data
166 //=======================================================================
167 template <class Instance>
168 void StdLPersistent_Collection::instance_1<Instance>::ImportAttribute()
170 Instance::ImportAttribute();
171 this->myTransient->SetDelta (myDelta);
175 template class StdLPersistent_Collection::instance
176 <StdLPersistent_Collection::booleanArrayBase,
177 StdLPersistent_Collection::integer,
178 TDataStd_BooleanArray,
179 StdLPersistent_Collection::byteConverter>;
181 template class StdLPersistent_Collection::instance
182 <StdLPersistent_Collection::directArrayBase,
183 StdLPersistent_Collection::integer,
184 TDataStd_IntegerArray,
185 StdLPersistent_Collection::noConversion>;
187 template class StdLPersistent_Collection::instance
188 <StdLPersistent_Collection::directArrayBase,
189 StdLPersistent_Collection::real,
191 StdLPersistent_Collection::noConversion>;
193 template class StdLPersistent_Collection::instance
194 <StdLPersistent_Collection::arrayBase,
195 StdLPersistent_Collection::integer,
197 StdLPersistent_Collection::byteConverter>;
199 template class StdLPersistent_Collection::instance
200 <StdLPersistent_Collection::arrayBase,
201 StdLPersistent_Collection::persistent,
202 TDataStd_ExtStringArray,
203 StdLPersistent_Collection::stringConverter>;
205 template class StdLPersistent_Collection::instance
206 <StdLPersistent_Collection::arrayBase,
207 StdLPersistent_Collection::persistent,
208 TDataStd_ReferenceArray,
209 StdLPersistent_Collection::referenceConverter>;
211 template class StdLPersistent_Collection::instance
212 <StdLPersistent_Collection::listBase,
213 StdLPersistent_Collection::integer,
214 TDataStd_IntegerList,
215 StdLPersistent_Collection::noConversion>;
217 template class StdLPersistent_Collection::instance
218 <StdLPersistent_Collection::listBase,
219 StdLPersistent_Collection::real,
221 StdLPersistent_Collection::noConversion>;
223 template class StdLPersistent_Collection::instance
224 <StdLPersistent_Collection::listBase,
225 StdLPersistent_Collection::integer,
226 TDataStd_BooleanList,
227 StdLPersistent_Collection::noConversion>;
229 template class StdLPersistent_Collection::instance
230 <StdLPersistent_Collection::listBase,
231 StdLPersistent_Collection::persistent,
232 TDataStd_ExtStringList,
233 StdLPersistent_Collection::stringConverter>;
235 template class StdLPersistent_Collection::instance
236 <StdLPersistent_Collection::listBase,
237 StdLPersistent_Collection::persistent,
238 TDataStd_ReferenceList,
239 StdLPersistent_Collection::referenceConverter>;
241 template class StdLPersistent_Collection::instance
242 <StdLPersistent_Collection::mapBase,
243 StdLPersistent_Collection::integer,
244 TDataStd_IntPackedMap,
245 StdLPersistent_Collection::noConversion>;
247 template class StdLPersistent_Collection::instance_1
248 <StdLPersistent_Collection::IntegerArray>;
250 template class StdLPersistent_Collection::instance_1
251 <StdLPersistent_Collection::RealArray>;
253 template class StdLPersistent_Collection::instance_1
254 <StdLPersistent_Collection::ByteArray>;
256 template class StdLPersistent_Collection::instance_1
257 <StdLPersistent_Collection::ExtStringArray>;
259 template class StdLPersistent_Collection::instance_1
260 <StdLPersistent_Collection::IntPackedMap>;