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