0024830: Remove redundant keyword 'mutable' in CDL declarations
[occt.git] / src / TDataStd / TDataStd_IntegerArray.cxx
CommitLineData
b311480e 1// Created on: 1999-06-16
2// Created by: Sergey RUIN
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TDataStd_IntegerArray.ixx>
18#include <TDataStd_DeltaOnModificationOfIntArray.hxx>
19#include <TDF_DefaultDeltaOnModification.hxx>
20#define OCC925
21#define OCC2932
22
23//=======================================================================
24//function : GetID
25//purpose :
26//=======================================================================
27
28const Standard_GUID& TDataStd_IntegerArray::GetID()
29{
30 static Standard_GUID TDataStd_IntegerArrayID ("2a96b61d-ec8b-11d0-bee7-080009dc3333");
31 return TDataStd_IntegerArrayID;
32}
33
34
35//=======================================================================
36//function : TDataStd_IntegerArray
37//purpose : Empty Constructor
38//=======================================================================
39
40TDataStd_IntegerArray::TDataStd_IntegerArray()
41 :myIsDelta(Standard_False) {}
42
43//=======================================================================
44//function : Init
45//purpose :
46//=======================================================================
47
48void TDataStd_IntegerArray::Init(const Standard_Integer lower,
49 const Standard_Integer upper)
50{
51#ifdef OCC925
52 Backup();
53#endif
54 myValue = new TColStd_HArray1OfInteger(lower, upper, 0);
55}
56
57//=======================================================================
58//function : Set
59//purpose : isDelta applicable only for new attributes
60//=======================================================================
61
62Handle(TDataStd_IntegerArray) TDataStd_IntegerArray::Set
63 (const TDF_Label& label,
64 const Standard_Integer lower,
65 const Standard_Integer upper,
66 const Standard_Boolean isDelta)
67
68{
69 Handle(TDataStd_IntegerArray) A;
70 if (!label.FindAttribute (TDataStd_IntegerArray::GetID(), A)) {
71 A = new TDataStd_IntegerArray;
72 A->Init (lower, upper);
73 A->SetDelta(isDelta);
74 label.AddAttribute(A);
75 }
76 else if (lower != A->Lower() || upper != A->Upper())
77 {
78 A->Init (lower, upper);
79 }
80 return A;
81}
82
83//=======================================================================
84//function : SetValue
85//purpose :
86//=======================================================================
87
88void TDataStd_IntegerArray::SetValue(const Standard_Integer index, const Standard_Integer value)
89{
90 if(myValue.IsNull()) return;
91 if( myValue->Value(index) == value)
fa13a85d 92 return;
7fd59977 93 Backup();
94 myValue->SetValue(index, value);
95}
96
97
98//=======================================================================
99//function : GetValue
100//purpose :
101//=======================================================================
102
103Standard_Integer TDataStd_IntegerArray::Value (const Standard_Integer index) const
104{
105 if(myValue.IsNull()) return 0;
106 return myValue->Value(index);
107}
108
109
110
111//=======================================================================
112//function : Lower
113//purpose :
114//=======================================================================
115Standard_Integer TDataStd_IntegerArray::Lower (void) const
116{
117 if(myValue.IsNull()) return 0;
118 return myValue->Lower();
119}
120
121
122//=======================================================================
123//function : Upper
124//purpose :
125//=======================================================================
126Standard_Integer TDataStd_IntegerArray::Upper (void) const
127{
128 if(myValue.IsNull()) return 0;
129 return myValue->Upper();
130}
131
132
133//=======================================================================
134//function : Length
135//purpose :
136//=======================================================================
137Standard_Integer TDataStd_IntegerArray::Length (void) const
138{
139 if(myValue.IsNull()) return 0;
140 return myValue->Length();
141}
142
143
144//=======================================================================
145//function : ChangeArray
146//purpose : If value of <newArray> differs from <myValue>, Backup
147// : performed and myValue refers to new instance of HArray1OfInteger
148// : that holds <newArray>
149//=======================================================================
150
151void TDataStd_IntegerArray::ChangeArray(const Handle(TColStd_HArray1OfInteger)& newArray,
152 const Standard_Boolean isCheckItems)
153{
154 Standard_Integer aLower = newArray->Lower();
155 Standard_Integer anUpper = newArray->Upper();
156 Standard_Boolean aDimEqual = Standard_False;
157 Standard_Integer i;
158#ifdef OCC2932
a855b7eb
S
159
160 if(Lower() == aLower && Upper() == anUpper ) {
7fd59977 161 aDimEqual = Standard_True;
162 if(isCheckItems) {
163 Standard_Boolean isEqual = Standard_True;
164 for(i = aLower; i <= anUpper; i++) {
165 if(myValue->Value(i) != newArray->Value(i)) {
166 isEqual = Standard_False;
167 break;
168 }
169 }
170 if(isEqual)
171 return;
172 }
173 }
174#endif
175
176 Backup();
177// Handles of myValue of current and backuped attributes will be different!
a855b7eb 178 if(myValue.IsNull() || !aDimEqual)
7fd59977 179 myValue = new TColStd_HArray1OfInteger(aLower, anUpper);
180
181 for(i = aLower; i <= anUpper; i++)
182 myValue->SetValue(i, newArray->Value(i));
183}
184
185
186//=======================================================================
187//function : ID
188//purpose :
189//=======================================================================
190
191const Standard_GUID& TDataStd_IntegerArray::ID () const { return GetID(); }
192
193
194//=======================================================================
195//function : NewEmpty
196//purpose :
197//=======================================================================
198
199Handle(TDF_Attribute) TDataStd_IntegerArray::NewEmpty () const
200{
201 return new TDataStd_IntegerArray();
202}
203
204//=======================================================================
205//function : Restore
206//purpose :
207//=======================================================================
208
209void TDataStd_IntegerArray::Restore(const Handle(TDF_Attribute)& With)
210{
211 Standard_Integer i, lower, upper;
212 Handle(TDataStd_IntegerArray) anArray = Handle(TDataStd_IntegerArray)::DownCast(With);
213 if(!anArray->myValue.IsNull()) {
214 lower = anArray->Lower();
215 upper = anArray->Upper();
216 myValue = new TColStd_HArray1OfInteger(lower, upper);
217 for(i = lower; i<=upper; i++)
218 myValue->SetValue(i, anArray->Value(i));
219 myIsDelta = anArray->myIsDelta;
220 }
221 else
222 myValue.Nullify();
223}
224
225//=======================================================================
226//function : Paste
227//purpose :
228//=======================================================================
229
230void TDataStd_IntegerArray::Paste (const Handle(TDF_Attribute)& Into,
231 const Handle(TDF_RelocationTable)& ) const
232{
233
234 if(!myValue.IsNull()) {
235 Handle(TDataStd_IntegerArray) anAtt = Handle(TDataStd_IntegerArray)::DownCast(Into);
236 if(!anAtt.IsNull()) {
237 anAtt->ChangeArray( myValue, Standard_False );
238 anAtt->SetDelta(myIsDelta);
239 }
240 }
241}
242
243//=======================================================================
244//function : Dump
245//purpose :
246//=======================================================================
247
248Standard_OStream& TDataStd_IntegerArray::Dump (Standard_OStream& anOS) const
249{
250 anOS << "\nIntegerArray:: " << this <<" :";
251 if(!myValue.IsNull()) {
252 Standard_Integer i, lower, upper;
253 lower = myValue->Lower();
254 upper = myValue->Upper();
255 for(i = lower; i<=upper; i++)
256 anOS << " " <<myValue->Value(i);
257 }
eb901da6 258 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
7fd59977 259 anOS << endl;
260
261 // anOS <<"\nAttribute fields: ";
262 // anOS << TDF_Attribute::Dump(anOS);
263
264 return anOS;
265}
266
267//=======================================================================
268//function : DeltaOnModification
269//purpose :
270//=======================================================================
271
272Handle(TDF_DeltaOnModification) TDataStd_IntegerArray::DeltaOnModification
273(const Handle(TDF_Attribute)& OldAttribute) const
274{
275 if(myIsDelta)
276 return new TDataStd_DeltaOnModificationOfIntArray(*((Handle(TDataStd_IntegerArray)*)&OldAttribute));
277 else return new TDF_DefaultDeltaOnModification(OldAttribute);
278}
279
280