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