0027970: Improvement of standard attributes usability - containers.
[occt.git] / src / TDataStd / TDataStd_IntegerList.cxx
CommitLineData
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_ListIteratorOfListOfInteger.hxx>
42cf5bc1 20#include <TDataStd_IntegerList.hxx>
21#include <TDF_Attribute.hxx>
22#include <TDF_Label.hxx>
23#include <TDF_RelocationTable.hxx>
7fd59977 24
92efcf78 25IMPLEMENT_STANDARD_RTTIEXT(TDataStd_IntegerList,TDF_Attribute)
26
7fd59977 27//=======================================================================
28//function : GetID
29//purpose :
30//=======================================================================
31const Standard_GUID& TDataStd_IntegerList::GetID()
32{
33 static Standard_GUID TDataStd_IntegerListID ("E406AA18-FF3F-483b-9A78-1A5EA5D1AA52");
34 return TDataStd_IntegerListID;
35}
36
5a1271c8 37//=======================================================================
38//function : SetAttr
39//purpose : Implements Set functionality
40//=======================================================================
41static Handle(TDataStd_IntegerList) SetAttr(const TDF_Label& label,
42 const Standard_GUID& theGuid)
43{
44 Handle(TDataStd_IntegerList) A;
45 if (!label.FindAttribute (theGuid, A))
46 {
47 A = new TDataStd_IntegerList;
48 A->SetID(theGuid);
49 label.AddAttribute(A);
50 }
51 return A;
52}
53
7fd59977 54//=======================================================================
55//function : TDataStd_IntegerList
56//purpose : Empty Constructor
57//=======================================================================
58TDataStd_IntegerList::TDataStd_IntegerList()
59{
60
61}
62
63//=======================================================================
64//function : Set
65//purpose :
66//=======================================================================
67Handle(TDataStd_IntegerList) TDataStd_IntegerList::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//=======================================================================
76Handle(TDataStd_IntegerList) TDataStd_IntegerList::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//=======================================================================
86Standard_Boolean TDataStd_IntegerList::IsEmpty() const
87{
88 return myList.IsEmpty();
89}
90
91//=======================================================================
92//function : Extent
93//purpose :
94//=======================================================================
95Standard_Integer TDataStd_IntegerList::Extent() const
96{
97 return myList.Extent();
98}
99
100//=======================================================================
101//function : Prepend
102//purpose :
103//=======================================================================
104void TDataStd_IntegerList::Prepend(const Standard_Integer value)
105{
106 Backup();
107 myList.Prepend(value);
108}
109
110//=======================================================================
111//function : Append
112//purpose :
113//=======================================================================
114void TDataStd_IntegerList::Append(const Standard_Integer value)
115{
116 Backup();
117 myList.Append(value);
118}
119
120//=======================================================================
121//function : InsertBefore
122//purpose :
123//=======================================================================
124Standard_Boolean TDataStd_IntegerList::InsertBefore(const Standard_Integer value,
5a1271c8 125 const Standard_Integer before_value)
7fd59977 126{
127 TColStd_ListIteratorOfListOfInteger 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// Inserts the <value> before the <index> position.
141// The indices start with 1 .. Extent().
142Standard_Boolean TDataStd_IntegerList::InsertBeforeByIndex (const Standard_Integer index,
143 const Standard_Integer before_value)
144{
145 Standard_Integer i(1);
146 Standard_Boolean found(Standard_False);
147 TColStd_ListIteratorOfListOfInteger itr(myList);
148 for (; itr.More(); itr.Next(), ++i)
149 {
150 if (i == index)
151 {
152 Backup();
153 myList.InsertBefore(before_value, itr);
154 found = Standard_True;
155 break;
156 }
157 }
158 return found;
159}
160
7fd59977 161//=======================================================================
162//function : InsertAfter
163//purpose :
164//=======================================================================
165Standard_Boolean TDataStd_IntegerList::InsertAfter(const Standard_Integer value,
5a1271c8 166 const Standard_Integer after_value)
7fd59977 167{
168 TColStd_ListIteratorOfListOfInteger itr(myList);
169 for (; itr.More(); itr.Next())
170 {
171 if (itr.Value() == after_value)
172 {
173 Backup();
174 myList.InsertAfter(value, itr);
175 return Standard_True;
176 }
177 }
178 return Standard_False;
179}
1ff07227 180
181// Inserts the <value> after the <index> position.
182// The indices start with 1 .. Extent().
183Standard_Boolean TDataStd_IntegerList::InsertAfterByIndex (const Standard_Integer index,
184 const Standard_Integer after_value)
185{
186 Standard_Integer i(1);
187 Standard_Boolean found(Standard_False);
188 TColStd_ListIteratorOfListOfInteger itr(myList);
189 for (; itr.More(); itr.Next(), ++i)
190 {
191 if (i == index)
192 {
193 Backup();
194 myList.InsertAfter(after_value, itr);
195 found = Standard_True;
196 break;
197 }
198 }
199 return found;
200}
7fd59977 201
202//=======================================================================
203//function : Remove
204//purpose :
205//=======================================================================
206Standard_Boolean TDataStd_IntegerList::Remove(const Standard_Integer value)
207{
208 TColStd_ListIteratorOfListOfInteger itr(myList);
209 for (; itr.More(); itr.Next())
210 {
211 if (itr.Value() == value)
212 {
213 Backup();
214 myList.Remove(itr);
215 return Standard_True;
216 }
217 }
218 return Standard_False;
219}
220
1ff07227 221//=======================================================================
222//function : Remove
223//purpose : Removes the <value> at the <index> position.
224//=======================================================================
225Standard_Boolean TDataStd_IntegerList::RemoveByIndex (const Standard_Integer index)
226{
227 Standard_Integer i(1);
228 Standard_Boolean found(Standard_False);
229 TColStd_ListIteratorOfListOfInteger itr(myList);
230 for (; itr.More(); itr.Next(), ++i)
231 {
232 if (i == index)
233 {
234 Backup();
235 myList.Remove(itr);
236 found = Standard_True;
237 break;
238 }
239 }
240 return found;
241}
242
7fd59977 243//=======================================================================
244//function : Clear
245//purpose :
246//=======================================================================
247void TDataStd_IntegerList::Clear()
248{
249 Backup();
250 myList.Clear();
251}
252
253//=======================================================================
254//function : First
255//purpose :
256//=======================================================================
257Standard_Integer TDataStd_IntegerList::First() const
258{
259 return myList.First();
260}
261
262//=======================================================================
263//function : Last
264//purpose :
265//=======================================================================
266Standard_Integer TDataStd_IntegerList::Last() const
267{
268 return myList.Last();
269}
270
271//=======================================================================
272//function : List
273//purpose :
274//=======================================================================
275const TColStd_ListOfInteger& TDataStd_IntegerList::List() const
276{
277 return myList;
278}
279
280//=======================================================================
281//function : ID
282//purpose :
283//=======================================================================
284const Standard_GUID& TDataStd_IntegerList::ID () const
285{
5a1271c8 286 return myID;
287}
288
289//=======================================================================
290//function : SetID
291//purpose :
292//=======================================================================
293
294void TDataStd_IntegerList::SetID( const Standard_GUID& theGuid)
295{
296 if(myID == theGuid) return;
297 Backup();
298 myID = theGuid;
299}
300
301//=======================================================================
302//function : SetID
303//purpose : sets default ID
304//=======================================================================
305
306void TDataStd_IntegerList::SetID()
307{
308 Backup();
309 myID = GetID();
7fd59977 310}
311
312//=======================================================================
313//function : NewEmpty
314//purpose :
315//=======================================================================
316Handle(TDF_Attribute) TDataStd_IntegerList::NewEmpty () const
317{
318 return new TDataStd_IntegerList();
319}
320
321//=======================================================================
322//function : Restore
323//purpose :
324//=======================================================================
325void TDataStd_IntegerList::Restore(const Handle(TDF_Attribute)& With)
326{
327 myList.Clear();
328 Handle(TDataStd_IntegerList) aList = Handle(TDataStd_IntegerList)::DownCast(With);
329 TColStd_ListIteratorOfListOfInteger itr(aList->List());
330 for (; itr.More(); itr.Next())
331 {
332 myList.Append(itr.Value());
333 }
5a1271c8 334 myID = aList->ID();
7fd59977 335}
336
337//=======================================================================
338//function : Paste
339//purpose :
340//=======================================================================
341void TDataStd_IntegerList::Paste (const Handle(TDF_Attribute)& Into,
5a1271c8 342 const Handle(TDF_RelocationTable)& ) const
7fd59977 343{
344 Handle(TDataStd_IntegerList) aList = Handle(TDataStd_IntegerList)::DownCast(Into);
345 aList->Clear();
346 TColStd_ListIteratorOfListOfInteger itr(myList);
347 for (; itr.More(); itr.Next())
348 {
349 aList->Append(itr.Value());
350 }
5a1271c8 351 aList->SetID(myID);
7fd59977 352}
353
354//=======================================================================
355//function : Dump
356//purpose :
357//=======================================================================
358Standard_OStream& TDataStd_IntegerList::Dump (Standard_OStream& anOS) const
359{
5a1271c8 360 anOS << "\nIntegerList: ";
361 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
362 myID.ToCString(sguid);
363 anOS << sguid;
364 anOS << endl;
7fd59977 365 return anOS;
366}