0027277: geom/extruded_00/A0: OCAF document is not opened correctly
[occt.git] / src / StdLPersistent / StdLPersistent_Collection.cxx
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
20 struct 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
28 struct 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
36 struct StdLPersistent_Collection::stringConverter
37 {
38   stringConverter (const Handle(TDF_Data)&) {}
39
40   const TCollection_ExtendedString& operator()
41     (const Handle(StdObjMgt_Persistent)& theValue) const
42   {
43     static TCollection_ExtendedString anEmptyString;
44     if (theValue.IsNull())
45       return anEmptyString;
46
47     Handle(TCollection_HExtendedString) aString = theValue->ExtString();
48     return aString ? aString->String() : anEmptyString;
49   }
50 };
51
52 struct StdLPersistent_Collection::referenceConverter
53 {
54   referenceConverter (const Handle(TDF_Data)& theDF) : myDF (theDF) {}
55
56   TDF_Label operator() (const Handle(StdObjMgt_Persistent)& theValue) const
57     { return theValue->Label (myDF); }
58
59 private:
60   Handle(TDF_Data) myDF;
61 };
62
63 //=======================================================================
64 //function : Read
65 //purpose  : Read persistent data from a file
66 //=======================================================================
67 template <class Base>
68 void StdLPersistent_Collection::booleanArrayBase<Base>::Read
69   (StdObjMgt_ReadData& theReadData)
70 {
71   Base::Read (theReadData);
72   theReadData >> myLower >> myUpper;
73 }
74
75 template <class Base>
76 template <class ArrayHandle, class Converter>
77 void StdLPersistent_Collection::booleanArrayBase<Base>::import
78   (const ArrayHandle& theArray, Converter theConverter) const
79 {
80   Handle(TColStd_HArray1OfByte) aByteArray =
81     new TColStd_HArray1OfByte (theArray->Lower(), theArray->Upper());
82
83   for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
84     aByteArray->SetValue (i, theConverter (theArray->Value(i)));
85
86   this->myTransient->Init (myLower, myUpper);
87   this->myTransient->SetInternalArray (aByteArray);
88 }
89
90 template <class Base>
91 template <class ArrayHandle, class Converter>
92 void StdLPersistent_Collection::directArrayBase<Base>::import
93   (const ArrayHandle& theArray, Converter) const
94 {
95   this->myTransient->ChangeArray (theArray);
96 }
97
98 template <class Base>
99 template <class ArrayHandle, class Converter>
100 void StdLPersistent_Collection::arrayBase<Base>::import
101   (const ArrayHandle& theArray, Converter theConverter) const
102 {
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)));
106 }
107
108 template <class Base>
109 template <class ArrayHandle, class Converter>
110 void StdLPersistent_Collection::listBase<Base>::import
111   (const ArrayHandle& theArray, Converter theConverter) const
112 {
113   for (Standard_Integer i = theArray->Lower(); i <= theArray->Upper(); i++)
114     this->myTransient->Append (theConverter (theArray->Value(i)));
115 }
116
117 template <class Base>
118 template <class ArrayHandle, class Converter>
119 void StdLPersistent_Collection::mapBase<Base>::import
120   (const ArrayHandle& theArray, Converter theConverter) const
121 {
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);
126 }
127
128 //=======================================================================
129 //function : ImportAttribute
130 //purpose  : Import transient attribuite from the persistent data
131 //=======================================================================
132 template <template<class> class BaseT,
133           class HArrayClass,
134           class AttribClass,
135           class Converter>
136 void StdLPersistent_Collection::
137        instance<BaseT, HArrayClass, AttribClass, Converter>::ImportAttribute()
138 {
139   Handle(HArrayClass) anHArray = Handle(HArrayClass)::DownCast (this->myData);
140   if (anHArray)
141   {
142     typename HArrayClass::ArrayHandle anArray = anHArray->Array();
143     if (anArray)
144       this->import (anArray, Converter (this->myTransient->Label().Data()));
145     this->myData.Nullify();
146   }
147 }
148
149 //=======================================================================
150 //function : Read
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)
156 {
157   Instance::Read (theReadData);
158   theReadData >> myDelta;
159 }
160
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()
167 {
168   Instance::ImportAttribute();
169   this->myTransient->SetDelta (myDelta);
170 }
171
172
173 template class StdLPersistent_Collection::instance
174   <StdLPersistent_Collection::booleanArrayBase,
175    StdLPersistent_Collection::integer,
176    TDataStd_BooleanArray,
177    StdLPersistent_Collection::byteConverter>;
178
179 template class StdLPersistent_Collection::instance
180   <StdLPersistent_Collection::directArrayBase,
181    StdLPersistent_Collection::integer,
182    TDataStd_IntegerArray,
183    StdLPersistent_Collection::noConversion>;
184
185 template class StdLPersistent_Collection::instance
186   <StdLPersistent_Collection::directArrayBase,
187    StdLPersistent_Collection::real,
188    TDataStd_RealArray,
189    StdLPersistent_Collection::noConversion>;
190
191 template class StdLPersistent_Collection::instance
192   <StdLPersistent_Collection::arrayBase,
193    StdLPersistent_Collection::integer,
194    TDataStd_ByteArray,
195    StdLPersistent_Collection::byteConverter>;
196
197 template class StdLPersistent_Collection::instance
198   <StdLPersistent_Collection::arrayBase,
199    StdLPersistent_Collection::persistent,
200    TDataStd_ExtStringArray,
201    StdLPersistent_Collection::stringConverter>;
202
203 template class StdLPersistent_Collection::instance
204   <StdLPersistent_Collection::arrayBase,
205    StdLPersistent_Collection::persistent,
206    TDataStd_ReferenceArray,
207    StdLPersistent_Collection::referenceConverter>;
208
209 template class StdLPersistent_Collection::instance
210   <StdLPersistent_Collection::listBase,
211    StdLPersistent_Collection::integer,
212    TDataStd_IntegerList,
213    StdLPersistent_Collection::noConversion>;
214
215 template class StdLPersistent_Collection::instance
216   <StdLPersistent_Collection::listBase,
217    StdLPersistent_Collection::real,
218    TDataStd_RealList,
219    StdLPersistent_Collection::noConversion>;
220
221 template class StdLPersistent_Collection::instance
222   <StdLPersistent_Collection::listBase,
223    StdLPersistent_Collection::integer,
224    TDataStd_BooleanList,
225    StdLPersistent_Collection::noConversion>;
226
227 template class StdLPersistent_Collection::instance
228   <StdLPersistent_Collection::listBase,
229    StdLPersistent_Collection::persistent,
230    TDataStd_ExtStringList,
231    StdLPersistent_Collection::stringConverter>;
232
233 template class StdLPersistent_Collection::instance
234   <StdLPersistent_Collection::listBase,
235    StdLPersistent_Collection::persistent,
236    TDataStd_ReferenceList,
237    StdLPersistent_Collection::referenceConverter>;
238
239 template class StdLPersistent_Collection::instance
240   <StdLPersistent_Collection::mapBase,
241    StdLPersistent_Collection::integer,
242    TDataStd_IntPackedMap,
243    StdLPersistent_Collection::noConversion>;
244
245 template class StdLPersistent_Collection::instance_1
246   <StdLPersistent_Collection::IntegerArray>;
247
248 template class StdLPersistent_Collection::instance_1
249   <StdLPersistent_Collection::RealArray>;
250
251 template class StdLPersistent_Collection::instance_1
252   <StdLPersistent_Collection::ByteArray>;
253
254 template class StdLPersistent_Collection::instance_1
255   <StdLPersistent_Collection::ExtStringArray>;
256
257 template class StdLPersistent_Collection::instance_1
258   <StdLPersistent_Collection::IntPackedMap>;