b311480e |
1 | // Created on: 2007-07-02 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 2007-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | #include <BinMDataStd_NamedDataDriver.ixx> |
22 | #include <TCollection_ExtendedString.hxx> |
23 | #include <CDM_MessageDriver.hxx> |
24 | #include <TDataStd_NamedData.hxx> |
25 | #include <TColStd_HArray1OfReal.hxx> |
26 | #include <TColStd_HArray1OfInteger.hxx> |
27 | #include <TColStd_HArray1OfReal.hxx> |
28 | #include <TColStd_DataMapOfStringInteger.hxx> |
29 | #include <TDataStd_DataMapOfStringReal.hxx> |
30 | #include <TDataStd_DataMapOfStringString.hxx> |
31 | #include <TDataStd_DataMapOfStringByte.hxx> |
32 | #include <TDataStd_DataMapOfStringHArray1OfInteger.hxx> |
33 | #include <TDataStd_DataMapOfStringHArray1OfReal.hxx> |
34 | #include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx> |
35 | #include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx> |
36 | #include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx> |
37 | #include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx> |
38 | #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx> |
39 | #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx> |
40 | |
41 | |
42 | //======================================================================= |
43 | //function : BinMDataStd_NamedDataDriver |
44 | //purpose : Constructor |
45 | //======================================================================= |
46 | BinMDataStd_NamedDataDriver::BinMDataStd_NamedDataDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
47 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_NamedData)->Name()) |
48 | { |
49 | |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : NewEmpty |
3616fc06 |
54 | //purpose : |
7fd59977 |
55 | //======================================================================= |
56 | Handle(TDF_Attribute) BinMDataStd_NamedDataDriver::NewEmpty() const |
57 | { |
58 | return new TDataStd_NamedData(); |
59 | } |
60 | |
61 | //======================================================================= |
62 | //function : Paste |
63 | //purpose : persistent -> transient (retrieve) |
64 | //======================================================================= |
65 | Standard_Boolean BinMDataStd_NamedDataDriver::Paste(const BinObjMgt_Persistent& theSource, |
66 | const Handle(TDF_Attribute)& theTarget, |
67 | BinObjMgt_RRelocationTable& ) const |
68 | { |
69 | |
70 | Handle(TDataStd_NamedData) T = Handle(TDataStd_NamedData)::DownCast(theTarget); |
71 | if(T.IsNull()) return Standard_False; |
72 | Standard_Integer aLower, anUpper,i; |
73 | if (! (theSource >> aLower >> anUpper)) |
74 | return Standard_False; |
75 | // const Standard_Integer aLength = anUpper - aLower + 1; |
76 | if (anUpper < aLower) return Standard_False; |
77 | if(anUpper | aLower) { |
78 | TColStd_DataMapOfStringInteger anIntegers; |
79 | for (i=aLower; i<=anUpper; i++) { |
80 | TCollection_ExtendedString aKey; |
81 | Standard_Integer aValue; |
82 | if (! (theSource >> aKey >> aValue)) |
83 | return Standard_False; |
84 | anIntegers.Bind(aKey, aValue); |
85 | } |
86 | T->ChangeIntegers(anIntegers); |
87 | } |
88 | |
89 | if (! (theSource >> aLower >> anUpper)) |
90 | return Standard_False; |
91 | if (anUpper < aLower) return Standard_False; |
92 | if(anUpper | aLower) { |
93 | TDataStd_DataMapOfStringReal aReals; |
94 | for (i=aLower; i<=anUpper; i++) { |
95 | TCollection_ExtendedString aKey; |
96 | Standard_Real aValue; |
97 | if (! (theSource >> aKey >> aValue)) |
98 | return Standard_False; |
99 | aReals.Bind(aKey, aValue); |
100 | } |
101 | T->ChangeReals(aReals); |
102 | } |
103 | |
104 | // strings |
105 | if (! (theSource >> aLower >> anUpper)) |
106 | return Standard_False; |
107 | if (anUpper < aLower) return Standard_False; |
108 | if(anUpper | aLower) { |
109 | TDataStd_DataMapOfStringString aStrings; |
110 | for (i=aLower; i<=anUpper; i++) { |
111 | TCollection_ExtendedString aKey; |
112 | TCollection_ExtendedString aValue; |
113 | if (! (theSource >> aKey >> aValue)) |
114 | return Standard_False; |
115 | aStrings.Bind(aKey, aValue); |
116 | } |
117 | T->ChangeStrings(aStrings); |
118 | } |
119 | |
120 | //Bytes |
121 | if (! (theSource >> aLower >> anUpper)) |
122 | return Standard_False; |
123 | if (anUpper < aLower) return Standard_False; |
124 | if(anUpper | aLower) { |
125 | TDataStd_DataMapOfStringByte aBytes; |
126 | for (i=aLower; i<=anUpper; i++) { |
127 | TCollection_ExtendedString aKey; |
128 | Standard_Byte aValue; |
129 | if (! (theSource >> aKey >> aValue)) |
130 | return Standard_False; |
131 | aBytes.Bind(aKey, (Standard_Byte)aValue); |
132 | } |
133 | T->ChangeBytes(aBytes); |
134 | } |
135 | |
136 | // arrays of integers |
137 | if (! (theSource >> aLower >> anUpper)) |
138 | return Standard_False; |
139 | if (anUpper < aLower) return Standard_False; |
140 | Standard_Boolean aResult = Standard_False; |
141 | if(anUpper | aLower) { |
142 | TDataStd_DataMapOfStringHArray1OfInteger anIntArrays; |
143 | for (i=aLower; i<=anUpper; i++) { |
144 | TCollection_ExtendedString aKey; |
145 | if (! (theSource >> aKey)) |
146 | return Standard_False; |
147 | Standard_Integer low, up; |
148 | if (! (theSource >> low >> up)) |
149 | return Standard_False; |
150 | if(up < low) |
151 | return Standard_False; |
152 | if(up | low) { |
153 | Handle(TColStd_HArray1OfInteger) aTargetArray = new TColStd_HArray1OfInteger (low, up); |
154 | if(!theSource.GetIntArray (&(aTargetArray->ChangeArray1())(low), up-low+1)) |
155 | return Standard_False; |
3616fc06 |
156 | |
7fd59977 |
157 | Standard_Boolean Ok = anIntArrays.Bind(aKey, aTargetArray); |
158 | aResult |= Ok; |
159 | } |
160 | } |
3616fc06 |
161 | if (aResult) |
7fd59977 |
162 | T->ChangeArraysOfIntegers(anIntArrays); |
163 | } |
164 | |
165 | // arrays of reals |
166 | if (! (theSource >> aLower >> anUpper)) |
167 | return Standard_False; |
168 | if (anUpper < aLower) return Standard_False; |
169 | aResult = Standard_False; |
170 | if(anUpper | aLower) { |
171 | TDataStd_DataMapOfStringHArray1OfReal aRealArrays; |
172 | for (i=aLower; i<=anUpper; i++) { |
173 | TCollection_ExtendedString aKey; |
174 | if (! (theSource >> aKey)) |
175 | return Standard_False; |
176 | Standard_Integer low, up; |
177 | if (! (theSource >> low >> up)) |
178 | return Standard_False; |
3616fc06 |
179 | if (up < low) |
180 | return Standard_False; |
7fd59977 |
181 | if(low | up) { |
182 | Handle(TColStd_HArray1OfReal) aTargetArray = |
183 | new TColStd_HArray1OfReal(low, up); |
184 | if(!theSource.GetRealArray (&(aTargetArray->ChangeArray1())(low), up-low+1)) |
185 | return Standard_False; |
186 | Standard_Boolean Ok = aRealArrays.Bind(aKey, aTargetArray); |
187 | aResult |= Ok; |
188 | } |
189 | } |
190 | if(aResult) |
191 | T->ChangeArraysOfReals(aRealArrays); |
192 | } |
193 | return Standard_True; |
194 | } |
195 | |
196 | //======================================================================= |
197 | //function : Paste |
198 | //purpose : transient -> persistent (store) |
199 | //======================================================================= |
200 | void BinMDataStd_NamedDataDriver::Paste(const Handle(TDF_Attribute)& theSource, |
201 | BinObjMgt_Persistent& theTarget, |
202 | BinObjMgt_SRelocationTable& ) const |
203 | { |
204 | Handle(TDataStd_NamedData) S = Handle(TDataStd_NamedData)::DownCast (theSource); |
205 | if(S.IsNull()) return; |
206 | // Standard_Integer i=0; |
3616fc06 |
207 | |
7fd59977 |
208 | if(S->HasIntegers() && !S->GetIntegersContainer().IsEmpty()) { |
209 | theTarget.PutInteger(1) << S->GetIntegersContainer().Extent(); //dim |
210 | TColStd_DataMapIteratorOfDataMapOfStringInteger itr(S->GetIntegersContainer()); |
211 | for (; itr.More(); itr.Next()) { |
212 | theTarget << itr.Key() << itr.Value(); // key - value; |
213 | } |
214 | } else { |
215 | theTarget.PutInteger(0).PutInteger(0); |
216 | } |
3616fc06 |
217 | |
7fd59977 |
218 | if(S->HasReals() && !S->GetRealsContainer().IsEmpty()) { |
219 | theTarget.PutInteger(1) << S->GetRealsContainer().Extent(); |
220 | TDataStd_DataMapIteratorOfDataMapOfStringReal itr(S->GetRealsContainer()); |
221 | for (; itr.More(); itr.Next()) { |
222 | theTarget << itr.Key() << itr.Value(); |
223 | } |
224 | } else { |
225 | theTarget.PutInteger(0).PutInteger(0); |
226 | } |
227 | |
228 | if(S->HasStrings() && !S->GetStringsContainer().IsEmpty()) { |
229 | theTarget.PutInteger(1) << S->GetStringsContainer().Extent(); |
230 | TDataStd_DataMapIteratorOfDataMapOfStringString itr(S->GetStringsContainer()); |
231 | for (; itr.More(); itr.Next()) { |
232 | theTarget << itr.Key() << itr.Value(); |
233 | } |
234 | } else { |
235 | theTarget.PutInteger(0).PutInteger(0); |
236 | } |
237 | |
238 | if(S->HasBytes() && !S->GetBytesContainer().IsEmpty()) { |
239 | theTarget.PutInteger(1) << S->GetBytesContainer().Extent(); |
240 | TDataStd_DataMapIteratorOfDataMapOfStringByte itr(S->GetBytesContainer()); |
241 | for (; itr.More(); itr.Next()) { |
242 | theTarget << itr.Key() << (Standard_Byte) itr.Value(); |
243 | } |
244 | } else { |
245 | theTarget.PutInteger(0).PutInteger(0); |
246 | } |
247 | |
248 | if(S->HasArraysOfIntegers() && !S->GetArraysOfIntegersContainer().IsEmpty()) { |
249 | theTarget.PutInteger(1) << S->GetArraysOfIntegersContainer().Extent(); |
250 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger |
251 | itr(S->GetArraysOfIntegersContainer()); |
252 | for (; itr.More(); itr.Next()) { |
253 | theTarget << itr.Key(); //key |
254 | const TColStd_Array1OfInteger& anArr1 = itr.Value()->Array1(); |
255 | theTarget << anArr1.Lower() <<anArr1.Upper(); // value Arr1 dimensions |
256 | Standard_Integer *aPtr = (Standard_Integer *) &anArr1(anArr1.Lower()); |
257 | theTarget.PutIntArray(aPtr, anArr1.Length()); |
258 | } |
259 | } else { |
260 | theTarget.PutInteger(0).PutInteger(0); |
261 | } |
262 | |
263 | if(S->HasArraysOfReals() && !S->GetArraysOfRealsContainer().IsEmpty()) { |
264 | theTarget.PutInteger(1) << S->GetArraysOfRealsContainer().Extent(); //dim |
265 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal |
266 | itr(S->GetArraysOfRealsContainer()); |
267 | for (; itr.More(); itr.Next()) { |
268 | theTarget << itr.Key();//key |
269 | const TColStd_Array1OfReal& anArr1 = itr.Value()->Array1(); |
270 | theTarget << anArr1.Lower() <<anArr1.Upper(); // value Arr1 dimensions |
271 | Standard_Real *aPtr = (Standard_Real *) &anArr1(anArr1.Lower()); |
272 | theTarget.PutRealArray(aPtr, anArr1.Length()); |
273 | } |
274 | } else { |
275 | theTarget.PutInteger(0).PutInteger(0); |
276 | } |
277 | } |