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