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_ListIteratorOfListOfReal.hxx>
20 #include <TDataStd_RealList.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_Label.hxx>
23 #include <TDF_RelocationTable.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_RealList,TDF_Attribute)
27 //=======================================================================
30 //=======================================================================
31 const Standard_GUID& TDataStd_RealList::GetID()
33 static Standard_GUID TDataStd_RealListID ("349ACE18-7CD6-4525-9938-FBBF22AA54D3");
34 return TDataStd_RealListID;
37 //=======================================================================
39 //purpose : Implements Set functionality
40 //=======================================================================
41 static Handle(TDataStd_RealList) SetAttr(const TDF_Label& label,
42 const Standard_GUID& theGuid)
44 Handle(TDataStd_RealList) A;
45 if (!label.FindAttribute (theGuid, A))
47 A = new TDataStd_RealList;
49 label.AddAttribute(A);
54 //=======================================================================
55 //function : TDataStd_RealList
56 //purpose : Empty Constructor
57 //=======================================================================
58 TDataStd_RealList::TDataStd_RealList()
63 //=======================================================================
66 //=======================================================================
67 Handle(TDataStd_RealList) TDataStd_RealList::Set(const TDF_Label& label)
69 return SetAttr(label, GetID());
72 //=======================================================================
74 //purpose : Set user defined attribute with specific ID
75 //=======================================================================
76 Handle(TDataStd_RealList) TDataStd_RealList::Set(const TDF_Label& label,
77 const Standard_GUID& theGuid)
79 return SetAttr(label, theGuid);
82 //=======================================================================
85 //=======================================================================
86 Standard_Boolean TDataStd_RealList::IsEmpty() const
88 return myList.IsEmpty();
91 //=======================================================================
94 //=======================================================================
95 Standard_Integer TDataStd_RealList::Extent() const
97 return myList.Extent();
100 //=======================================================================
103 //=======================================================================
104 void TDataStd_RealList::Prepend(const Standard_Real value)
107 myList.Prepend(value);
110 //=======================================================================
113 //=======================================================================
114 void TDataStd_RealList::Append(const Standard_Real value)
117 myList.Append(value);
120 //=======================================================================
121 //function : InsertBefore
123 //=======================================================================
124 Standard_Boolean TDataStd_RealList::InsertBefore(const Standard_Real value,
125 const Standard_Real before_value)
127 TColStd_ListIteratorOfListOfReal 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_RealList::InsertBeforeByIndex (const Standard_Integer index,
143 const Standard_Real before_value)
145 Standard_Integer i(1);
146 Standard_Boolean found(Standard_False);
147 TColStd_ListIteratorOfListOfReal 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_RealList::InsertAfter(const Standard_Real value,
166 const Standard_Real after_value)
168 TColStd_ListIteratorOfListOfReal 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_RealList::InsertAfterByIndex (const Standard_Integer index,
184 const Standard_Real after_value)
186 Standard_Integer i(1);
187 Standard_Boolean found(Standard_False);
188 TColStd_ListIteratorOfListOfReal 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_RealList::Remove(const Standard_Real value)
208 TColStd_ListIteratorOfListOfReal 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 a value at the <index> position.
224 //=======================================================================
225 Standard_Boolean TDataStd_RealList::RemoveByIndex (const Standard_Integer index)
227 Standard_Integer i(1);
228 Standard_Boolean found(Standard_False);
229 TColStd_ListIteratorOfListOfReal itr(myList);
230 for (; itr.More(); itr.Next(), ++i)
236 found = Standard_True;
243 //=======================================================================
246 //=======================================================================
247 void TDataStd_RealList::Clear()
253 //=======================================================================
256 //=======================================================================
257 Standard_Real TDataStd_RealList::First() const
259 return myList.First();
262 //=======================================================================
265 //=======================================================================
266 Standard_Real TDataStd_RealList::Last() const
268 return myList.Last();
271 //=======================================================================
274 //=======================================================================
275 const TColStd_ListOfReal& TDataStd_RealList::List() const
280 //=======================================================================
283 //=======================================================================
284 const Standard_GUID& TDataStd_RealList::ID () const
289 //=======================================================================
292 //=======================================================================
293 void TDataStd_RealList::SetID( const Standard_GUID& theGuid)
295 if(myID == theGuid) return;
300 //=======================================================================
302 //purpose : sets default ID
303 //=======================================================================
304 void TDataStd_RealList::SetID()
310 //=======================================================================
311 //function : NewEmpty
313 //=======================================================================
314 Handle(TDF_Attribute) TDataStd_RealList::NewEmpty () const
316 return new TDataStd_RealList();
319 //=======================================================================
322 //=======================================================================
323 void TDataStd_RealList::Restore(const Handle(TDF_Attribute)& With)
326 Handle(TDataStd_RealList) aList = Handle(TDataStd_RealList)::DownCast(With);
327 TColStd_ListIteratorOfListOfReal itr(aList->List());
328 for (; itr.More(); itr.Next())
330 myList.Append(itr.Value());
335 //=======================================================================
338 //=======================================================================
339 void TDataStd_RealList::Paste (const Handle(TDF_Attribute)& Into,
340 const Handle(TDF_RelocationTable)& ) const
342 Handle(TDataStd_RealList) aList = Handle(TDataStd_RealList)::DownCast(Into);
344 TColStd_ListIteratorOfListOfReal itr(myList);
345 for (; itr.More(); itr.Next())
347 aList->Append(itr.Value());
352 //=======================================================================
355 //=======================================================================
356 Standard_OStream& TDataStd_RealList::Dump (Standard_OStream& anOS) const
358 anOS << "\nRealList: ";
359 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
360 myID.ToCString(sguid);