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