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 <TDataStd_BooleanList.hxx>
20 #include <TDataStd_ListIteratorOfListOfByte.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_Label.hxx>
23 #include <TDF_RelocationTable.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_BooleanList,TDF_Attribute)
27 //=======================================================================
30 //=======================================================================
31 const Standard_GUID& TDataStd_BooleanList::GetID()
33 static Standard_GUID TDataStd_BooleanListID ("23A9D60E-A033-44d8-96EE-015587A41BBC");
34 return TDataStd_BooleanListID;
37 //=======================================================================
39 //purpose : Implements Set functionality
40 //=======================================================================
41 static Handle(TDataStd_BooleanList) SetAttr(const TDF_Label& label,
42 const Standard_GUID& theGuid)
44 Handle(TDataStd_BooleanList) A;
45 if (!label.FindAttribute (theGuid, A))
47 A = new TDataStd_BooleanList;
49 label.AddAttribute(A);
54 //=======================================================================
55 //function : TDataStd_BooleanList
56 //purpose : Empty Constructor
57 //=======================================================================
58 TDataStd_BooleanList::TDataStd_BooleanList() : myID(GetID())
61 //=======================================================================
64 //=======================================================================
65 Handle(TDataStd_BooleanList) TDataStd_BooleanList::Set(const TDF_Label& label)
67 return SetAttr(label, GetID());
70 //=======================================================================
72 //purpose : Set user defined attribute with specific ID
73 //=======================================================================
74 Handle(TDataStd_BooleanList) TDataStd_BooleanList::Set(const TDF_Label& label,
75 const Standard_GUID& theGuid)
77 return SetAttr(label, theGuid);
79 //=======================================================================
82 //=======================================================================
83 Standard_Boolean TDataStd_BooleanList::IsEmpty() const
85 return myList.IsEmpty();
88 //=======================================================================
91 //=======================================================================
92 Standard_Integer TDataStd_BooleanList::Extent() const
94 return myList.Extent();
97 //=======================================================================
100 //=======================================================================
101 void TDataStd_BooleanList::Prepend(const Standard_Boolean value)
104 myList.Prepend( value ? 1 : 0 );
107 //=======================================================================
110 //=======================================================================
111 void TDataStd_BooleanList::Append(const Standard_Boolean value)
114 myList.Append( value ? 1 : 0 );
117 //=======================================================================
120 //=======================================================================
121 void TDataStd_BooleanList::Clear()
127 //=======================================================================
130 //=======================================================================
131 Standard_Boolean TDataStd_BooleanList::First() const
133 return myList.First() == 1;
136 //=======================================================================
139 //=======================================================================
140 Standard_Boolean TDataStd_BooleanList::Last() const
142 return myList.Last() == 1;
145 //=======================================================================
148 //=======================================================================
149 const TDataStd_ListOfByte& TDataStd_BooleanList::List() const
154 //=======================================================================
155 //function : InsertBefore
156 //purpose : Inserts the <value> before the <index> position.
157 //=======================================================================
158 Standard_Boolean TDataStd_BooleanList::InsertBefore(const Standard_Integer index,
159 const Standard_Boolean before_value)
161 Standard_Integer i(1);
162 Standard_Boolean found(Standard_False);
163 TDataStd_ListIteratorOfListOfByte itr(myList);
164 for (; itr.More(); itr.Next(), ++i)
169 myList.InsertBefore(before_value ? 1 : 0, itr);
170 found = Standard_True;
177 //=======================================================================
178 //function : InsertAfter
179 //purpose : Inserts the <value> after the <index> position.
180 //=======================================================================
181 Standard_Boolean TDataStd_BooleanList::InsertAfter(const Standard_Integer index,
182 const Standard_Boolean after_value)
184 Standard_Integer i(1);
185 Standard_Boolean found(Standard_False);
186 TDataStd_ListIteratorOfListOfByte itr(myList);
187 for (; itr.More(); itr.Next(), ++i)
192 myList.InsertAfter(after_value ? 1 : 0, itr);
193 found = Standard_True;
200 //=======================================================================
202 //purpose : Removes the <value> at the <index> position.
203 //=======================================================================
204 Standard_Boolean TDataStd_BooleanList::Remove(const Standard_Integer index)
206 Standard_Integer i(1);
207 Standard_Boolean found(Standard_False);
208 TDataStd_ListIteratorOfListOfByte itr(myList);
209 for (; itr.More(); itr.Next(), ++i)
215 found = Standard_True;
222 //=======================================================================
225 //=======================================================================
226 const Standard_GUID& TDataStd_BooleanList::ID () const
231 //=======================================================================
234 //=======================================================================
236 void TDataStd_BooleanList::SetID( const Standard_GUID& theGuid)
238 if(myID == theGuid) return;
243 //=======================================================================
245 //purpose : sets default ID
246 //=======================================================================
248 void TDataStd_BooleanList::SetID()
254 //=======================================================================
255 //function : NewEmpty
257 //=======================================================================
258 Handle(TDF_Attribute) TDataStd_BooleanList::NewEmpty () const
260 return new TDataStd_BooleanList();
263 //=======================================================================
266 //=======================================================================
267 void TDataStd_BooleanList::Restore(const Handle(TDF_Attribute)& With)
270 Handle(TDataStd_BooleanList) aList = Handle(TDataStd_BooleanList)::DownCast(With);
271 TDataStd_ListIteratorOfListOfByte itr(aList->List());
272 for (; itr.More(); itr.Next())
274 myList.Append (itr.Value() ? 1 : 0);
279 //=======================================================================
282 //=======================================================================
283 void TDataStd_BooleanList::Paste (const Handle(TDF_Attribute)& Into,
284 const Handle(TDF_RelocationTable)& ) const
286 Handle(TDataStd_BooleanList) aList = Handle(TDataStd_BooleanList)::DownCast(Into);
288 TDataStd_ListIteratorOfListOfByte itr(myList);
289 for (; itr.More(); itr.Next())
291 aList->Append (itr.Value() != 0);
296 //=======================================================================
299 //=======================================================================
300 Standard_OStream& TDataStd_BooleanList::Dump (Standard_OStream& anOS) const
302 anOS << "\nBooleanList: ";
303 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
304 myID.ToCString(sguid);