1 // Created on: 2002-01-16
2 // Created by: Michael PONIKAROV
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <TDataStd_ExtStringArray.ixx>
23 #include <TDataStd_DeltaOnModificationOfExtStringArray.hxx>
24 #include <TDF_DefaultDeltaOnModification.hxx>
26 //=======================================================================
29 //=======================================================================
31 const Standard_GUID& TDataStd_ExtStringArray::GetID()
33 static Standard_GUID anExtStringArrayID ("2a96b624-ec8b-11d0-bee7-080009dc3333");
34 return anExtStringArrayID;
38 //=======================================================================
39 //function : TDataStd_ExtStringArray::TDataStd_ExtStringArray
41 //=======================================================================
43 TDataStd_ExtStringArray::TDataStd_ExtStringArray()
44 : myIsDelta(Standard_False){}
46 //=======================================================================
49 //=======================================================================
51 void TDataStd_ExtStringArray::Init(const Standard_Integer lower,
52 const Standard_Integer upper)
55 myValue = new TColStd_HArray1OfExtendedString(lower, upper, "");
58 //=======================================================================
61 //=======================================================================
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)
70 Handle(TDataStd_ExtStringArray) A;
71 if (!label.FindAttribute (TDataStd_ExtStringArray::GetID(), A)) {
72 A = new TDataStd_ExtStringArray;
73 A->Init (lower, upper);
75 label.AddAttribute(A);
77 else if (lower != A->Lower() || upper != A->Upper())
79 A->Init (lower, upper);
85 //=======================================================================
88 //=======================================================================
90 void TDataStd_ExtStringArray::SetValue(const Standard_Integer index, const TCollection_ExtendedString& value)
92 if(myValue.IsNull()) return;
93 if( myValue->Value(index) == value)
97 myValue->SetValue(index, value);
101 //=======================================================================
104 //=======================================================================
106 const TCollection_ExtendedString& TDataStd_ExtStringArray::Value (const Standard_Integer index) const
108 if (myValue.IsNull())
110 static TCollection_ExtendedString staticEmptyValue;
111 return staticEmptyValue;
113 return myValue->Value(index);
116 //=======================================================================
119 //=======================================================================
120 Standard_Integer TDataStd_ExtStringArray::Lower (void) const
122 if(myValue.IsNull()) return 0;
123 return myValue->Lower();
127 //=======================================================================
130 //=======================================================================
131 Standard_Integer TDataStd_ExtStringArray::Upper (void) const
133 if(myValue.IsNull()) return 0;
134 return myValue->Upper();
138 //=======================================================================
141 //=======================================================================
142 Standard_Integer TDataStd_ExtStringArray::Length (void) const
144 if(myValue.IsNull()) return 0;
145 return myValue->Length();
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 //=======================================================================
157 void TDataStd_ExtStringArray::ChangeArray(const Handle(TColStd_HArray1OfExtendedString)& newArray,
158 const Standard_Boolean isCheckItems)
160 Standard_Integer aLower = newArray->Lower();
161 Standard_Integer anUpper = newArray->Upper();
162 Standard_Boolean aDimEqual = Standard_False;
165 if (Lower() == aLower && Upper() == anUpper ) {
166 aDimEqual = Standard_True;
167 Standard_Boolean isEqual = Standard_True;
169 for(i = aLower; i <= anUpper; i++) {
170 if(myValue->Value(i) != newArray->Value(i)) {
171 isEqual = Standard_False;
182 // Handles of myValue of current and backuped attributes will be different!!!
183 if(myValue.IsNull() || !aDimEqual)
184 myValue = new TColStd_HArray1OfExtendedString(aLower, anUpper);
186 for(i = aLower; i <= anUpper; i++)
187 myValue->SetValue(i, newArray->Value(i));
190 //=======================================================================
193 //=======================================================================
195 const Standard_GUID& TDataStd_ExtStringArray::ID () const { return GetID(); }
198 //=======================================================================
199 //function : NewEmpty
201 //=======================================================================
203 Handle(TDF_Attribute) TDataStd_ExtStringArray::NewEmpty () const
205 return new TDataStd_ExtStringArray();
208 //=======================================================================
211 //=======================================================================
213 void TDataStd_ExtStringArray::Restore(const Handle(TDF_Attribute)& With)
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;
229 //=======================================================================
232 //=======================================================================
234 void TDataStd_ExtStringArray::Paste (const Handle(TDF_Attribute)& Into,
235 const Handle(TDF_RelocationTable)& ) const
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);
246 //=======================================================================
249 //=======================================================================
251 Standard_OStream& TDataStd_ExtStringArray::Dump (Standard_OStream& anOS) const
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;
261 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
266 //=======================================================================
267 //function : DeltaOnModification
269 //=======================================================================
271 Handle(TDF_DeltaOnModification) TDataStd_ExtStringArray::DeltaOnModification
272 (const Handle(TDF_Attribute)& OldAttribute) const
275 return new TDataStd_DeltaOnModificationOfExtStringArray(*((Handle(TDataStd_ExtStringArray)*)&OldAttribute));
276 else return new TDF_DefaultDeltaOnModification(OldAttribute);