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.
16 #include <TDataStd_RealList.hxx>
18 #include <Standard_Dump.hxx>
19 #include <Standard_GUID.hxx>
20 #include <Standard_Type.hxx>
21 #include <TColStd_ListIteratorOfListOfReal.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_RelocationTable.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_RealList,TDF_Attribute)
28 //=======================================================================
31 //=======================================================================
32 const Standard_GUID& TDataStd_RealList::GetID()
34 static Standard_GUID TDataStd_RealListID ("349ACE18-7CD6-4525-9938-FBBF22AA54D3");
35 return TDataStd_RealListID;
38 //=======================================================================
40 //purpose : Implements Set functionality
41 //=======================================================================
42 static Handle(TDataStd_RealList) SetAttr(const TDF_Label& label,
43 const Standard_GUID& theGuid)
45 Handle(TDataStd_RealList) A;
46 if (!label.FindAttribute (theGuid, A))
48 A = new TDataStd_RealList;
50 label.AddAttribute(A);
55 //=======================================================================
56 //function : TDataStd_RealList
57 //purpose : Empty Constructor
58 //=======================================================================
59 TDataStd_RealList::TDataStd_RealList() : myID(GetID())
62 //=======================================================================
65 //=======================================================================
66 Handle(TDataStd_RealList) TDataStd_RealList::Set(const TDF_Label& label)
68 return SetAttr(label, GetID());
71 //=======================================================================
73 //purpose : Set user defined attribute with specific ID
74 //=======================================================================
75 Handle(TDataStd_RealList) TDataStd_RealList::Set(const TDF_Label& label,
76 const Standard_GUID& theGuid)
78 return SetAttr(label, theGuid);
81 //=======================================================================
84 //=======================================================================
85 Standard_Boolean TDataStd_RealList::IsEmpty() const
87 return myList.IsEmpty();
90 //=======================================================================
93 //=======================================================================
94 Standard_Integer TDataStd_RealList::Extent() const
96 return myList.Extent();
99 //=======================================================================
102 //=======================================================================
103 void TDataStd_RealList::Prepend(const Standard_Real value)
106 myList.Prepend(value);
109 //=======================================================================
112 //=======================================================================
113 void TDataStd_RealList::Append(const Standard_Real value)
116 myList.Append(value);
119 //=======================================================================
120 //function : InsertBefore
122 //=======================================================================
123 Standard_Boolean TDataStd_RealList::InsertBefore(const Standard_Real value,
124 const Standard_Real before_value)
126 TColStd_ListIteratorOfListOfReal itr(myList);
127 for (; itr.More(); itr.Next())
129 if (itr.Value() == before_value)
132 myList.InsertBefore(value, itr);
133 return Standard_True;
136 return Standard_False;
139 // Inserts the <value> before the <index> position.
140 // The indices start with 1 .. Extent().
141 Standard_Boolean TDataStd_RealList::InsertBeforeByIndex (const Standard_Integer index,
142 const Standard_Real before_value)
144 Standard_Integer i(1);
145 Standard_Boolean found(Standard_False);
146 TColStd_ListIteratorOfListOfReal itr(myList);
147 for (; itr.More(); itr.Next(), ++i)
152 myList.InsertBefore(before_value, itr);
153 found = Standard_True;
160 //=======================================================================
161 //function : InsertAfter
163 //=======================================================================
164 Standard_Boolean TDataStd_RealList::InsertAfter(const Standard_Real value,
165 const Standard_Real after_value)
167 TColStd_ListIteratorOfListOfReal itr(myList);
168 for (; itr.More(); itr.Next())
170 if (itr.Value() == after_value)
173 myList.InsertAfter(value, itr);
174 return Standard_True;
177 return Standard_False;
180 // Inserts the <value> after the <index> position.
181 // The indices start with 1 .. Extent().
182 Standard_Boolean TDataStd_RealList::InsertAfterByIndex (const Standard_Integer index,
183 const Standard_Real after_value)
185 Standard_Integer i(1);
186 Standard_Boolean found(Standard_False);
187 TColStd_ListIteratorOfListOfReal itr(myList);
188 for (; itr.More(); itr.Next(), ++i)
193 myList.InsertAfter(after_value, itr);
194 found = Standard_True;
201 //=======================================================================
204 //=======================================================================
205 Standard_Boolean TDataStd_RealList::Remove(const Standard_Real value)
207 TColStd_ListIteratorOfListOfReal itr(myList);
208 for (; itr.More(); itr.Next())
210 if (itr.Value() == value)
214 return Standard_True;
217 return Standard_False;
220 //=======================================================================
222 //purpose : Removes a value at the <index> position.
223 //=======================================================================
224 Standard_Boolean TDataStd_RealList::RemoveByIndex (const Standard_Integer index)
226 Standard_Integer i(1);
227 Standard_Boolean found(Standard_False);
228 TColStd_ListIteratorOfListOfReal itr(myList);
229 for (; itr.More(); itr.Next(), ++i)
235 found = Standard_True;
242 //=======================================================================
245 //=======================================================================
246 void TDataStd_RealList::Clear()
252 //=======================================================================
255 //=======================================================================
256 Standard_Real TDataStd_RealList::First() const
258 return myList.First();
261 //=======================================================================
264 //=======================================================================
265 Standard_Real TDataStd_RealList::Last() const
267 return myList.Last();
270 //=======================================================================
273 //=======================================================================
274 const TColStd_ListOfReal& TDataStd_RealList::List() const
279 //=======================================================================
282 //=======================================================================
283 const Standard_GUID& TDataStd_RealList::ID () const
288 //=======================================================================
291 //=======================================================================
292 void TDataStd_RealList::SetID( const Standard_GUID& theGuid)
294 if(myID == theGuid) return;
299 //=======================================================================
301 //purpose : sets default ID
302 //=======================================================================
303 void TDataStd_RealList::SetID()
309 //=======================================================================
310 //function : NewEmpty
312 //=======================================================================
313 Handle(TDF_Attribute) TDataStd_RealList::NewEmpty () const
315 return new TDataStd_RealList();
318 //=======================================================================
321 //=======================================================================
322 void TDataStd_RealList::Restore(const Handle(TDF_Attribute)& With)
325 Handle(TDataStd_RealList) aList = Handle(TDataStd_RealList)::DownCast(With);
326 TColStd_ListIteratorOfListOfReal itr(aList->List());
327 for (; itr.More(); itr.Next())
329 myList.Append(itr.Value());
334 //=======================================================================
337 //=======================================================================
338 void TDataStd_RealList::Paste (const Handle(TDF_Attribute)& Into,
339 const Handle(TDF_RelocationTable)& ) const
341 Handle(TDataStd_RealList) aList = Handle(TDataStd_RealList)::DownCast(Into);
343 TColStd_ListIteratorOfListOfReal itr(myList);
344 for (; itr.More(); itr.Next())
346 aList->Append(itr.Value());
351 //=======================================================================
354 //=======================================================================
355 Standard_OStream& TDataStd_RealList::Dump (Standard_OStream& anOS) const
357 anOS << "\nRealList: ";
358 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
359 myID.ToCString(sguid);
365 //=======================================================================
366 //function : DumpJson
368 //=======================================================================
369 void TDataStd_RealList::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
371 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
373 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
375 for (TColStd_ListOfReal::Iterator aListIt (myList); aListIt.More(); aListIt.Next())
377 const Standard_Real& aValue = aListIt.Value();
378 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aValue)
381 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)