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 | |
42cf5bc1 |
16 | |
17 | #include <Standard_GUID.hxx> |
18 | #include <Standard_Type.hxx> |
19 | #include <TCollection_ExtendedString.hxx> |
20 | #include <TDataStd_ExtStringList.hxx> |
7fd59977 |
21 | #include <TDataStd_ListIteratorOfListOfExtendedString.hxx> |
42cf5bc1 |
22 | #include <TDF_Attribute.hxx> |
23 | #include <TDF_Label.hxx> |
24 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_ExtStringList,TDF_Attribute) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : GetID |
30 | //purpose : |
31 | //======================================================================= |
32 | const Standard_GUID& TDataStd_ExtStringList::GetID() |
33 | { |
34 | static Standard_GUID TDataStd_ExtStringListID ("D13FBE0A-E084-4912-A99D-7713C59C0AC4"); |
35 | return TDataStd_ExtStringListID; |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : TDataStd_ExtStringList |
40 | //purpose : Empty Constructor |
41 | //======================================================================= |
42 | TDataStd_ExtStringList::TDataStd_ExtStringList() |
43 | { |
44 | |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Set |
49 | //purpose : |
50 | //======================================================================= |
51 | Handle(TDataStd_ExtStringList) TDataStd_ExtStringList::Set(const TDF_Label& label) |
52 | { |
53 | Handle(TDataStd_ExtStringList) A; |
54 | if (!label.FindAttribute (TDataStd_ExtStringList::GetID(), A)) |
55 | { |
56 | A = new TDataStd_ExtStringList; |
57 | label.AddAttribute(A); |
58 | } |
59 | return A; |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : IsEmpty |
64 | //purpose : |
65 | //======================================================================= |
66 | Standard_Boolean TDataStd_ExtStringList::IsEmpty() const |
67 | { |
68 | return myList.IsEmpty(); |
69 | } |
70 | |
71 | //======================================================================= |
72 | //function : Extent |
73 | //purpose : |
74 | //======================================================================= |
75 | Standard_Integer TDataStd_ExtStringList::Extent() const |
76 | { |
77 | return myList.Extent(); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : Prepend |
82 | //purpose : |
83 | //======================================================================= |
84 | void TDataStd_ExtStringList::Prepend(const TCollection_ExtendedString& value) |
85 | { |
86 | Backup(); |
87 | myList.Prepend(value); |
88 | } |
89 | |
90 | //======================================================================= |
91 | //function : Append |
92 | //purpose : |
93 | //======================================================================= |
94 | void TDataStd_ExtStringList::Append(const TCollection_ExtendedString& value) |
95 | { |
96 | Backup(); |
97 | myList.Append(value); |
98 | } |
99 | |
100 | //======================================================================= |
101 | //function : InsertBefore |
102 | //purpose : |
103 | //======================================================================= |
104 | Standard_Boolean TDataStd_ExtStringList::InsertBefore(const TCollection_ExtendedString& value, |
105 | const TCollection_ExtendedString& before_value) |
106 | { |
107 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
108 | for (; itr.More(); itr.Next()) |
109 | { |
110 | if (itr.Value() == before_value) |
111 | { |
112 | Backup(); |
113 | myList.InsertBefore(value, itr); |
114 | return Standard_True; |
115 | } |
116 | } |
117 | return Standard_False; |
118 | } |
119 | |
1ff07227 |
120 | //======================================================================= |
121 | //function : InsertBefore |
122 | //purpose : Inserts the <value> before the <index> position. |
123 | //======================================================================= |
124 | Standard_Boolean TDataStd_ExtStringList::InsertBefore(const Standard_Integer index, |
125 | const TCollection_ExtendedString& before_value) |
126 | { |
127 | Standard_Integer i(1); |
128 | Standard_Boolean found(Standard_False); |
129 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
130 | for (; itr.More(); itr.Next(), ++i) |
131 | { |
132 | if (i == index) |
133 | { |
134 | Backup(); |
135 | myList.InsertBefore(before_value, itr); |
136 | found = Standard_True; |
137 | break; |
138 | } |
139 | } |
140 | return found; |
141 | } |
142 | |
7fd59977 |
143 | //======================================================================= |
144 | //function : InsertAfter |
145 | //purpose : |
146 | //======================================================================= |
147 | Standard_Boolean TDataStd_ExtStringList::InsertAfter(const TCollection_ExtendedString& value, |
148 | const TCollection_ExtendedString& after_value) |
149 | { |
150 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
151 | for (; itr.More(); itr.Next()) |
152 | { |
153 | if (itr.Value() == after_value) |
154 | { |
155 | Backup(); |
156 | myList.InsertAfter(value, itr); |
157 | return Standard_True; |
158 | } |
159 | } |
160 | return Standard_False; |
161 | } |
162 | |
1ff07227 |
163 | //======================================================================= |
164 | //function : InsertAfter |
165 | //purpose : Inserts the <value> after the <index> position. |
166 | //======================================================================= |
167 | Standard_Boolean TDataStd_ExtStringList::InsertAfter(const Standard_Integer index, |
168 | const TCollection_ExtendedString& after_value) |
169 | { |
170 | Standard_Integer i(1); |
171 | Standard_Boolean found(Standard_False); |
172 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
173 | for (; itr.More(); itr.Next(), ++i) |
174 | { |
175 | if (i == index) |
176 | { |
177 | Backup(); |
178 | myList.InsertAfter(after_value, itr); |
179 | found = Standard_True; |
180 | break; |
181 | } |
182 | } |
183 | return found; |
184 | } |
185 | |
7fd59977 |
186 | //======================================================================= |
187 | //function : Remove |
188 | //purpose : |
189 | //======================================================================= |
190 | Standard_Boolean TDataStd_ExtStringList::Remove(const TCollection_ExtendedString& value) |
191 | { |
192 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
193 | for (; itr.More(); itr.Next()) |
194 | { |
195 | if (itr.Value() == value) |
196 | { |
197 | Backup(); |
198 | myList.Remove(itr); |
199 | return Standard_True; |
200 | } |
201 | } |
202 | return Standard_False; |
203 | } |
204 | |
1ff07227 |
205 | //======================================================================= |
206 | //function : Remove |
207 | //purpose : Removes a value at <index> position. |
208 | //======================================================================= |
209 | Standard_Boolean TDataStd_ExtStringList::Remove(const Standard_Integer index) |
210 | { |
211 | Standard_Integer i(1); |
212 | Standard_Boolean found(Standard_False); |
213 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
214 | for (; itr.More(); itr.Next(), ++i) |
215 | { |
216 | if (index == i) |
217 | { |
218 | Backup(); |
219 | myList.Remove(itr); |
220 | found = Standard_True; |
221 | break; |
222 | } |
223 | } |
224 | return found; |
225 | } |
226 | |
7fd59977 |
227 | //======================================================================= |
228 | //function : Clear |
229 | //purpose : |
230 | //======================================================================= |
231 | void TDataStd_ExtStringList::Clear() |
232 | { |
233 | Backup(); |
234 | myList.Clear(); |
235 | } |
236 | |
237 | //======================================================================= |
238 | //function : First |
239 | //purpose : |
240 | //======================================================================= |
241 | const TCollection_ExtendedString& TDataStd_ExtStringList::First() const |
242 | { |
243 | return myList.First(); |
244 | } |
245 | |
246 | //======================================================================= |
247 | //function : Last |
248 | //purpose : |
249 | //======================================================================= |
250 | const TCollection_ExtendedString& TDataStd_ExtStringList::Last() const |
251 | { |
252 | return myList.Last(); |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : List |
257 | //purpose : |
258 | //======================================================================= |
259 | const TDataStd_ListOfExtendedString& TDataStd_ExtStringList::List() const |
260 | { |
261 | return myList; |
262 | } |
263 | |
264 | //======================================================================= |
265 | //function : ID |
266 | //purpose : |
267 | //======================================================================= |
268 | const Standard_GUID& TDataStd_ExtStringList::ID () const |
269 | { |
270 | return GetID(); |
271 | } |
272 | |
273 | //======================================================================= |
274 | //function : NewEmpty |
275 | //purpose : |
276 | //======================================================================= |
277 | Handle(TDF_Attribute) TDataStd_ExtStringList::NewEmpty () const |
278 | { |
279 | return new TDataStd_ExtStringList(); |
280 | } |
281 | |
282 | //======================================================================= |
283 | //function : Restore |
284 | //purpose : |
285 | //======================================================================= |
286 | void TDataStd_ExtStringList::Restore(const Handle(TDF_Attribute)& With) |
287 | { |
288 | myList.Clear(); |
289 | Handle(TDataStd_ExtStringList) aList = Handle(TDataStd_ExtStringList)::DownCast(With); |
290 | TDataStd_ListIteratorOfListOfExtendedString itr(aList->List()); |
291 | for (; itr.More(); itr.Next()) |
292 | { |
293 | myList.Append(itr.Value()); |
294 | } |
295 | } |
296 | |
297 | //======================================================================= |
298 | //function : Paste |
299 | //purpose : |
300 | //======================================================================= |
301 | void TDataStd_ExtStringList::Paste (const Handle(TDF_Attribute)& Into, |
302 | const Handle(TDF_RelocationTable)& ) const |
303 | { |
304 | Handle(TDataStd_ExtStringList) aList = Handle(TDataStd_ExtStringList)::DownCast(Into); |
305 | aList->Clear(); |
306 | TDataStd_ListIteratorOfListOfExtendedString itr(myList); |
307 | for (; itr.More(); itr.Next()) |
308 | { |
309 | aList->Append(itr.Value()); |
310 | } |
311 | } |
312 | |
313 | //======================================================================= |
314 | //function : Dump |
315 | //purpose : |
316 | //======================================================================= |
317 | Standard_OStream& TDataStd_ExtStringList::Dump (Standard_OStream& anOS) const |
318 | { |
319 | anOS << "ExtStringList"; |
320 | return anOS; |
321 | } |