1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <Standard_GUID.hxx>
18 #include <Standard_Type.hxx>
19 #include <TColStd_ListIteratorOfListOfInteger.hxx>
20 #include <TDataStd_IntegerList.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_Label.hxx>
23 #include <TDF_RelocationTable.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_IntegerList,TDF_Attribute)
27 //=======================================================================
30 //=======================================================================
31 const Standard_GUID& TDataStd_IntegerList::GetID()
33 static Standard_GUID TDataStd_IntegerListID ("E406AA18-FF3F-483b-9A78-1A5EA5D1AA52");
34 return TDataStd_IntegerListID;
37 //=======================================================================
39 //purpose : Implements Set functionality
40 //=======================================================================
41 static Handle(TDataStd_IntegerList) SetAttr(const TDF_Label& label,
42 const Standard_GUID& theGuid)
44 Handle(TDataStd_IntegerList) A;
45 if (!label.FindAttribute (theGuid, A))
47 A = new TDataStd_IntegerList;
49 label.AddAttribute(A);
54 //=======================================================================
55 //function : TDataStd_IntegerList
56 //purpose : Empty Constructor
57 //=======================================================================
58 TDataStd_IntegerList::TDataStd_IntegerList()
63 //=======================================================================
66 //=======================================================================
67 Handle(TDataStd_IntegerList) TDataStd_IntegerList::Set(const TDF_Label& label)
69 return SetAttr(label, GetID());
72 //=======================================================================
74 //purpose : Set user defined attribute with specific ID
75 //=======================================================================
76 Handle(TDataStd_IntegerList) TDataStd_IntegerList::Set(const TDF_Label& label,
77 const Standard_GUID& theGuid)
79 return SetAttr(label, theGuid);
82 //=======================================================================
85 //=======================================================================
86 Standard_Boolean TDataStd_IntegerList::IsEmpty() const
88 return myList.IsEmpty();
91 //=======================================================================
94 //=======================================================================
95 Standard_Integer TDataStd_IntegerList::Extent() const
97 return myList.Extent();
100 //=======================================================================
103 //=======================================================================
104 void TDataStd_IntegerList::Prepend(const Standard_Integer value)
107 myList.Prepend(value);
110 //=======================================================================
113 //=======================================================================
114 void TDataStd_IntegerList::Append(const Standard_Integer value)
117 myList.Append(value);
120 //=======================================================================
121 //function : InsertBefore
123 //=======================================================================
124 Standard_Boolean TDataStd_IntegerList::InsertBefore(const Standard_Integer value,
125 const Standard_Integer before_value)
127 TColStd_ListIteratorOfListOfInteger itr(myList);
128 for (; itr.More(); itr.Next())
130 if (itr.Value() == before_value)
133 myList.InsertBefore(value, itr);
134 return Standard_True;
137 return Standard_False;
140 // Inserts the <value> before the <index> position.
141 // The indices start with 1 .. Extent().
142 Standard_Boolean TDataStd_IntegerList::InsertBeforeByIndex (const Standard_Integer index,
143 const Standard_Integer before_value)
145 Standard_Integer i(1);
146 Standard_Boolean found(Standard_False);
147 TColStd_ListIteratorOfListOfInteger itr(myList);
148 for (; itr.More(); itr.Next(), ++i)
153 myList.InsertBefore(before_value, itr);
154 found = Standard_True;
161 //=======================================================================
162 //function : InsertAfter
164 //=======================================================================
165 Standard_Boolean TDataStd_IntegerList::InsertAfter(const Standard_Integer value,
166 const Standard_Integer after_value)
168 TColStd_ListIteratorOfListOfInteger itr(myList);
169 for (; itr.More(); itr.Next())
171 if (itr.Value() == after_value)
174 myList.InsertAfter(value, itr);
175 return Standard_True;
178 return Standard_False;
181 // Inserts the <value> after the <index> position.
182 // The indices start with 1 .. Extent().
183 Standard_Boolean TDataStd_IntegerList::InsertAfterByIndex (const Standard_Integer index,
184 const Standard_Integer after_value)
186 Standard_Integer i(1);
187 Standard_Boolean found(Standard_False);
188 TColStd_ListIteratorOfListOfInteger itr(myList);
189 for (; itr.More(); itr.Next(), ++i)
194 myList.InsertAfter(after_value, itr);
195 found = Standard_True;
202 //=======================================================================
205 //=======================================================================
206 Standard_Boolean TDataStd_IntegerList::Remove(const Standard_Integer value)
208 TColStd_ListIteratorOfListOfInteger itr(myList);
209 for (; itr.More(); itr.Next())
211 if (itr.Value() == value)
215 return Standard_True;
218 return Standard_False;
221 //=======================================================================
223 //purpose : Removes the <value> at the <index> position.
224 //=======================================================================
225 Standard_Boolean TDataStd_IntegerList::RemoveByIndex (const Standard_Integer index)
227 Standard_Integer i(1);
228 Standard_Boolean found(Standard_False);
229 TColStd_ListIteratorOfListOfInteger itr(myList);
230 for (; itr.More(); itr.Next(), ++i)
236 found = Standard_True;
243 //=======================================================================
246 //=======================================================================
247 void TDataStd_IntegerList::Clear()
253 //=======================================================================
256 //=======================================================================
257 Standard_Integer TDataStd_IntegerList::First() const
259 return myList.First();
262 //=======================================================================
265 //=======================================================================
266 Standard_Integer TDataStd_IntegerList::Last() const
268 return myList.Last();
271 //=======================================================================
274 //=======================================================================
275 const TColStd_ListOfInteger& TDataStd_IntegerList::List() const
280 //=======================================================================
283 //=======================================================================
284 const Standard_GUID& TDataStd_IntegerList::ID () const
289 //=======================================================================
292 //=======================================================================
294 void TDataStd_IntegerList::SetID( const Standard_GUID& theGuid)
296 if(myID == theGuid) return;
301 //=======================================================================
303 //purpose : sets default ID
304 //=======================================================================
306 void TDataStd_IntegerList::SetID()
312 //=======================================================================
313 //function : NewEmpty
315 //=======================================================================
316 Handle(TDF_Attribute) TDataStd_IntegerList::NewEmpty () const
318 return new TDataStd_IntegerList();
321 //=======================================================================
324 //=======================================================================
325 void TDataStd_IntegerList::Restore(const Handle(TDF_Attribute)& With)
328 Handle(TDataStd_IntegerList) aList = Handle(TDataStd_IntegerList)::DownCast(With);
329 TColStd_ListIteratorOfListOfInteger itr(aList->List());
330 for (; itr.More(); itr.Next())
332 myList.Append(itr.Value());
337 //=======================================================================
340 //=======================================================================
341 void TDataStd_IntegerList::Paste (const Handle(TDF_Attribute)& Into,
342 const Handle(TDF_RelocationTable)& ) const
344 Handle(TDataStd_IntegerList) aList = Handle(TDataStd_IntegerList)::DownCast(Into);
346 TColStd_ListIteratorOfListOfInteger itr(myList);
347 for (; itr.More(); itr.Next())
349 aList->Append(itr.Value());
354 //=======================================================================
357 //=======================================================================
358 Standard_OStream& TDataStd_IntegerList::Dump (Standard_OStream& anOS) const
360 anOS << "\nIntegerList: ";
361 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
362 myID.ToCString(sguid);