0024162: Eliminate CLang compiler warning
[occt.git] / src / TDataStd / TDataStd_DeltaOnModificationOfIntPackedMap.cxx
1 // Created on: 2008-01-23
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2008-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_DeltaOnModificationOfIntPackedMap.ixx>
22 #include <TDF_DeltaOnModification.hxx>
23 #include <TDF_Label.hxx>
24 #include <TColStd_PackedMapOfInteger.hxx>
25 #include <TColStd_HPackedMapOfInteger.hxx>
26 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
27
28 #ifdef DEB
29 #define MAXUP 1000
30 #endif
31
32 //=======================================================================
33 //function : TDataStd_DeltaOnModificationOfIntPackedMap
34 //purpose  : 
35 //=======================================================================
36
37 TDataStd_DeltaOnModificationOfIntPackedMap::TDataStd_DeltaOnModificationOfIntPackedMap(
38                              const Handle(TDataStd_IntPackedMap)& OldAtt)
39 : TDF_DeltaOnModification(OldAtt)
40 {
41   Handle(TDataStd_IntPackedMap) CurrAtt;
42   if (Label().FindAttribute(OldAtt->ID(),CurrAtt)) {
43     {
44       Handle(TColStd_HPackedMapOfInteger) aMap1, aMap2;
45       aMap1 = OldAtt->GetHMap();
46       aMap2 = CurrAtt->GetHMap();
47 #ifdef DEB
48       if(aMap1.IsNull())
49         cout <<"DeltaOnModificationOfIntPackedMap:: Old Map is Null" <<endl;
50       if(aMap2.IsNull())
51         cout <<"DeltaOnModificationOfIntPackedMap:: Current Map is Null" <<endl;
52 #endif
53       
54       if(aMap1.IsNull() || aMap2.IsNull()) return;
55       if(aMap1 != aMap2) {
56         if(!aMap1->Map().HasIntersection(aMap2->Map()))
57           return; // no intersection: use full-scale backup
58
59         if(aMap1->Map().IsSubset(aMap2->Map())) { 
60           myDeletion = new TColStd_HPackedMapOfInteger();
61           myDeletion->ChangeMap().Subtraction(aMap2->Map(), aMap1->Map());
62         } else if(aMap2->Map().IsSubset(aMap1->Map())) { 
63           myAddition = new TColStd_HPackedMapOfInteger();
64           myAddition->ChangeMap().Subtraction(aMap1->Map(), aMap2->Map());
65         } else {
66           myAddition = new TColStd_HPackedMapOfInteger();
67           myAddition->ChangeMap().Subtraction(aMap1->Map(), aMap2->Map());
68           myDeletion = new TColStd_HPackedMapOfInteger();
69           myDeletion->ChangeMap().Subtraction(aMap2->Map(), aMap1->Map());
70         }
71       }
72     }
73     OldAtt->RemoveMap();
74 #ifdef DEB
75     if(OldAtt->GetHMap().IsNull())
76       cout << "BackUp Arr is Nullified" << endl;
77 #endif
78   }
79 }
80
81
82 //=======================================================================
83 //function : Apply
84 //purpose  : 
85 //=======================================================================
86
87 void TDataStd_DeltaOnModificationOfIntPackedMap::Apply()
88 {
89
90   Handle(TDF_Attribute) aTDFAttribute = Attribute();
91   Handle(TDataStd_IntPackedMap) aBackAtt = (*((Handle(TDataStd_IntPackedMap)*)&aTDFAttribute));
92   if(aBackAtt.IsNull()) {
93 #ifdef DEB
94     cout << "DeltaOnModificationOfIntPAckedMap::Apply: OldAtt is Null" <<endl;
95 #endif
96     return;
97   }
98   
99   Handle(TDataStd_IntPackedMap) aCurAtt;
100   if (!Label().FindAttribute(aBackAtt->ID(),aCurAtt)) {
101
102     Label().AddAttribute(aBackAtt);
103   }
104
105   if(aCurAtt.IsNull()) {
106 #ifdef DEB
107     cout << "DeltaOnModificationOfIntAPckedMAp::Apply: CurAtt is Null" <<endl;
108 #endif
109     return;
110   }
111   else 
112     aCurAtt->Backup();
113
114   
115   
116   Handle(TColStd_HPackedMapOfInteger) IntMap = aCurAtt->GetHMap();
117   if(IntMap.IsNull()) return;
118
119   if(myDeletion.IsNull() && myAddition.IsNull())
120     return;
121   else {
122     if(!myDeletion.IsNull()) {
123   
124       if(myDeletion->Map().Extent())
125         IntMap->ChangeMap().Subtract(myDeletion->Map());
126     } 
127     if(!myAddition.IsNull()) {
128       if(myAddition->Map().Extent())
129         IntMap->ChangeMap().Unite(myAddition->Map());
130     }
131   }
132   
133 #ifdef DEB    
134   cout << " << Map Dump after Delta Apply >>" <<endl;
135   Handle(TColStd_HPackedMapOfInteger) aIntMap = aCurAtt->GetHMap();
136   TColStd_MapIteratorOfPackedMapOfInteger it(aIntMap->Map());
137   for (Standard_Integer i=1;it.More() && i <= MAXUP; it.Next(), i++) 
138     cout << it.Key() << "  ";
139   cout <<endl;
140 #endif
141 }
142
143