0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / TDataStd / TDataStd_ExtStringArray.cxx
1 // Created on: 2002-01-16
2 // Created by: Michael PONIKAROV
3 // Copyright (c) 2002-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
20
21
22 #include <TDataStd_ExtStringArray.ixx>
23 #include <TDataStd_DeltaOnModificationOfExtStringArray.hxx>
24 #include <TDF_DefaultDeltaOnModification.hxx>
25
26 //=======================================================================
27 //function : GetID
28 //purpose  : 
29 //=======================================================================
30
31 const Standard_GUID& TDataStd_ExtStringArray::GetID() 
32
33   static Standard_GUID anExtStringArrayID ("2a96b624-ec8b-11d0-bee7-080009dc3333");
34   return anExtStringArrayID; 
35 }
36
37
38 //=======================================================================
39 //function : TDataStd_ExtStringArray::TDataStd_ExtStringArray
40 //purpose  : 
41 //=======================================================================
42
43 TDataStd_ExtStringArray::TDataStd_ExtStringArray() 
44     : myIsDelta(Standard_False){}
45      
46 //=======================================================================
47 //function : Init
48 //purpose  : 
49 //=======================================================================
50
51 void TDataStd_ExtStringArray::Init(const Standard_Integer lower,
52                                 const Standard_Integer upper)
53 {
54   Backup();
55   myValue = new TColStd_HArray1OfExtendedString(lower, upper, "");
56 }
57
58 //=======================================================================
59 //function : Set
60 //purpose  : 
61 //=======================================================================
62
63 Handle(TDataStd_ExtStringArray) TDataStd_ExtStringArray::Set (
64                                           const TDF_Label& label,
65                                           const Standard_Integer lower,
66                                           const Standard_Integer upper,
67                                           const Standard_Boolean isDelta) 
68
69 {
70   Handle(TDataStd_ExtStringArray) A;
71   if (!label.FindAttribute (TDataStd_ExtStringArray::GetID(), A)) {
72     A = new TDataStd_ExtStringArray;
73     A->Init (lower, upper);
74     A->SetDelta(isDelta); 
75     label.AddAttribute(A);
76   }
77   else if (lower != A->Lower() || upper != A->Upper())
78   {
79     A->Init (lower, upper); 
80   }
81   return A;
82 }
83
84
85 //=======================================================================
86 //function : SetValue
87 //purpose  : 
88 //=======================================================================
89
90 void TDataStd_ExtStringArray::SetValue(const Standard_Integer index, const TCollection_ExtendedString& value) 
91 {
92   if(myValue.IsNull()) return;
93   if( myValue->Value(index) == value)
94     return; 
95
96   Backup();
97   myValue->SetValue(index, value);
98 }
99
100
101 //=======================================================================
102 //function : Value
103 //purpose  : 
104 //=======================================================================
105
106 const TCollection_ExtendedString& TDataStd_ExtStringArray::Value (const Standard_Integer index) const 
107 {
108     if (myValue.IsNull()) 
109     {
110         static TCollection_ExtendedString staticEmptyValue;
111         return staticEmptyValue;
112     }
113     return myValue->Value(index); 
114 }
115
116 //=======================================================================
117 //function : Lower
118 //purpose  : 
119 //=======================================================================
120 Standard_Integer TDataStd_ExtStringArray::Lower (void) const 
121
122   if(myValue.IsNull()) return 0;
123   return myValue->Lower(); 
124 }
125
126
127 //=======================================================================
128 //function : Upper
129 //purpose  : 
130 //=======================================================================
131 Standard_Integer TDataStd_ExtStringArray::Upper (void) const 
132
133   if(myValue.IsNull()) return 0;
134   return myValue->Upper(); 
135 }
136
137
138 //=======================================================================
139 //function : Length
140 //purpose  : 
141 //=======================================================================
142 Standard_Integer TDataStd_ExtStringArray::Length (void) const 
143 {
144   if(myValue.IsNull()) return 0;
145   return myValue->Length(); 
146 }
147
148
149
150 //=======================================================================
151 //function : ChangeArray
152 //purpose  : If value of <newArray> differs from <myValue>, Backup 
153 //         : performed and myValue refers to new instance of HArray1OfExtendedString
154 //         : that holds <newArray>
155 //=======================================================================
156
157 void TDataStd_ExtStringArray::ChangeArray(const Handle(TColStd_HArray1OfExtendedString)& newArray,
158                                           const Standard_Boolean isCheckItems) 
159 {
160   Standard_Integer aLower    = newArray->Lower();
161   Standard_Integer anUpper   = newArray->Upper();
162   Standard_Boolean aDimEqual = Standard_False;
163   Standard_Integer i;
164
165   if (Lower() == aLower && Upper() == anUpper ) {
166     aDimEqual = Standard_True;
167     Standard_Boolean isEqual = Standard_True;
168     if(isCheckItems) {
169       for(i = aLower; i <= anUpper; i++) {
170         if(myValue->Value(i) != newArray->Value(i)) {
171           isEqual = Standard_False;
172           break;
173         }
174       }
175       if(isEqual)
176         return;
177     }
178   }
179
180   Backup();
181
182 // Handles of myValue of current and backuped attributes will be different!!!
183   if(myValue.IsNull() || !aDimEqual) 
184     myValue = new TColStd_HArray1OfExtendedString(aLower, anUpper);
185
186   for(i = aLower; i <= anUpper; i++) 
187     myValue->SetValue(i, newArray->Value(i));
188 }
189
190 //=======================================================================
191 //function : ID
192 //purpose  : 
193 //=======================================================================
194
195 const Standard_GUID& TDataStd_ExtStringArray::ID () const { return GetID(); }
196
197
198 //=======================================================================
199 //function : NewEmpty
200 //purpose  : 
201 //=======================================================================
202
203 Handle(TDF_Attribute) TDataStd_ExtStringArray::NewEmpty () const
204 {  
205   return new TDataStd_ExtStringArray(); 
206 }
207
208 //=======================================================================
209 //function : Restore
210 //purpose  : 
211 //=======================================================================
212
213 void TDataStd_ExtStringArray::Restore(const Handle(TDF_Attribute)& With) 
214 {
215   Standard_Integer i, lower, upper;
216   Handle(TDataStd_ExtStringArray) anArray = Handle(TDataStd_ExtStringArray)::DownCast(With);
217   if(!anArray->myValue.IsNull()) {
218     lower = anArray->Lower();
219     upper = anArray->Upper(); 
220     myValue = new TColStd_HArray1OfExtendedString(lower, upper);
221     for(i = lower; i<=upper; i++)
222       myValue->SetValue(i, anArray->Value(i));
223     myIsDelta = anArray->myIsDelta;
224   }
225   else
226     myValue.Nullify();
227 }
228
229 //=======================================================================
230 //function : Paste
231 //purpose  : 
232 //=======================================================================
233
234 void TDataStd_ExtStringArray::Paste (const Handle(TDF_Attribute)& Into,
235                                    const Handle(TDF_RelocationTable)& ) const
236 {
237   if(!myValue.IsNull()) {
238     Handle(TDataStd_ExtStringArray) anAtt = Handle(TDataStd_ExtStringArray)::DownCast(Into);
239     if(!anAtt.IsNull()) {
240       anAtt->ChangeArray( myValue, Standard_False );
241       anAtt->SetDelta(myIsDelta);
242     }
243   }
244 }
245
246 //=======================================================================
247 //function : Dump
248 //purpose  : 
249 //=======================================================================
250
251 Standard_OStream& TDataStd_ExtStringArray::Dump (Standard_OStream& anOS) const
252 {  
253   anOS << "ExtStringArray :";
254   if(!myValue.IsNull()) {
255     Standard_Integer i, lower, upper;
256     lower = myValue->Lower();
257     upper = myValue->Upper();
258     for(i = lower; i<=upper; i++)
259       anOS << "\t" <<myValue->Value(i)<<endl;
260   }
261   anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
262   anOS << endl;
263   return anOS;
264 }
265
266 //=======================================================================
267 //function : DeltaOnModification
268 //purpose  : 
269 //=======================================================================
270
271 Handle(TDF_DeltaOnModification) TDataStd_ExtStringArray::DeltaOnModification
272 (const Handle(TDF_Attribute)& OldAttribute) const
273 {
274   if(myIsDelta)
275     return new TDataStd_DeltaOnModificationOfExtStringArray(*((Handle(TDataStd_ExtStringArray)*)&OldAttribute));
276   else return new TDF_DefaultDeltaOnModification(OldAttribute);
277 }
278