0030895: Coding Rules - specify std namespace explicitly for std::cout and streams
[occt.git] / src / TDataStd / TDataStd_BooleanList.cxx
1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
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>
24
25 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_BooleanList,TDF_Attribute)
26
27 //=======================================================================
28 //function : GetID
29 //purpose  : 
30 //=======================================================================
31 const Standard_GUID& TDataStd_BooleanList::GetID() 
32
33   static Standard_GUID TDataStd_BooleanListID ("23A9D60E-A033-44d8-96EE-015587A41BBC");
34   return TDataStd_BooleanListID; 
35 }
36
37 //=======================================================================
38 //function : SetAttr
39 //purpose  : Implements Set functionality
40 //=======================================================================
41 static Handle(TDataStd_BooleanList) SetAttr(const TDF_Label&       label,
42                                             const Standard_GUID&   theGuid) 
43 {
44   Handle(TDataStd_BooleanList) A;
45   if (!label.FindAttribute (theGuid, A)) 
46   {
47     A = new TDataStd_BooleanList;
48     A->SetID(theGuid);
49     label.AddAttribute(A);
50   }
51   return A;
52 }
53
54 //=======================================================================
55 //function : TDataStd_BooleanList
56 //purpose  : Empty Constructor
57 //=======================================================================
58 TDataStd_BooleanList::TDataStd_BooleanList() : myID(GetID())
59 {}
60
61 //=======================================================================
62 //function : Set
63 //purpose  : 
64 //=======================================================================
65 Handle(TDataStd_BooleanList) TDataStd_BooleanList::Set(const TDF_Label& label) 
66 {
67   return SetAttr(label, GetID());
68 }
69
70 //=======================================================================
71 //function : Set
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) 
76 {
77   return SetAttr(label, theGuid); 
78 }
79 //=======================================================================
80 //function : IsEmpty
81 //purpose  : 
82 //=======================================================================
83 Standard_Boolean TDataStd_BooleanList::IsEmpty() const
84 {
85   return myList.IsEmpty();
86 }
87
88 //=======================================================================
89 //function : Extent
90 //purpose  : 
91 //=======================================================================
92 Standard_Integer TDataStd_BooleanList::Extent() const
93 {
94   return myList.Extent();
95 }
96
97 //=======================================================================
98 //function : Prepend
99 //purpose  : 
100 //=======================================================================
101 void TDataStd_BooleanList::Prepend(const Standard_Boolean value)
102 {
103   Backup();
104   myList.Prepend( value ? 1 : 0 );
105 }
106
107 //=======================================================================
108 //function : Append
109 //purpose  : 
110 //=======================================================================
111 void TDataStd_BooleanList::Append(const Standard_Boolean value)
112 {
113   Backup();
114   myList.Append( value ? 1 : 0 );
115 }
116
117 //=======================================================================
118 //function : Clear
119 //purpose  : 
120 //=======================================================================
121 void TDataStd_BooleanList::Clear()
122 {
123   Backup();
124   myList.Clear();
125 }
126
127 //=======================================================================
128 //function : First
129 //purpose  : 
130 //=======================================================================
131 Standard_Boolean TDataStd_BooleanList::First() const
132 {
133   return myList.First() == 1;
134 }
135
136 //=======================================================================
137 //function : Last
138 //purpose  : 
139 //=======================================================================
140 Standard_Boolean TDataStd_BooleanList::Last() const
141 {
142   return myList.Last() == 1;
143 }
144
145 //=======================================================================
146 //function : List
147 //purpose  : 
148 //=======================================================================
149 const TDataStd_ListOfByte& TDataStd_BooleanList::List() const
150 {
151   return myList;
152 }
153
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)
160 {
161   Standard_Integer i(1);
162   Standard_Boolean found(Standard_False);
163   TDataStd_ListIteratorOfListOfByte itr(myList);
164   for (; itr.More(); itr.Next(), ++i)
165   {
166     if (i == index)
167     {
168       Backup();
169       myList.InsertBefore(before_value ? 1 : 0, itr);
170       found = Standard_True;
171       break;
172     }
173   }
174   return found;
175 }
176
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)
183 {
184   Standard_Integer i(1);
185   Standard_Boolean found(Standard_False);
186   TDataStd_ListIteratorOfListOfByte itr(myList);
187   for (; itr.More(); itr.Next(), ++i)
188   {
189     if (i == index)
190     {
191       Backup();
192       myList.InsertAfter(after_value ? 1 : 0, itr);
193       found = Standard_True;
194       break;
195     }
196   }
197   return found;
198 }
199
200 //=======================================================================
201 //function : Remove
202 //purpose  : Removes the <value> at the <index> position.
203 //=======================================================================
204 Standard_Boolean TDataStd_BooleanList::Remove(const Standard_Integer index)
205 {
206   Standard_Integer i(1);
207   Standard_Boolean found(Standard_False);
208   TDataStd_ListIteratorOfListOfByte itr(myList);
209   for (; itr.More(); itr.Next(), ++i)
210   {
211     if (i == index)
212     {
213       Backup();
214       myList.Remove(itr);
215       found = Standard_True;
216       break;
217     }
218   }
219   return found;
220 }
221
222 //=======================================================================
223 //function : ID
224 //purpose  : 
225 //=======================================================================
226 const Standard_GUID& TDataStd_BooleanList::ID () const 
227
228   return myID; 
229 }
230
231 //=======================================================================
232 //function : SetID
233 //purpose  :
234 //=======================================================================
235
236 void TDataStd_BooleanList::SetID( const Standard_GUID&  theGuid)
237 {  
238   if(myID == theGuid) return;
239   Backup();
240   myID = theGuid;
241 }
242
243 //=======================================================================
244 //function : SetID
245 //purpose  : sets default ID
246 //=======================================================================
247
248 void TDataStd_BooleanList::SetID()
249 {  
250   Backup();
251   myID = GetID();
252 }
253
254 //=======================================================================
255 //function : NewEmpty
256 //purpose  : 
257 //=======================================================================
258 Handle(TDF_Attribute) TDataStd_BooleanList::NewEmpty () const
259 {  
260   return new TDataStd_BooleanList(); 
261 }
262
263 //=======================================================================
264 //function : Restore
265 //purpose  : 
266 //=======================================================================
267 void TDataStd_BooleanList::Restore(const Handle(TDF_Attribute)& With) 
268 {
269   myList.Clear();
270   Handle(TDataStd_BooleanList) aList = Handle(TDataStd_BooleanList)::DownCast(With);
271   TDataStd_ListIteratorOfListOfByte itr(aList->List());
272   for (; itr.More(); itr.Next())
273   {
274     myList.Append (itr.Value() ? 1 : 0);
275   }
276   myID = aList->ID();
277 }
278
279 //=======================================================================
280 //function : Paste
281 //purpose  : 
282 //=======================================================================
283 void TDataStd_BooleanList::Paste (const Handle(TDF_Attribute)& Into,
284                                   const Handle(TDF_RelocationTable)& ) const
285 {
286   Handle(TDataStd_BooleanList) aList = Handle(TDataStd_BooleanList)::DownCast(Into);
287   aList->Clear();
288   TDataStd_ListIteratorOfListOfByte itr(myList);
289   for (; itr.More(); itr.Next())
290   {
291     aList->Append (itr.Value() != 0);
292   }
293   aList->SetID(myID);
294 }
295
296 //=======================================================================
297 //function : Dump
298 //purpose  : 
299 //=======================================================================
300 Standard_OStream& TDataStd_BooleanList::Dump (Standard_OStream& anOS) const
301 {  
302   anOS << "\nBooleanList: ";
303   Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
304   myID.ToCString(sguid);
305   anOS << sguid;
306   anOS << std::endl;
307   return anOS;
308 }