0024129: Eliminate remaining compiler warnings in MSVC++ 2008 32 bit with warning...
[occt.git] / src / TDataStd / TDataStd_ReferenceArray.cxx
CommitLineData
b311480e 1// Created on: 2007-05-29
2// Created by: Vlad Romashko
3// Copyright (c) 2007-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <TDataStd_ReferenceArray.ixx>
22
23//=======================================================================
24//function : GetID
25//purpose :
26//=======================================================================
27const Standard_GUID& TDataStd_ReferenceArray::GetID()
28{
29 static Standard_GUID TDataStd_ReferenceArrayID ("7EE745A6-BB50-446c-BB0B-C195B23AB5CA");
30 return TDataStd_ReferenceArrayID;
31}
32
33//=======================================================================
34//function : TDataStd_ReferenceArray
35//purpose : Empty Constructor
36//=======================================================================
37TDataStd_ReferenceArray::TDataStd_ReferenceArray()
38{
39
40}
41
42//=======================================================================
43//function : Init
44//purpose :
45//=======================================================================
46void TDataStd_ReferenceArray::Init(const Standard_Integer lower,
47 const Standard_Integer upper)
48{
a855b7eb 49 Standard_RangeError_Raise_if(upper < lower,"TDataStd_ReferenceArray::Init");
7fd59977 50 Backup();
a855b7eb 51 myArray = new TDataStd_HLabelArray1(lower, upper);
7fd59977 52}
53
54//=======================================================================
55//function : Set
56//purpose :
57//=======================================================================
58Handle(TDataStd_ReferenceArray) TDataStd_ReferenceArray::Set(const TDF_Label& label,
59 const Standard_Integer lower,
60 const Standard_Integer upper)
61{
62 Handle(TDataStd_ReferenceArray) A;
63 if (!label.FindAttribute (TDataStd_ReferenceArray::GetID(), A))
64 {
65 A = new TDataStd_ReferenceArray;
66 A->Init (lower, upper);
67 label.AddAttribute(A);
68 }
69 else if (lower != A->Lower() || upper != A->Upper())
70 {
71 A->Init(lower, upper);
72 }
73 return A;
74}
75
76//=======================================================================
77//function : SetValue
78//purpose :
79//=======================================================================
80void TDataStd_ReferenceArray::SetValue (const Standard_Integer index,
81 const TDF_Label& value)
82{
fa13a85d 83 if(myArray.IsNull()) return;
7fd59977 84 if (value == myArray->Value(index))
85 return;
7fd59977 86 Backup();
87
88 myArray->SetValue(index, value);
89}
90
91//=======================================================================
92//function : Value
93//purpose :
94//=======================================================================
95TDF_Label TDataStd_ReferenceArray::Value (const Standard_Integer index) const
96{
97 return myArray->Value(index);
98}
99
100//=======================================================================
101//function : Lower
102//purpose :
103//=======================================================================
104Standard_Integer TDataStd_ReferenceArray::Lower () const
105{
106 if (myArray.IsNull())
107 return 0;
108 return myArray->Lower();
109}
110
111//=======================================================================
112//function : Upper
113//purpose :
114//=======================================================================
115Standard_Integer TDataStd_ReferenceArray::Upper () const
116{
117 if (myArray.IsNull())
118 return -1;
119 return myArray->Upper();
120}
121
122//=======================================================================
123//function : Length
124//purpose :
125//=======================================================================
126Standard_Integer TDataStd_ReferenceArray::Length () const
127{
128 if (myArray.IsNull())
129 return 0;
130 return myArray->Length();
131}
132
133//=======================================================================
134//function : InternalArray
135//purpose :
136//=======================================================================
137const Handle(TDataStd_HLabelArray1)& TDataStd_ReferenceArray::InternalArray () const
138{
139 return myArray;
140}
141
142//=======================================================================
143//function : SetInternalArray
144//purpose :
145//=======================================================================
a855b7eb 146void TDataStd_ReferenceArray::SetInternalArray (const Handle(TDataStd_HLabelArray1)& values,
498ce76b 147 const Standard_Boolean)
7fd59977 148{
a855b7eb
S
149// myArray = values;
150 Standard_Integer aLower = values->Lower();
151 Standard_Integer anUpper = values->Upper();
152 Standard_Boolean aDimEqual = Standard_False;
153 Standard_Integer i;
154
155#ifdef OCC2932
156 if (Lower() == aLower && Upper() == anUpper ) {
157 aDimEqual = Standard_True;
158 Standard_Boolean isEqual = Standard_True;
159 if(isCheckItems) {
160 for(i = aLower; i <= anUpper; i++) {
161 if(myArray->Value(i) != values->Value(i)) {
162 isEqual = Standard_False;
163 break;
164 }
165 }
166 if(isEqual)
167 return;
168 }
169 }
170#endif
171
172 Backup();
173
174 if(myArray.IsNull() || !aDimEqual)
175 myArray = new TDataStd_HLabelArray1(aLower, anUpper);
176
177 for(i = aLower; i <= anUpper; i++)
178 myArray->SetValue(i, values->Value(i));
7fd59977 179}
180
181//=======================================================================
182//function : ID
183//purpose :
184//=======================================================================
185const Standard_GUID& TDataStd_ReferenceArray::ID () const
186{
a855b7eb 187 return GetID();
7fd59977 188}
189
190//=======================================================================
191//function : NewEmpty
192//purpose :
193//=======================================================================
194Handle(TDF_Attribute) TDataStd_ReferenceArray::NewEmpty () const
195{
196 return new TDataStd_ReferenceArray();
197}
198
199//=======================================================================
200//function : Restore
201//purpose :
202//=======================================================================
203void TDataStd_ReferenceArray::Restore(const Handle(TDF_Attribute)& With)
204{
205 Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(With);
206 if (!anArray->myArray.IsNull())
207 {
208 const TDataStd_LabelArray1& arr = anArray->myArray->Array1();
209 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
210 Init(lower, upper);
211 for (; i <= upper; i++)
212 {
213 myArray->SetValue(i, arr.Value(i));
214 }
215 }
216 else
217 {
218 myArray.Nullify();
219 }
220}
221
222//=======================================================================
223//function : Paste
224//purpose :
225//=======================================================================
226void TDataStd_ReferenceArray::Paste (const Handle(TDF_Attribute)& Into,
227 const Handle(TDF_RelocationTable)& RT) const
228{
229 Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(Into);
230 if (myArray.IsNull())
231 {
232 anArray->myArray.Nullify();
233 return;
234 }
235 const TDataStd_LabelArray1& arr = myArray->Array1();
236 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
237 if (lower != anArray->Lower() || upper != anArray->Upper())
238 anArray->Init(lower, upper);
239 for (; i <= upper; i++)
240 {
241 TDF_Label L = arr.Value(i), rL;
242 if (!L.IsNull())
243 {
244 if (!RT->HasRelocation(L, rL))
245 rL = L;
246 anArray->myArray->SetValue(i, rL);
247 }
248 }
249}
250
251//=======================================================================
252//function : References
253//purpose : Adds the referenced attributes or labels.
254//=======================================================================
255void TDataStd_ReferenceArray::References(const Handle(TDF_DataSet)& aDataSet) const
256{
257 if (!Label().IsImported() && !myArray.IsNull())
258 {
259 const TDataStd_LabelArray1& arr = myArray->Array1();
260 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
261 for (; i <= upper; i++)
262 {
263 if (!arr.Value(i).IsNull())
264 aDataSet->AddLabel(arr.Value(i));
265 }
266 }
267}
268
269//=======================================================================
270//function : Dump
271//purpose :
272//=======================================================================
273Standard_OStream& TDataStd_ReferenceArray::Dump (Standard_OStream& anOS) const
274{
275 anOS << "ReferenceArray";
276 return anOS;
277}