1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-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.
21 #include <TDataStd_ByteArray.ixx>
22 #include <TDataStd_DeltaOnModificationOfByteArray.hxx>
23 #include <TDF_DefaultDeltaOnModification.hxx>
25 //=======================================================================
28 //=======================================================================
29 const Standard_GUID& TDataStd_ByteArray::GetID()
31 static Standard_GUID TDataStd_ByteArrayID ("FD9B918F-2980-4c66-85E0-D71965475290");
32 return TDataStd_ByteArrayID;
35 //=======================================================================
36 //function : TDataStd_ByteArray
37 //purpose : Empty Constructor
38 //=======================================================================
39 TDataStd_ByteArray::TDataStd_ByteArray() : myIsDelta(Standard_False){}
42 //=======================================================================
45 //=======================================================================
46 void TDataStd_ByteArray::Init(const Standard_Integer lower,
47 const Standard_Integer upper)
52 myValue = new TColStd_HArray1OfByte(lower, upper, 0x00);
55 //=======================================================================
58 //=======================================================================
59 Handle(TDataStd_ByteArray) TDataStd_ByteArray::Set(const TDF_Label& label,
60 const Standard_Integer lower,
61 const Standard_Integer upper,
62 const Standard_Boolean isDelta)
64 Handle(TDataStd_ByteArray) A;
65 if (!label.FindAttribute (TDataStd_ByteArray::GetID(), A))
67 A = new TDataStd_ByteArray;
68 A->Init (lower, upper);
70 label.AddAttribute(A);
75 //=======================================================================
78 //=======================================================================
79 void TDataStd_ByteArray::SetValue (const Standard_Integer index,
80 const Standard_Byte value)
82 if (value == myValue->Value(index))
86 myValue->SetValue(index, value);
89 //=======================================================================
92 //=======================================================================
93 Standard_Byte TDataStd_ByteArray::Value (const Standard_Integer index) const
95 return myValue->Value(index);
98 //=======================================================================
101 //=======================================================================
102 Standard_Integer TDataStd_ByteArray::Lower (void) const
104 if (myValue.IsNull())
106 return myValue->Lower();
109 //=======================================================================
112 //=======================================================================
113 Standard_Integer TDataStd_ByteArray::Upper (void) const
115 if (myValue.IsNull()) return -1;
116 return myValue->Upper();
119 //=======================================================================
122 //=======================================================================
123 Standard_Integer TDataStd_ByteArray::Length (void) const
125 if (myValue.IsNull())
127 return myValue->Length();
130 //=======================================================================
131 //function : ChangeArray
132 //purpose : If value of <newArray> differs from <myValue>, Backup
133 // : performed and myValue refers to new instance of HArray1OfByte
134 // : that holds <newArray>
135 //=======================================================================
136 void TDataStd_ByteArray::ChangeArray (const Handle(TColStd_HArray1OfByte)& newArray,
137 const Standard_Boolean isCheckItems)
140 Standard_Integer aLower = newArray->Lower();
141 Standard_Integer anUpper = newArray->Upper();
142 Standard_Boolean aDimEqual = Standard_False;
145 if ( Lower() == aLower && Upper() == anUpper ) {
146 aDimEqual = Standard_True;
148 Standard_Boolean isEqual = Standard_True;
149 for(i = aLower; i <= anUpper; i++) {
150 if(myValue->Value(i) != newArray->Value(i)) {
151 isEqual = Standard_False;
161 // Handles of myValue of current and backuped attributes will be different!
162 if(myValue.IsNull() || !aDimEqual)
163 myValue = new TColStd_HArray1OfByte(aLower, anUpper);
165 for(i = aLower; i <= anUpper; i++)
166 myValue->SetValue(i, newArray->Value(i));
169 //=======================================================================
172 //=======================================================================
173 const Standard_GUID& TDataStd_ByteArray::ID () const
178 //=======================================================================
179 //function : NewEmpty
181 //=======================================================================
182 Handle(TDF_Attribute) TDataStd_ByteArray::NewEmpty () const
184 return new TDataStd_ByteArray();
187 //=======================================================================
190 //=======================================================================
191 void TDataStd_ByteArray::Restore(const Handle(TDF_Attribute)& With)
193 Handle(TDataStd_ByteArray) anArray = Handle(TDataStd_ByteArray)::DownCast(With);
194 if (!anArray->myValue.IsNull())
196 const TColStd_Array1OfByte& with_array = anArray->myValue->Array1();
197 Standard_Integer lower = with_array.Lower(), i = lower, upper = with_array.Upper();
198 myValue = new TColStd_HArray1OfByte(lower, upper);
199 for (; i <= upper; i++)
200 myValue->SetValue(i, with_array.Value(i));
201 myIsDelta = anArray->myIsDelta;
207 //=======================================================================
210 //=======================================================================
211 void TDataStd_ByteArray::Paste (const Handle(TDF_Attribute)& Into,
212 const Handle(TDF_RelocationTable)& ) const
214 if (!myValue.IsNull())
216 Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(Into);
219 anAtt->ChangeArray( myValue, Standard_False);
220 anAtt->SetDelta(myIsDelta);
225 //=======================================================================
228 //=======================================================================
229 Standard_OStream& TDataStd_ByteArray::Dump (Standard_OStream& anOS) const
235 //=======================================================================
236 //function : DeltaOnModification
238 //=======================================================================
240 Handle(TDF_DeltaOnModification) TDataStd_ByteArray::DeltaOnModification
241 (const Handle(TDF_Attribute)& OldAttribute) const
244 return new TDataStd_DeltaOnModificationOfByteArray(*((Handle(TDataStd_ByteArray)*)&OldAttribute));
245 else return new TDF_DefaultDeltaOnModification(OldAttribute);