0031939: Coding - correction of spelling errors in comments [part 10]
[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
45d8465e 71template <class Base>
ff205346 72template <class ArrayHandle, class Converter>
45d8465e 73void StdLPersistent_Collection::booleanArrayBase<Base>::import
ff205346 74 (const ArrayHandle& theArray, Converter theConverter) const
75{
76 Handle(TColStd_HArray1OfByte) aByteArray =
77 new TColStd_HArray1OfByte (theArray->Lower(), theArray->Upper());
78
79 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
80 aByteArray->SetValue (i, theConverter (theArray->Value(i)));
81
82 this->myTransient->Init (myLower, myUpper);
83 this->myTransient->SetInternalArray (aByteArray);
84}
85
45d8465e 86template <class Base>
ff205346 87template <class ArrayHandle, class Converter>
45d8465e 88void StdLPersistent_Collection::directArrayBase<Base>::import
ff205346 89 (const ArrayHandle& theArray, Converter) const
90{
91 this->myTransient->ChangeArray (theArray);
92}
93
45d8465e 94template <class Base>
ff205346 95template <class ArrayHandle, class Converter>
45d8465e 96void StdLPersistent_Collection::arrayBase<Base>::import
ff205346 97 (const ArrayHandle& theArray, Converter theConverter) const
98{
99 this->myTransient->Init (theArray->Lower(), theArray->Upper());
100 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
101 this->myTransient->SetValue (i, theConverter (theArray->Value(i)));
102}
103
45d8465e 104template <class Base>
ff205346 105template <class ArrayHandle, class Converter>
45d8465e 106void StdLPersistent_Collection::listBase<Base>::import
ff205346 107 (const ArrayHandle& theArray, Converter theConverter) const
108{
109 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
110 this->myTransient->Append (theConverter (theArray->Value(i)));
111}
112
45d8465e 113template <class Base>
ff205346 114template <class ArrayHandle, class Converter>
45d8465e 115void StdLPersistent_Collection::mapBase<Base>::import
ff205346 116 (const ArrayHandle& theArray, Converter theConverter) const
117{
118 Handle(TColStd_HPackedMapOfInteger) anHMap = new TColStd_HPackedMapOfInteger;
119 for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
120 anHMap->ChangeMap().Add (theConverter (theArray->Value(i)));
121 this->myTransient->ChangeMap (anHMap);
122}
123
124//=======================================================================
125//function : ImportAttribute
316ea293 126//purpose : Import transient attribute from the persistent data
ff205346 127//=======================================================================
128template <template<class> class BaseT,
129 class HArrayClass,
130 class AttribClass,
131 class Converter>
132void StdLPersistent_Collection::
133 instance<BaseT, HArrayClass, AttribClass, Converter>::ImportAttribute()
134{
45d8465e 135 Handle(HArrayClass) anHArray = Handle(HArrayClass)::DownCast (this->myData);
136 if (anHArray)
ff205346 137 {
138 typename HArrayClass::ArrayHandle anArray = anHArray->Array();
139 if (anArray)
140 this->import (anArray, Converter (this->myTransient->Label().Data()));
141 this->myData.Nullify();
142 }
143}
144
145//=======================================================================
146//function : Read
147//purpose : Read persistent data from a file
148//=======================================================================
149template <class Instance>
150void StdLPersistent_Collection::instance_1<Instance>::Read
151 (StdObjMgt_ReadData& theReadData)
152{
153 Instance::Read (theReadData);
154 theReadData >> myDelta;
155}
156
157//=======================================================================
158//function : ImportAttribute
316ea293 159//purpose : Import transient attribute from the persistent data
ff205346 160//=======================================================================
161template <class Instance>
162void StdLPersistent_Collection::instance_1<Instance>::ImportAttribute()
163{
164 Instance::ImportAttribute();
165 this->myTransient->SetDelta (myDelta);
166}
167
168
169template class StdLPersistent_Collection::instance
170 <StdLPersistent_Collection::booleanArrayBase,
171 StdLPersistent_Collection::integer,
172 TDataStd_BooleanArray,
173 StdLPersistent_Collection::byteConverter>;
174
175template class StdLPersistent_Collection::instance
176 <StdLPersistent_Collection::directArrayBase,
177 StdLPersistent_Collection::integer,
178 TDataStd_IntegerArray,
179 StdLPersistent_Collection::noConversion>;
180
181template class StdLPersistent_Collection::instance
182 <StdLPersistent_Collection::directArrayBase,
183 StdLPersistent_Collection::real,
184 TDataStd_RealArray,
185 StdLPersistent_Collection::noConversion>;
186
187template class StdLPersistent_Collection::instance
188 <StdLPersistent_Collection::arrayBase,
189 StdLPersistent_Collection::integer,
190 TDataStd_ByteArray,
191 StdLPersistent_Collection::byteConverter>;
192
193template class StdLPersistent_Collection::instance
194 <StdLPersistent_Collection::arrayBase,
195 StdLPersistent_Collection::persistent,
196 TDataStd_ExtStringArray,
197 StdLPersistent_Collection::stringConverter>;
198
199template class StdLPersistent_Collection::instance
200 <StdLPersistent_Collection::arrayBase,
201 StdLPersistent_Collection::persistent,
202 TDataStd_ReferenceArray,
203 StdLPersistent_Collection::referenceConverter>;
204
205template class StdLPersistent_Collection::instance
206 <StdLPersistent_Collection::listBase,
207 StdLPersistent_Collection::integer,
208 TDataStd_IntegerList,
209 StdLPersistent_Collection::noConversion>;
210
211template class StdLPersistent_Collection::instance
212 <StdLPersistent_Collection::listBase,
213 StdLPersistent_Collection::real,
214 TDataStd_RealList,
215 StdLPersistent_Collection::noConversion>;
216
217template class StdLPersistent_Collection::instance
218 <StdLPersistent_Collection::listBase,
219 StdLPersistent_Collection::integer,
220 TDataStd_BooleanList,
dde68833 221 StdLPersistent_Collection::boolConverter>;
ff205346 222
223template class StdLPersistent_Collection::instance
224 <StdLPersistent_Collection::listBase,
225 StdLPersistent_Collection::persistent,
226 TDataStd_ExtStringList,
227 StdLPersistent_Collection::stringConverter>;
228
229template class StdLPersistent_Collection::instance
230 <StdLPersistent_Collection::listBase,
231 StdLPersistent_Collection::persistent,
232 TDataStd_ReferenceList,
233 StdLPersistent_Collection::referenceConverter>;
234
235template class StdLPersistent_Collection::instance
236 <StdLPersistent_Collection::mapBase,
237 StdLPersistent_Collection::integer,
238 TDataStd_IntPackedMap,
239 StdLPersistent_Collection::noConversion>;
240
241template class StdLPersistent_Collection::instance_1
242 <StdLPersistent_Collection::IntegerArray>;
243
244template class StdLPersistent_Collection::instance_1
245 <StdLPersistent_Collection::RealArray>;
246
247template class StdLPersistent_Collection::instance_1
248 <StdLPersistent_Collection::ByteArray>;
249
250template class StdLPersistent_Collection::instance_1
251 <StdLPersistent_Collection::ExtStringArray>;
252
253template class StdLPersistent_Collection::instance_1
254 <StdLPersistent_Collection::IntPackedMap>;