1 // File: TDataStd_ByteArray.cxx
2 // Created: May 29 11:40:00 2007
3 // Author: Vlad Romashko
4 // <vladislav.romashko@opencascade.com>
5 //Copyright: Open CasCade SA 2007
7 #include <TDataStd_ByteArray.ixx>
8 #include <TDataStd_DeltaOnModificationOfByteArray.hxx>
9 #include <TDF_DefaultDeltaOnModification.hxx>
11 //=======================================================================
14 //=======================================================================
15 const Standard_GUID& TDataStd_ByteArray::GetID()
17 static Standard_GUID TDataStd_ByteArrayID ("FD9B918F-2980-4c66-85E0-D71965475290");
18 return TDataStd_ByteArrayID;
21 //=======================================================================
22 //function : TDataStd_ByteArray
23 //purpose : Empty Constructor
24 //=======================================================================
25 TDataStd_ByteArray::TDataStd_ByteArray() : myIsDelta(Standard_False){}
28 //=======================================================================
31 //=======================================================================
32 void TDataStd_ByteArray::Init(const Standard_Integer lower,
33 const Standard_Integer upper)
38 myValue = new TColStd_HArray1OfByte(lower, upper, 0x00);
41 //=======================================================================
44 //=======================================================================
45 Handle(TDataStd_ByteArray) TDataStd_ByteArray::Set(const TDF_Label& label,
46 const Standard_Integer lower,
47 const Standard_Integer upper,
48 const Standard_Boolean isDelta)
50 Handle(TDataStd_ByteArray) A;
51 if (!label.FindAttribute (TDataStd_ByteArray::GetID(), A))
53 A = new TDataStd_ByteArray;
54 A->Init (lower, upper);
56 label.AddAttribute(A);
61 //=======================================================================
64 //=======================================================================
65 void TDataStd_ByteArray::SetValue (const Standard_Integer index,
66 const Standard_Byte value)
68 if (value == myValue->Value(index))
72 myValue->SetValue(index, value);
75 //=======================================================================
78 //=======================================================================
79 Standard_Byte TDataStd_ByteArray::Value (const Standard_Integer index) const
81 return myValue->Value(index);
84 //=======================================================================
87 //=======================================================================
88 Standard_Integer TDataStd_ByteArray::Lower (void) const
92 return myValue->Lower();
95 //=======================================================================
98 //=======================================================================
99 Standard_Integer TDataStd_ByteArray::Upper (void) const
101 if (myValue.IsNull()) return -1;
102 return myValue->Upper();
105 //=======================================================================
108 //=======================================================================
109 Standard_Integer TDataStd_ByteArray::Length (void) const
111 if (myValue.IsNull())
113 return myValue->Length();
116 //=======================================================================
117 //function : ChangeArray
118 //purpose : If value of <newArray> differs from <myValue>, Backup
119 // : performed and myValue refers to new instance of HArray1OfByte
120 // : that holds <newArray>
121 //=======================================================================
122 void TDataStd_ByteArray::ChangeArray (const Handle(TColStd_HArray1OfByte)& newArray,
123 const Standard_Boolean isCheckItems)
126 Standard_Integer aLower = newArray->Lower();
127 Standard_Integer anUpper = newArray->Upper();
128 Standard_Boolean aDimEqual = Standard_False;
131 if ( Lower() == aLower && Upper() == anUpper ) {
132 aDimEqual = Standard_True;
134 Standard_Boolean isEqual = Standard_True;
135 for(i = aLower; i <= anUpper; i++) {
136 if(myValue->Value(i) != newArray->Value(i)) {
137 isEqual = Standard_False;
147 // Handles of myValue of current and backuped attributes will be different!
148 if(myValue.IsNull() || !aDimEqual)
149 myValue = new TColStd_HArray1OfByte(aLower, anUpper);
151 for(i = aLower; i <= anUpper; i++)
152 myValue->SetValue(i, newArray->Value(i));
155 //=======================================================================
158 //=======================================================================
159 const Standard_GUID& TDataStd_ByteArray::ID () const
164 //=======================================================================
165 //function : NewEmpty
167 //=======================================================================
168 Handle(TDF_Attribute) TDataStd_ByteArray::NewEmpty () const
170 return new TDataStd_ByteArray();
173 //=======================================================================
176 //=======================================================================
177 void TDataStd_ByteArray::Restore(const Handle(TDF_Attribute)& With)
179 Handle(TDataStd_ByteArray) anArray = Handle(TDataStd_ByteArray)::DownCast(With);
180 if (!anArray->myValue.IsNull())
182 const TColStd_Array1OfByte& with_array = anArray->myValue->Array1();
183 Standard_Integer lower = with_array.Lower(), i = lower, upper = with_array.Upper();
184 myValue = new TColStd_HArray1OfByte(lower, upper);
185 for (; i <= upper; i++)
186 myValue->SetValue(i, with_array.Value(i));
187 myIsDelta = anArray->myIsDelta;
193 //=======================================================================
196 //=======================================================================
197 void TDataStd_ByteArray::Paste (const Handle(TDF_Attribute)& Into,
198 const Handle(TDF_RelocationTable)& ) const
200 if (!myValue.IsNull())
202 Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(Into);
205 anAtt->ChangeArray( myValue, Standard_False);
206 anAtt->SetDelta(myIsDelta);
211 //=======================================================================
214 //=======================================================================
215 Standard_OStream& TDataStd_ByteArray::Dump (Standard_OStream& anOS) const
221 //=======================================================================
222 //function : DeltaOnModification
224 //=======================================================================
226 Handle(TDF_DeltaOnModification) TDataStd_ByteArray::DeltaOnModification
227 (const Handle(TDF_Attribute)& OldAttribute) const
230 return new TDataStd_DeltaOnModificationOfByteArray(*((Handle(TDataStd_ByteArray)*)&OldAttribute));
231 else return new TDF_DefaultDeltaOnModification(OldAttribute);