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 //=======================================================================
102 //function : GetValue
104 //=======================================================================
106 TCollection_ExtendedString TDataStd_ExtStringArray::Value (const Standard_Integer index) const
108 if(myValue.IsNull()) return TCollection_ExtendedString();
109 return myValue->Value(index);
114 //=======================================================================
117 //=======================================================================
118 Standard_Integer TDataStd_ExtStringArray::Lower (void) const
120 if(myValue.IsNull()) return 0;
121 return myValue->Lower();
125 //=======================================================================
128 //=======================================================================
129 Standard_Integer TDataStd_ExtStringArray::Upper (void) const
131 if(myValue.IsNull()) return 0;
132 return myValue->Upper();
136 //=======================================================================
139 //=======================================================================
140 Standard_Integer TDataStd_ExtStringArray::Length (void) const
142 if(myValue.IsNull()) return 0;
143 return myValue->Length();
148 //=======================================================================
149 //function : ChangeArray
150 //purpose : If value of <newArray> differs from <myValue>, Backup
151 // : performed and myValue refers to new instance of HArray1OfExtendedString
152 // : that holds <newArray>
153 //=======================================================================
155 void TDataStd_ExtStringArray::ChangeArray(const Handle(TColStd_HArray1OfExtendedString)& newArray,
156 const Standard_Boolean isCheckItems)
158 Standard_Integer aLower = newArray->Lower();
159 Standard_Integer anUpper = newArray->Upper();
160 Standard_Boolean aDimEqual = Standard_False;
163 if (Lower() == aLower && Upper() == anUpper ) {
164 aDimEqual = Standard_True;
165 Standard_Boolean isEqual = Standard_True;
167 for(i = aLower; i <= anUpper; i++) {
168 if(myValue->Value(i) != newArray->Value(i)) {
169 isEqual = Standard_False;
180 // Handles of myValue of current and backuped attributes will be different!!!
181 if(myValue.IsNull() || !aDimEqual)
182 myValue = new TColStd_HArray1OfExtendedString(aLower, anUpper);
184 for(i = aLower; i <= anUpper; i++)
185 myValue->SetValue(i, newArray->Value(i));
188 //=======================================================================
191 //=======================================================================
193 const Standard_GUID& TDataStd_ExtStringArray::ID () const { return GetID(); }
196 //=======================================================================
197 //function : NewEmpty
199 //=======================================================================
201 Handle(TDF_Attribute) TDataStd_ExtStringArray::NewEmpty () const
203 return new TDataStd_ExtStringArray();
206 //=======================================================================
209 //=======================================================================
211 void TDataStd_ExtStringArray::Restore(const Handle(TDF_Attribute)& With)
213 Standard_Integer i, lower, upper;
214 Handle(TDataStd_ExtStringArray) anArray = Handle(TDataStd_ExtStringArray)::DownCast(With);
215 if(!anArray->myValue.IsNull()) {
216 lower = anArray->Lower();
217 upper = anArray->Upper();
218 myValue = new TColStd_HArray1OfExtendedString(lower, upper);
219 for(i = lower; i<=upper; i++)
220 myValue->SetValue(i, anArray->Value(i));
221 myIsDelta = anArray->myIsDelta;
227 //=======================================================================
230 //=======================================================================
232 void TDataStd_ExtStringArray::Paste (const Handle(TDF_Attribute)& Into,
233 const Handle(TDF_RelocationTable)& ) const
235 if(!myValue.IsNull()) {
236 Handle(TDataStd_ExtStringArray) anAtt = Handle(TDataStd_ExtStringArray)::DownCast(Into);
237 if(!anAtt.IsNull()) {
238 anAtt->ChangeArray( myValue, Standard_False );
239 anAtt->SetDelta(myIsDelta);
244 //=======================================================================
247 //=======================================================================
249 Standard_OStream& TDataStd_ExtStringArray::Dump (Standard_OStream& anOS) const
251 anOS << "ExtStringArray :";
252 if(!myValue.IsNull()) {
253 Standard_Integer i, lower, upper;
254 lower = myValue->Lower();
255 upper = myValue->Upper();
256 for(i = lower; i<=upper; i++)
257 anOS << "\t" <<myValue->Value(i)<<endl;
259 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
264 //=======================================================================
265 //function : DeltaOnModification
267 //=======================================================================
269 Handle(TDF_DeltaOnModification) TDataStd_ExtStringArray::DeltaOnModification
270 (const Handle(TDF_Attribute)& OldAttribute) const
273 return new TDataStd_DeltaOnModificationOfExtStringArray(*((Handle(TDataStd_ExtStringArray)*)&OldAttribute));
274 else return new TDF_DefaultDeltaOnModification(OldAttribute);