0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / StdLPersistent / StdLPersistent_Collection.cxx
CommitLineData
ff205346 1// Copyright (c) 2015 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <StdLPersistent_Collection.hxx>
15
16#include <TColStd_HPackedMapOfInteger.hxx>
17#include <TCollection_HExtendedString.hxx>
18
19
20struct StdLPersistent_Collection::noConversion
21{
22 noConversion (const Handle(TDF_Data)&) {}
23
24 template <class Type>
25 Type operator() (Type theValue) const { return theValue; }
26};
27
28struct StdLPersistent_Collection::byteConverter
29{
30 byteConverter (const Handle(TDF_Data)&) {}
31
32 Standard_Byte operator() (Standard_Integer theValue) const
33 { return static_cast<Standard_Byte> (theValue); }
34};
35
dde68833 36struct StdLPersistent_Collection::boolConverter
37{
38 boolConverter (const Handle(TDF_Data)&) {}
39
40 Standard_Boolean operator() (Standard_Integer theValue) const
41 { return theValue != 0; }
42};
43
ff205346 44struct StdLPersistent_Collection::stringConverter
45{
46 stringConverter (const Handle(TDF_Data)&) {}
47
48 const TCollection_ExtendedString& operator()
49 (const Handle(StdObjMgt_Persistent)& theValue) const
50 {
12b86472 51 static TCollection_ExtendedString anEmptyString;
52 if (theValue.IsNull())
ff205346 53 return anEmptyString;
12b86472 54
55 Handle(TCollection_HExtendedString) aString = theValue->ExtString();
56 return aString ? aString->String() : anEmptyString;
ff205346 57 }
58};
59
60struct StdLPersistent_Collection::referenceConverter
61{
62 referenceConverter (const Handle(TDF_Data)& theDF) : myDF (theDF) {}
63
64 TDF_Label operator() (const Handle(StdObjMgt_Persistent)& theValue) const
65 { return theValue->Label (myDF); }
66
67private:
68 Handle(TDF_Data) myDF;
69};
70
71//=======================================================================
72//function : Read
73//purpose : Read persistent data from a file
74//=======================================================================
45d8465e 75template <class Base>
76void StdLPersistent_Collection::booleanArrayBase<Base>::Read
ff205346 77 (StdObjMgt_ReadData& theReadData)
78{
45d8465e 79 Base::Read (theReadData);
ff205346 80 theReadData >> myLower >> myUpper;
81}
82
45d8465e 83template <class Base>
ff205346 84template <class ArrayHandle, class Converter>
45d8465e 85void StdLPersistent_Collection::booleanArrayBase<Base>::import
ff205346 86 (const ArrayHandle& theArray, Converter theConverter) const
87{
88 Handle(TColStd_HArray1OfByte) aByteArray =
89 new TColStd_HArray1OfByte (theArray->Lower(), theArray->Upper());
90
91 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
92 aByteArray->SetValue (i, theConverter (theArray->Value(i)));
93
94 this->myTransient->Init (myLower, myUpper);
95 this->myTransient->SetInternalArray (aByteArray);
96}
97
45d8465e 98template <class Base>
ff205346 99template <class ArrayHandle, class Converter>
45d8465e 100void StdLPersistent_Collection::directArrayBase<Base>::import
ff205346 101 (const ArrayHandle& theArray, Converter) const
102{
103 this->myTransient->ChangeArray (theArray);
104}
105
45d8465e 106template <class Base>
ff205346 107template <class ArrayHandle, class Converter>
45d8465e 108void StdLPersistent_Collection::arrayBase<Base>::import
ff205346 109 (const ArrayHandle& theArray, Converter theConverter) const
110{
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)));
114}
115
45d8465e 116template <class Base>
ff205346 117template <class ArrayHandle, class Converter>
45d8465e 118void StdLPersistent_Collection::listBase<Base>::import
ff205346 119 (const ArrayHandle& theArray, Converter theConverter) const
120{
121 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
122 this->myTransient->Append (theConverter (theArray->Value(i)));
123}
124
45d8465e 125template <class Base>
ff205346 126template <class ArrayHandle, class Converter>
45d8465e 127void StdLPersistent_Collection::mapBase<Base>::import
ff205346 128 (const ArrayHandle& theArray, Converter theConverter) const
129{
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);
134}
135
136//=======================================================================
137//function : ImportAttribute
138//purpose : Import transient attribuite from the persistent data
139//=======================================================================
140template <template<class> class BaseT,
141 class HArrayClass,
142 class AttribClass,
143 class Converter>
144void StdLPersistent_Collection::
145 instance<BaseT, HArrayClass, AttribClass, Converter>::ImportAttribute()
146{
45d8465e 147 Handle(HArrayClass) anHArray = Handle(HArrayClass)::DownCast (this->myData);
148 if (anHArray)
ff205346 149 {
150 typename HArrayClass::ArrayHandle anArray = anHArray->Array();
151 if (anArray)
152 this->import (anArray, Converter (this->myTransient->Label().Data()));
153 this->myData.Nullify();
154 }
155}
156
157//=======================================================================
158//function : Read
159//purpose : Read persistent data from a file
160//=======================================================================
161template <class Instance>
162void StdLPersistent_Collection::instance_1<Instance>::Read
163 (StdObjMgt_ReadData& theReadData)
164{
165 Instance::Read (theReadData);
166 theReadData >> myDelta;
167}
168
169//=======================================================================
170//function : ImportAttribute
171//purpose : Import transient attribuite from the persistent data
172//=======================================================================
173template <class Instance>
174void StdLPersistent_Collection::instance_1<Instance>::ImportAttribute()
175{
176 Instance::ImportAttribute();
177 this->myTransient->SetDelta (myDelta);
178}
179
180
181template class StdLPersistent_Collection::instance
182 <StdLPersistent_Collection::booleanArrayBase,
183 StdLPersistent_Collection::integer,
184 TDataStd_BooleanArray,
185 StdLPersistent_Collection::byteConverter>;
186
187template class StdLPersistent_Collection::instance
188 <StdLPersistent_Collection::directArrayBase,
189 StdLPersistent_Collection::integer,
190 TDataStd_IntegerArray,
191 StdLPersistent_Collection::noConversion>;
192
193template class StdLPersistent_Collection::instance
194 <StdLPersistent_Collection::directArrayBase,
195 StdLPersistent_Collection::real,
196 TDataStd_RealArray,
197 StdLPersistent_Collection::noConversion>;
198
199template class StdLPersistent_Collection::instance
200 <StdLPersistent_Collection::arrayBase,
201 StdLPersistent_Collection::integer,
202 TDataStd_ByteArray,
203 StdLPersistent_Collection::byteConverter>;
204
205template class StdLPersistent_Collection::instance
206 <StdLPersistent_Collection::arrayBase,
207 StdLPersistent_Collection::persistent,
208 TDataStd_ExtStringArray,
209 StdLPersistent_Collection::stringConverter>;
210
211template class StdLPersistent_Collection::instance
212 <StdLPersistent_Collection::arrayBase,
213 StdLPersistent_Collection::persistent,
214 TDataStd_ReferenceArray,
215 StdLPersistent_Collection::referenceConverter>;
216
217template class StdLPersistent_Collection::instance
218 <StdLPersistent_Collection::listBase,
219 StdLPersistent_Collection::integer,
220 TDataStd_IntegerList,
221 StdLPersistent_Collection::noConversion>;
222
223template class StdLPersistent_Collection::instance
224 <StdLPersistent_Collection::listBase,
225 StdLPersistent_Collection::real,
226 TDataStd_RealList,
227 StdLPersistent_Collection::noConversion>;
228
229template class StdLPersistent_Collection::instance
230 <StdLPersistent_Collection::listBase,
231 StdLPersistent_Collection::integer,
232 TDataStd_BooleanList,
dde68833 233 StdLPersistent_Collection::boolConverter>;
ff205346 234
235template class StdLPersistent_Collection::instance
236 <StdLPersistent_Collection::listBase,
237 StdLPersistent_Collection::persistent,
238 TDataStd_ExtStringList,
239 StdLPersistent_Collection::stringConverter>;
240
241template class StdLPersistent_Collection::instance
242 <StdLPersistent_Collection::listBase,
243 StdLPersistent_Collection::persistent,
244 TDataStd_ReferenceList,
245 StdLPersistent_Collection::referenceConverter>;
246
247template class StdLPersistent_Collection::instance
248 <StdLPersistent_Collection::mapBase,
249 StdLPersistent_Collection::integer,
250 TDataStd_IntPackedMap,
251 StdLPersistent_Collection::noConversion>;
252
253template class StdLPersistent_Collection::instance_1
254 <StdLPersistent_Collection::IntegerArray>;
255
256template class StdLPersistent_Collection::instance_1
257 <StdLPersistent_Collection::RealArray>;
258
259template class StdLPersistent_Collection::instance_1
260 <StdLPersistent_Collection::ByteArray>;
261
262template class StdLPersistent_Collection::instance_1
263 <StdLPersistent_Collection::ExtStringArray>;
264
265template class StdLPersistent_Collection::instance_1
266 <StdLPersistent_Collection::IntPackedMap>;