0029371: The problem of the attributes constructor call
[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//=======================================================================
4a5eefb9 58TDataStd_IntegerList::TDataStd_IntegerList() : myID(GetID())
59{}
7fd59977 60
61//=======================================================================
62//function : Set
63//purpose :
64//=======================================================================
65Handle(TDataStd_IntegerList) TDataStd_IntegerList::Set(const TDF_Label& label)
66{
5a1271c8 67 return SetAttr(label, GetID());
68}
69
70//=======================================================================
71//function : Set
72//purpose : Set user defined attribute with specific ID
73//=======================================================================
74Handle(TDataStd_IntegerList) TDataStd_IntegerList::Set(const TDF_Label& label,
75 const Standard_GUID& theGuid)
76{
77 return SetAttr(label, theGuid);
7fd59977 78}
79
80//=======================================================================
81//function : IsEmpty
82//purpose :
83//=======================================================================
84Standard_Boolean TDataStd_IntegerList::IsEmpty() const
85{
86 return myList.IsEmpty();
87}
88
89//=======================================================================
90//function : Extent
91//purpose :
92//=======================================================================
93Standard_Integer TDataStd_IntegerList::Extent() const
94{
95 return myList.Extent();
96}
97
98//=======================================================================
99//function : Prepend
100//purpose :
101//=======================================================================
102void TDataStd_IntegerList::Prepend(const Standard_Integer value)
103{
104 Backup();
105 myList.Prepend(value);
106}
107
108//=======================================================================
109//function : Append
110//purpose :
111//=======================================================================
112void TDataStd_IntegerList::Append(const Standard_Integer value)
113{
114 Backup();
115 myList.Append(value);
116}
117
118//=======================================================================
119//function : InsertBefore
120//purpose :
121//=======================================================================
122Standard_Boolean TDataStd_IntegerList::InsertBefore(const Standard_Integer value,
5a1271c8 123 const Standard_Integer before_value)
7fd59977 124{
125 TColStd_ListIteratorOfListOfInteger itr(myList);
126 for (; itr.More(); itr.Next())
127 {
128 if (itr.Value() == before_value)
129 {
130 Backup();
131 myList.InsertBefore(value, itr);
132 return Standard_True;
133 }
134 }
135 return Standard_False;
136}
137
1ff07227 138// Inserts the <value> before the <index> position.
139// The indices start with 1 .. Extent().
140Standard_Boolean TDataStd_IntegerList::InsertBeforeByIndex (const Standard_Integer index,
141 const Standard_Integer before_value)
142{
143 Standard_Integer i(1);
144 Standard_Boolean found(Standard_False);
145 TColStd_ListIteratorOfListOfInteger itr(myList);
146 for (; itr.More(); itr.Next(), ++i)
147 {
148 if (i == index)
149 {
150 Backup();
151 myList.InsertBefore(before_value, itr);
152 found = Standard_True;
153 break;
154 }
155 }
156 return found;
157}
158
7fd59977 159//=======================================================================
160//function : InsertAfter
161//purpose :
162//=======================================================================
163Standard_Boolean TDataStd_IntegerList::InsertAfter(const Standard_Integer value,
5a1271c8 164 const Standard_Integer after_value)
7fd59977 165{
166 TColStd_ListIteratorOfListOfInteger itr(myList);
167 for (; itr.More(); itr.Next())
168 {
169 if (itr.Value() == after_value)
170 {
171 Backup();
172 myList.InsertAfter(value, itr);
173 return Standard_True;
174 }
175 }
176 return Standard_False;
177}
1ff07227 178
179// Inserts the <value> after the <index> position.
180// The indices start with 1 .. Extent().
181Standard_Boolean TDataStd_IntegerList::InsertAfterByIndex (const Standard_Integer index,
182 const Standard_Integer after_value)
183{
184 Standard_Integer i(1);
185 Standard_Boolean found(Standard_False);
186 TColStd_ListIteratorOfListOfInteger itr(myList);
187 for (; itr.More(); itr.Next(), ++i)
188 {
189 if (i == index)
190 {
191 Backup();
192 myList.InsertAfter(after_value, itr);
193 found = Standard_True;
194 break;
195 }
196 }
197 return found;
198}
7fd59977 199
200//=======================================================================
201//function : Remove
202//purpose :
203//=======================================================================
204Standard_Boolean TDataStd_IntegerList::Remove(const Standard_Integer value)
205{
206 TColStd_ListIteratorOfListOfInteger itr(myList);
207 for (; itr.More(); itr.Next())
208 {
209 if (itr.Value() == value)
210 {
211 Backup();
212 myList.Remove(itr);
213 return Standard_True;
214 }
215 }
216 return Standard_False;
217}
218
1ff07227 219//=======================================================================
220//function : Remove
221//purpose : Removes the <value> at the <index> position.
222//=======================================================================
223Standard_Boolean TDataStd_IntegerList::RemoveByIndex (const Standard_Integer index)
224{
225 Standard_Integer i(1);
226 Standard_Boolean found(Standard_False);
227 TColStd_ListIteratorOfListOfInteger itr(myList);
228 for (; itr.More(); itr.Next(), ++i)
229 {
230 if (i == index)
231 {
232 Backup();
233 myList.Remove(itr);
234 found = Standard_True;
235 break;
236 }
237 }
238 return found;
239}
240
7fd59977 241//=======================================================================
242//function : Clear
243//purpose :
244//=======================================================================
245void TDataStd_IntegerList::Clear()
246{
247 Backup();
248 myList.Clear();
249}
250
251//=======================================================================
252//function : First
253//purpose :
254//=======================================================================
255Standard_Integer TDataStd_IntegerList::First() const
256{
257 return myList.First();
258}
259
260//=======================================================================
261//function : Last
262//purpose :
263//=======================================================================
264Standard_Integer TDataStd_IntegerList::Last() const
265{
266 return myList.Last();
267}
268
269//=======================================================================
270//function : List
271//purpose :
272//=======================================================================
273const TColStd_ListOfInteger& TDataStd_IntegerList::List() const
274{
275 return myList;
276}
277
278//=======================================================================
279//function : ID
280//purpose :
281//=======================================================================
282const Standard_GUID& TDataStd_IntegerList::ID () const
283{
5a1271c8 284 return myID;
285}
286
287//=======================================================================
288//function : SetID
289//purpose :
290//=======================================================================
291
292void TDataStd_IntegerList::SetID( const Standard_GUID& theGuid)
293{
294 if(myID == theGuid) return;
295 Backup();
296 myID = theGuid;
297}
298
299//=======================================================================
300//function : SetID
301//purpose : sets default ID
302//=======================================================================
303
304void TDataStd_IntegerList::SetID()
305{
306 Backup();
307 myID = GetID();
7fd59977 308}
309
310//=======================================================================
311//function : NewEmpty
312//purpose :
313//=======================================================================
314Handle(TDF_Attribute) TDataStd_IntegerList::NewEmpty () const
315{
316 return new TDataStd_IntegerList();
317}
318
319//=======================================================================
320//function : Restore
321//purpose :
322//=======================================================================
323void TDataStd_IntegerList::Restore(const Handle(TDF_Attribute)& With)
324{
325 myList.Clear();
326 Handle(TDataStd_IntegerList) aList = Handle(TDataStd_IntegerList)::DownCast(With);
327 TColStd_ListIteratorOfListOfInteger itr(aList->List());
328 for (; itr.More(); itr.Next())
329 {
330 myList.Append(itr.Value());
331 }
5a1271c8 332 myID = aList->ID();
7fd59977 333}
334
335//=======================================================================
336//function : Paste
337//purpose :
338//=======================================================================
339void TDataStd_IntegerList::Paste (const Handle(TDF_Attribute)& Into,
5a1271c8 340 const Handle(TDF_RelocationTable)& ) const
7fd59977 341{
342 Handle(TDataStd_IntegerList) aList = Handle(TDataStd_IntegerList)::DownCast(Into);
343 aList->Clear();
344 TColStd_ListIteratorOfListOfInteger itr(myList);
345 for (; itr.More(); itr.Next())
346 {
347 aList->Append(itr.Value());
348 }
5a1271c8 349 aList->SetID(myID);
7fd59977 350}
351
352//=======================================================================
353//function : Dump
354//purpose :
355//=======================================================================
356Standard_OStream& TDataStd_IntegerList::Dump (Standard_OStream& anOS) const
357{
5a1271c8 358 anOS << "\nIntegerList: ";
359 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
360 myID.ToCString(sguid);
361 anOS << sguid;
362 anOS << endl;
7fd59977 363 return anOS;
364}