b311480e |
1 | // Created on: 2007-05-29 |
2 | // Created by: Vlad Romashko |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
bc73b006 |
16 | #include <TDataStd_ExtStringList.hxx> |
42cf5bc1 |
17 | |
bc73b006 |
18 | #include <Standard_Dump.hxx> |
42cf5bc1 |
19 | #include <Standard_GUID.hxx> |
20 | #include <Standard_Type.hxx> |
21 | #include <TCollection_ExtendedString.hxx> |
7fd59977 |
22 | #include <TDataStd_ListIteratorOfListOfExtendedString.hxx> |
42cf5bc1 |
23 | #include <TDF_Attribute.hxx> |
24 | #include <TDF_Label.hxx> |
25 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_ExtStringList,TDF_Attribute) |
28 | |
7fd59977 |
29 | //======================================================================= |
30 | //function : GetID |
31 | //purpose : |
32 | //======================================================================= |
33 | const Standard_GUID& TDataStd_ExtStringList::GetID() |
34 | { |
35 | static Standard_GUID TDataStd_ExtStringListID ("D13FBE0A-E084-4912-A99D-7713C59C0AC4"); |
36 | return TDataStd_ExtStringListID; |
37 | } |
38 | |
39 | //======================================================================= |
5a1271c8 |
40 | //function : SetAttr |
41 | //purpose : Implements Set functionality |
7fd59977 |
42 | //======================================================================= |
5a1271c8 |
43 | static Handle(TDataStd_ExtStringList) SetAttr(const TDF_Label& label, |
44 | const Standard_GUID& theGuid) |
7fd59977 |
45 | { |
5a1271c8 |
46 | Handle(TDataStd_ExtStringList) A; |
47 | if (!label.FindAttribute (theGuid, A)) |
48 | { |
49 | A = new TDataStd_ExtStringList; |
50 | A->SetID(theGuid); |
51 | label.AddAttribute(A); |
52 | } |
53 | return A; |
7fd59977 |
54 | } |
55 | |
5a1271c8 |
56 | //======================================================================= |
57 | //function : TDataStd_ExtStringList |
58 | //purpose : Empty Constructor |
59 | //======================================================================= |
4a5eefb9 |
60 | TDataStd_ExtStringList::TDataStd_ExtStringList() : myID(GetID()) |
5a1271c8 |
61 | {} |
62 | |
7fd59977 |
63 | //======================================================================= |
64 | //function : Set |
65 | //purpose : |
66 | //======================================================================= |
67 | Handle(TDataStd_ExtStringList) TDataStd_ExtStringList::Set(const TDF_Label& label) |
68 | { |
5a1271c8 |
69 | return SetAttr(label, GetID()); |
70 | } |
71 | |
72 | //======================================================================= |
73 | //function : Set |
74 | //purpose : Set user defined attribute with specific ID |
75 | //======================================================================= |
76 | Handle(TDataStd_ExtStringList) TDataStd_ExtStringList::Set(const TDF_Label& label, |
77 | const Standard_GUID& theGuid) |
78 | { |
79 | return SetAttr(label, theGuid); |
7fd59977 |
80 | } |
81 | |
82 | //======================================================================= |
83 | //function : IsEmpty |
84 | //purpose : |
85 | //======================================================================= |
86 | Standard_Boolean TDataStd_ExtStringList::IsEmpty() const |
87 | { |
88 | return myList.IsEmpty(); |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : Extent |
93 | //purpose : |
94 | //======================================================================= |
95 | Standard_Integer TDataStd_ExtStringList::Extent() const |
96 | { |
97 | return myList.Extent(); |
98 | } |
99 | |
100 | //======================================================================= |
101 | //function : Prepend |
102 | //purpose : |
103 | //======================================================================= |
104 | void TDataStd_ExtStringList::Prepend(const TCollection_ExtendedString& value) |
105 | { |
106 | Backup(); |
107 | myList.Prepend(value); |
108 | } |
109 | |
110 | //======================================================================= |
111 | //function : Append |
112 | //purpose : |
113 | //======================================================================= |
114 | void TDataStd_ExtStringList::Append(const TCollection_ExtendedString& value) |
115 | { |
116 | Backup(); |
117 | myList.Append(value); |
118 | } |
119 | |
120 | //======================================================================= |
121 | //function : InsertBefore |
122 | //purpose : |
123 | //======================================================================= |
124 | Standard_Boolean TDataStd_ExtStringList::InsertBefore(const TCollection_ExtendedString& value, |
5a1271c8 |
125 | const TCollection_ExtendedString& before_value) |
7fd59977 |
126 | { |
127 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
128 | for (; itr.More(); itr.Next()) |
129 | { |
130 | if (itr.Value() == before_value) |
131 | { |
132 | Backup(); |
133 | myList.InsertBefore(value, itr); |
134 | return Standard_True; |
135 | } |
136 | } |
137 | return Standard_False; |
138 | } |
139 | |
1ff07227 |
140 | //======================================================================= |
141 | //function : InsertBefore |
142 | //purpose : Inserts the <value> before the <index> position. |
143 | //======================================================================= |
144 | Standard_Boolean TDataStd_ExtStringList::InsertBefore(const Standard_Integer index, |
145 | const TCollection_ExtendedString& before_value) |
146 | { |
147 | Standard_Integer i(1); |
148 | Standard_Boolean found(Standard_False); |
149 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
150 | for (; itr.More(); itr.Next(), ++i) |
151 | { |
152 | if (i == index) |
153 | { |
154 | Backup(); |
155 | myList.InsertBefore(before_value, itr); |
156 | found = Standard_True; |
157 | break; |
158 | } |
159 | } |
160 | return found; |
161 | } |
162 | |
7fd59977 |
163 | //======================================================================= |
164 | //function : InsertAfter |
165 | //purpose : |
166 | //======================================================================= |
167 | Standard_Boolean TDataStd_ExtStringList::InsertAfter(const TCollection_ExtendedString& value, |
5a1271c8 |
168 | const TCollection_ExtendedString& after_value) |
7fd59977 |
169 | { |
170 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
171 | for (; itr.More(); itr.Next()) |
172 | { |
173 | if (itr.Value() == after_value) |
174 | { |
175 | Backup(); |
176 | myList.InsertAfter(value, itr); |
177 | return Standard_True; |
178 | } |
179 | } |
180 | return Standard_False; |
181 | } |
182 | |
1ff07227 |
183 | //======================================================================= |
184 | //function : InsertAfter |
185 | //purpose : Inserts the <value> after the <index> position. |
186 | //======================================================================= |
187 | Standard_Boolean TDataStd_ExtStringList::InsertAfter(const Standard_Integer index, |
188 | const TCollection_ExtendedString& after_value) |
189 | { |
190 | Standard_Integer i(1); |
191 | Standard_Boolean found(Standard_False); |
192 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
193 | for (; itr.More(); itr.Next(), ++i) |
194 | { |
195 | if (i == index) |
196 | { |
197 | Backup(); |
198 | myList.InsertAfter(after_value, itr); |
199 | found = Standard_True; |
200 | break; |
201 | } |
202 | } |
203 | return found; |
204 | } |
205 | |
7fd59977 |
206 | //======================================================================= |
207 | //function : Remove |
208 | //purpose : |
209 | //======================================================================= |
210 | Standard_Boolean TDataStd_ExtStringList::Remove(const TCollection_ExtendedString& value) |
211 | { |
212 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
213 | for (; itr.More(); itr.Next()) |
214 | { |
215 | if (itr.Value() == value) |
216 | { |
217 | Backup(); |
218 | myList.Remove(itr); |
219 | return Standard_True; |
220 | } |
221 | } |
222 | return Standard_False; |
223 | } |
224 | |
1ff07227 |
225 | //======================================================================= |
226 | //function : Remove |
227 | //purpose : Removes a value at <index> position. |
228 | //======================================================================= |
229 | Standard_Boolean TDataStd_ExtStringList::Remove(const Standard_Integer index) |
230 | { |
231 | Standard_Integer i(1); |
232 | Standard_Boolean found(Standard_False); |
233 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
234 | for (; itr.More(); itr.Next(), ++i) |
235 | { |
236 | if (index == i) |
237 | { |
238 | Backup(); |
239 | myList.Remove(itr); |
240 | found = Standard_True; |
241 | break; |
242 | } |
243 | } |
244 | return found; |
245 | } |
246 | |
7fd59977 |
247 | //======================================================================= |
248 | //function : Clear |
249 | //purpose : |
250 | //======================================================================= |
251 | void TDataStd_ExtStringList::Clear() |
252 | { |
253 | Backup(); |
254 | myList.Clear(); |
255 | } |
256 | |
257 | //======================================================================= |
258 | //function : First |
259 | //purpose : |
260 | //======================================================================= |
261 | const TCollection_ExtendedString& TDataStd_ExtStringList::First() const |
262 | { |
263 | return myList.First(); |
264 | } |
265 | |
266 | //======================================================================= |
267 | //function : Last |
268 | //purpose : |
269 | //======================================================================= |
270 | const TCollection_ExtendedString& TDataStd_ExtStringList::Last() const |
271 | { |
272 | return myList.Last(); |
273 | } |
274 | |
275 | //======================================================================= |
276 | //function : List |
277 | //purpose : |
278 | //======================================================================= |
279 | const TDataStd_ListOfExtendedString& TDataStd_ExtStringList::List() const |
280 | { |
281 | return myList; |
282 | } |
283 | |
284 | //======================================================================= |
285 | //function : ID |
286 | //purpose : |
287 | //======================================================================= |
288 | const Standard_GUID& TDataStd_ExtStringList::ID () const |
289 | { |
5a1271c8 |
290 | return myID; |
291 | } |
292 | |
293 | //======================================================================= |
294 | //function : SetID |
295 | //purpose : |
296 | //======================================================================= |
297 | |
298 | void TDataStd_ExtStringList::SetID( const Standard_GUID& theGuid) |
299 | { |
300 | if(myID == theGuid) return; |
301 | Backup(); |
302 | myID = theGuid; |
7fd59977 |
303 | } |
304 | |
5a1271c8 |
305 | //======================================================================= |
306 | //function : SetID |
307 | //purpose : sets default ID |
308 | //======================================================================= |
309 | |
310 | void TDataStd_ExtStringList::SetID() |
311 | { |
312 | Backup(); |
313 | myID = GetID(); |
314 | } |
7fd59977 |
315 | //======================================================================= |
316 | //function : NewEmpty |
317 | //purpose : |
318 | //======================================================================= |
319 | Handle(TDF_Attribute) TDataStd_ExtStringList::NewEmpty () const |
320 | { |
321 | return new TDataStd_ExtStringList(); |
322 | } |
323 | |
324 | //======================================================================= |
325 | //function : Restore |
326 | //purpose : |
327 | //======================================================================= |
328 | void TDataStd_ExtStringList::Restore(const Handle(TDF_Attribute)& With) |
329 | { |
330 | myList.Clear(); |
331 | Handle(TDataStd_ExtStringList) aList = Handle(TDataStd_ExtStringList)::DownCast(With); |
332 | TDataStd_ListIteratorOfListOfExtendedString itr(aList->List()); |
333 | for (; itr.More(); itr.Next()) |
334 | { |
335 | myList.Append(itr.Value()); |
336 | } |
5a1271c8 |
337 | myID = aList->ID(); |
7fd59977 |
338 | } |
339 | |
340 | //======================================================================= |
341 | //function : Paste |
342 | //purpose : |
343 | //======================================================================= |
344 | void TDataStd_ExtStringList::Paste (const Handle(TDF_Attribute)& Into, |
5a1271c8 |
345 | const Handle(TDF_RelocationTable)& ) const |
7fd59977 |
346 | { |
347 | Handle(TDataStd_ExtStringList) aList = Handle(TDataStd_ExtStringList)::DownCast(Into); |
348 | aList->Clear(); |
349 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
350 | for (; itr.More(); itr.Next()) |
351 | { |
352 | aList->Append(itr.Value()); |
353 | } |
5a1271c8 |
354 | aList->SetID(myID); |
7fd59977 |
355 | } |
356 | |
357 | //======================================================================= |
358 | //function : Dump |
359 | //purpose : |
360 | //======================================================================= |
361 | Standard_OStream& TDataStd_ExtStringList::Dump (Standard_OStream& anOS) const |
362 | { |
5a1271c8 |
363 | anOS << "\nExtStringList: "; |
364 | Standard_Character sguid[Standard_GUID_SIZE_ALLOC]; |
365 | myID.ToCString(sguid); |
366 | anOS << sguid; |
04232180 |
367 | anOS << std::endl; |
7fd59977 |
368 | return anOS; |
369 | } |
bc73b006 |
370 | |
371 | //======================================================================= |
372 | //function : DumpJson |
373 | //purpose : |
374 | //======================================================================= |
375 | void TDataStd_ExtStringList::DumpJson (Standard_OStream& theOStream, Standard_Integer /*theDepth*/) const |
376 | { |
377 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
378 | |
379 | for (TDataStd_ListOfExtendedString::Iterator aListIt (myList); aListIt.More(); aListIt.Next()) |
380 | { |
381 | const TCollection_ExtendedString& aValue = aListIt.Value(); |
382 | OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aValue); |
383 | } |
384 | |
385 | OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID) |
386 | } |