0023947: Eliminate trivial compiler warnings in MSVC++ with warning level 4
[occt.git] / src / TDataStd / TDataStd_DeltaOnModificationOfByteArray.cxx
1 // Created on: 2007-12-05
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20
21 #include <TDataStd_DeltaOnModificationOfByteArray.ixx>
22 #include <TDataStd_ByteArray.hxx>
23 #include <TDF_DeltaOnModification.hxx>
24 #include <TDF_Label.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <TColStd_HArray1OfByte.hxx>
27 #include <TColStd_ListOfInteger.hxx>
28 #include <TColStd_ListIteratorOfListOfInteger.hxx>
29 #include <TDF_AttributeIterator.hxx>
30
31 #ifdef DEB
32 #define MAXUP 1000
33 #endif
34 //=======================================================================
35 //function : TDataStd_DeltaOnModificationOfByteArray
36 //purpose  : 
37 //=======================================================================
38
39 TDataStd_DeltaOnModificationOfByteArray::TDataStd_DeltaOnModificationOfByteArray(const Handle(TDataStd_ByteArray)& OldAtt)
40 : TDF_DeltaOnModification(OldAtt)
41 {
42   Handle(TDataStd_ByteArray) CurrAtt;
43   if (Label().FindAttribute(OldAtt->ID(),CurrAtt)) {
44     {
45       Handle(TColStd_HArray1OfByte) Arr1, Arr2;
46       Arr1 = OldAtt->InternalArray();
47       Arr2 = CurrAtt->InternalArray();
48 #ifdef DEB_DELTA
49       if(Arr1.IsNull())
50         cout <<"DeltaOnModificationOfByteArray:: Old ByteArray is Null" <<endl;
51       if(Arr2.IsNull())
52         cout <<"DeltaOnModificationOfByteArray:: Current ByteArray is Null" <<endl;
53 #endif
54
55       if(Arr1.IsNull() || Arr2.IsNull()) return;
56       if(Arr1 != Arr2) {
57         myUp1 = Arr1->Upper();
58         myUp2 = Arr2->Upper();
59         Standard_Integer i, N=0, aCase=0; 
60         if(myUp1 == myUp2) 
61           {aCase = 1; N = myUp1;}
62         else if(myUp1 < myUp2) 
63           {aCase = 2; N = myUp1;}
64         else 
65           {aCase = 3; N = myUp2;}//Up1 > Up2
66
67         TColStd_ListOfInteger aList;
68         for(i=Arr1->Lower();i<= N; i++)
69           if(Arr1->Value(i) != Arr2->Value(i)) 
70             aList.Append(i);
71         if(aCase == 3) {
72           for(i = N+1;i <= myUp1; i++)
73             aList.Append(i);
74         }
75
76         if(aList.Extent()) {
77           myIndxes = new TColStd_HArray1OfInteger(1,aList.Extent());
78           myValues = new TColStd_HArray1OfByte(1,aList.Extent());
79           TColStd_ListIteratorOfListOfInteger anIt(aList);
80           for(i =1;anIt.More();anIt.Next(),i++) {
81             myIndxes->SetValue(i, anIt.Value());
82             myValues->SetValue(i, Arr1->Value(anIt.Value()));
83           }
84         }
85       }
86     }
87     OldAtt->RemoveArray();
88 #ifdef DEB
89     if(OldAtt->InternalArray().IsNull())
90       cout << "BackUp Arr is Nullified" << endl;
91 #endif
92   }
93 }
94
95
96 //=======================================================================
97 //function : Apply
98 //purpose  : 
99 //=======================================================================
100
101 void TDataStd_DeltaOnModificationOfByteArray::Apply()
102 {
103
104   Handle(TDF_Attribute) TDFAttribute = Attribute();
105   Handle(TDataStd_ByteArray) BackAtt = (*((Handle(TDataStd_ByteArray)*)&TDFAttribute));
106   if(BackAtt.IsNull()) {
107 #ifdef DEB
108     cout << "DeltaOnModificationOfByteArray::Apply: OldAtt is Null" <<endl;
109 #endif
110     return;
111   }
112   
113   Handle(TDataStd_ByteArray) aCurAtt;
114   if (!Label().FindAttribute(BackAtt->ID(),aCurAtt)) {
115
116     Label().AddAttribute(BackAtt);
117   }
118
119   if(aCurAtt.IsNull()) {
120 #ifdef DEB
121     cout << "DeltaOnModificationOfByteArray::Apply: CurAtt is Null" <<endl;
122 #endif
123     return;
124   }
125   else 
126     aCurAtt->Backup();
127
128   Standard_Integer aCase;
129   if(myUp1 == myUp2) 
130     aCase = 1;
131   else if(myUp1 < myUp2) 
132     aCase = 2;
133   else 
134     aCase = 3;//Up1 > Up2
135
136   if (aCase == 1 && (myIndxes.IsNull() || myValues.IsNull()))
137     return;
138   
139   Standard_Integer i;
140   Handle(TColStd_HArray1OfByte) BArr = aCurAtt->InternalArray();
141   if(BArr.IsNull()) return;
142   if(aCase == 1)   
143     for(i = 1; i <= myIndxes->Upper();i++) 
144       BArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i));
145   else if(aCase == 2) {    
146     Handle(TColStd_HArray1OfByte) byteArr = new TColStd_HArray1OfByte(BArr->Lower(), myUp1);
147     for(i = BArr->Lower(); i <= myUp1 && i <= BArr->Upper(); i++) 
148       byteArr->SetValue(i, BArr->Value(i));
149     if(!myIndxes.IsNull() && !myValues.IsNull())
150       for(i = 1; i <= myIndxes->Upper();i++) 
151         byteArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i));
152     aCurAtt->myValue = byteArr;
153   }
154   else { // aCase == 3
155     Standard_Integer low = BArr->Lower();
156     Handle(TColStd_HArray1OfByte) byteArr = new TColStd_HArray1OfByte(low, myUp1);
157     for(i = BArr->Lower(); i <= myUp2 && i <= BArr->Upper(); i++) 
158       byteArr->SetValue(i, BArr->Value(i));
159     if(!myIndxes.IsNull() && !myValues.IsNull())
160       for(i = 1; i <= myIndxes->Upper();i++) {
161 #ifdef DEB  
162         cout << "i = " << i << "  myIndxes->Upper = " << myIndxes->Upper() << endl;
163         cout << "myIndxes->Value(i) = " << myIndxes->Value(i) << endl;
164         cout << "myValues->Value(i) = " << myValues->Value(i) << endl;
165 #endif
166         byteArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i));      
167       }
168     aCurAtt->myValue = byteArr;
169   }
170   
171 #ifdef DEB
172   cout << " << Array Dump after Delta Apply >>" <<endl;
173   Handle(TColStd_HArray1OfByte) BArr2 = aCurAtt->InternalArray();
174   for(i=BArr2->Lower(); i<=BArr2->Upper() && i<= MAXUP;i++)
175     cout << BArr2->Value(i) << "  ";
176   cout <<endl;
177 #endif
178 }
179
180