0026912: CLang 3.6.2 compiler warning [-Winconsistent-missing-override]
[occt.git] / src / TDataStd / TDataStd_ByteArray.cxx
1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-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 <TDataStd_ByteArray.hxx>
20 #include <TDataStd_DeltaOnModificationOfByteArray.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_DefaultDeltaOnModification.hxx>
23 #include <TDF_DeltaOnModification.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDF_RelocationTable.hxx>
26
27 //=======================================================================
28 //function : GetID
29 //purpose  : 
30 //=======================================================================
31 const Standard_GUID& TDataStd_ByteArray::GetID() 
32
33   static Standard_GUID TDataStd_ByteArrayID ("FD9B918F-2980-4c66-85E0-D71965475290");
34   return TDataStd_ByteArrayID; 
35 }
36
37 //=======================================================================
38 //function : TDataStd_ByteArray
39 //purpose  : Empty Constructor
40 //=======================================================================
41 TDataStd_ByteArray::TDataStd_ByteArray() : myIsDelta(Standard_False){}
42
43
44 //=======================================================================
45 //function : Init
46 //purpose  : 
47 //=======================================================================
48 void TDataStd_ByteArray::Init(const Standard_Integer lower,
49                               const Standard_Integer upper)
50 {
51   Backup();
52
53   if (upper >= lower)
54     myValue = new TColStd_HArray1OfByte(lower, upper, 0x00);
55 }
56
57 //=======================================================================
58 //function : Set
59 //purpose  : 
60 //=======================================================================
61 Handle(TDataStd_ByteArray) TDataStd_ByteArray::Set(const TDF_Label&       label,
62                                                    const Standard_Integer lower,
63                                                    const Standard_Integer upper,
64                                                  const Standard_Boolean isDelta) 
65 {
66   Handle(TDataStd_ByteArray) A;
67   if (!label.FindAttribute (TDataStd_ByteArray::GetID(), A)) 
68   {
69     A = new TDataStd_ByteArray;
70     A->Init (lower, upper);
71     A->SetDelta(isDelta); 
72     label.AddAttribute(A);
73   }
74   return A;
75 }
76
77 //=======================================================================
78 //function : SetValue
79 //purpose  : 
80 //=======================================================================
81 void TDataStd_ByteArray::SetValue (const Standard_Integer index,
82                                    const Standard_Byte value) 
83 {
84   if (myValue.IsNull()) 
85     return;
86   if (value == myValue->Value(index))
87     return;
88   Backup();
89
90   myValue->SetValue(index, value);
91 }
92
93 //=======================================================================
94 //function : Value
95 //purpose  : 
96 //=======================================================================
97 Standard_Byte TDataStd_ByteArray::Value (const Standard_Integer index) const 
98 {
99   return myValue->Value(index);
100 }
101
102 //=======================================================================
103 //function : Lower
104 //purpose  : 
105 //=======================================================================
106 Standard_Integer TDataStd_ByteArray::Lower (void) const 
107
108   if (myValue.IsNull())
109     return 0;
110   return myValue->Lower();
111 }
112
113 //=======================================================================
114 //function : Upper
115 //purpose  : 
116 //=======================================================================
117 Standard_Integer TDataStd_ByteArray::Upper (void) const 
118
119   if (myValue.IsNull())  return -1;
120   return myValue->Upper();
121 }
122
123 //=======================================================================
124 //function : Length
125 //purpose  : 
126 //=======================================================================
127 Standard_Integer TDataStd_ByteArray::Length (void) const 
128 {
129   if (myValue.IsNull())
130     return 0;
131   return myValue->Length();
132 }
133
134 //=======================================================================
135 //function : ChangeArray
136 //purpose  : If value of <newArray> differs from <myValue>, Backup 
137 //         : performed and myValue refers to new instance of HArray1OfByte 
138 //         : that holds <newArray>
139 //=======================================================================
140 void TDataStd_ByteArray::ChangeArray (const Handle(TColStd_HArray1OfByte)& newArray,
141                                       const Standard_Boolean isCheckItems)
142 {
143
144   Standard_Integer aLower    = newArray->Lower();
145   Standard_Integer anUpper   = newArray->Upper();
146   Standard_Boolean aDimEqual = Standard_False;
147   Standard_Integer i;
148
149   if ( Lower() == aLower && Upper() == anUpper ) {
150     aDimEqual = Standard_True;
151     if(isCheckItems) {
152       Standard_Boolean isEqual = Standard_True;
153       for(i = aLower; i <= anUpper; i++) {
154         if(myValue->Value(i) != newArray->Value(i)) {
155           isEqual = Standard_False;
156           break;
157         }
158       }
159       if(isEqual)
160         return;
161     }
162   }
163   
164   Backup();
165 // Handles of myValue of current and backuped attributes will be different!
166   if(myValue.IsNull() || !aDimEqual) 
167     myValue = new TColStd_HArray1OfByte(aLower, anUpper);  
168
169   for(i = aLower; i <= anUpper; i++) 
170     myValue->SetValue(i, newArray->Value(i));
171 }
172
173 //=======================================================================
174 //function : ID
175 //purpose  : 
176 //=======================================================================
177 const Standard_GUID& TDataStd_ByteArray::ID () const 
178
179   return GetID(); 
180 }
181
182 //=======================================================================
183 //function : NewEmpty
184 //purpose  : 
185 //=======================================================================
186 Handle(TDF_Attribute) TDataStd_ByteArray::NewEmpty () const
187 {  
188   return new TDataStd_ByteArray(); 
189 }
190
191 //=======================================================================
192 //function : Restore
193 //purpose  : 
194 //=======================================================================
195 void TDataStd_ByteArray::Restore(const Handle(TDF_Attribute)& With) 
196 {
197   Handle(TDataStd_ByteArray) anArray = Handle(TDataStd_ByteArray)::DownCast(With);
198   if (!anArray->myValue.IsNull()) 
199   {
200     const TColStd_Array1OfByte& with_array = anArray->myValue->Array1();
201     Standard_Integer lower = with_array.Lower(), i = lower, upper = with_array.Upper();
202     myValue = new TColStd_HArray1OfByte(lower, upper);
203     for (; i <= upper; i++)
204       myValue->SetValue(i, with_array.Value(i));
205     myIsDelta = anArray->myIsDelta;
206   }
207   else
208     myValue.Nullify();
209 }
210
211 //=======================================================================
212 //function : Paste
213 //purpose  : 
214 //=======================================================================
215 void TDataStd_ByteArray::Paste (const Handle(TDF_Attribute)& Into,
216                                 const Handle(TDF_RelocationTable)& ) const
217 {
218   if (!myValue.IsNull()) 
219   {
220     Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(Into);
221     if (!anAtt.IsNull())
222     {
223       anAtt->ChangeArray( myValue, Standard_False);
224       anAtt->SetDelta(myIsDelta);
225     }
226   }
227 }
228
229 //=======================================================================
230 //function : Dump
231 //purpose  : 
232 //=======================================================================
233 Standard_OStream& TDataStd_ByteArray::Dump (Standard_OStream& anOS) const
234 {  
235   anOS << "ByteArray";
236   return anOS;
237 }
238
239 //=======================================================================
240 //function : DeltaOnModification
241 //purpose  : 
242 //=======================================================================
243
244 Handle(TDF_DeltaOnModification) TDataStd_ByteArray::DeltaOnModification
245 (const Handle(TDF_Attribute)& OldAttribute) const
246 {
247   if(myIsDelta)
248     return new TDataStd_DeltaOnModificationOfByteArray(Handle(TDataStd_ByteArray)::DownCast (OldAttribute));
249   else return new TDF_DefaultDeltaOnModification(OldAttribute);
250 }
251