0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / TDataStd / TDataStd_IntPackedMap.cxx
CommitLineData
b311480e 1// Created on: 2007-07-31
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
16#include <TDataStd_IntPackedMap.ixx>
17#include <TColStd_PackedMapOfInteger.hxx>
18#include <TColStd_HPackedMapOfInteger.hxx>
19#include <TDF_DefaultDeltaOnModification.hxx>
20#include <TDataStd_DeltaOnModificationOfIntPackedMap.hxx>
21#include <Standard_GUID.hxx>
22#include <TDF_Label.hxx>
23#include <TDF_Attribute.hxx>
24//=======================================================================
25//function : GetID
26//purpose :
27//=======================================================================
28
29const Standard_GUID& TDataStd_IntPackedMap::GetID()
30{
31 static Standard_GUID theGUID ("7031faff-161e-44df-8239-7c264a81f5a1");
32 return theGUID;
33}
34
35//=======================================================================
36//function : Set
37//purpose :
38//=======================================================================
39
40Handle(TDataStd_IntPackedMap) TDataStd_IntPackedMap::Set (const TDF_Label& theLabel,
41 const Standard_Boolean isDelta)
42{
43 Handle(TDataStd_IntPackedMap) anAtt;
44 if (!theLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
45 {
46 anAtt = new TDataStd_IntPackedMap;
47 anAtt->Clear();
48 anAtt->SetDelta(isDelta);
49 theLabel.AddAttribute(anAtt);
50 }
51 return anAtt;
52}
53//=======================================================================
54//function : Constructor
55//purpose :
56//=======================================================================
57TDataStd_IntPackedMap::TDataStd_IntPackedMap ()
58 :myIsDelta(Standard_False)
59{
60 myMap = new TColStd_HPackedMapOfInteger ();
61}
62//=======================================================================
63//function : ChangeMap
64//purpose :
65//=======================================================================
66
67Standard_Boolean TDataStd_IntPackedMap::ChangeMap (const Handle(TColStd_HPackedMapOfInteger)& theMap)
68{
69 if(theMap.IsNull()) return Standard_False;
70 if (myMap != theMap)
71 {
72 if (!myMap->Map().IsEqual(theMap->Map()))
73 {
74 Backup();
75 myMap->ChangeMap().Assign(theMap->Map());
76 return Standard_True;
77 }
78 }
79 return Standard_False;
80}
81//=======================================================================
82//function : Clear
83//purpose :
84//=======================================================================
85
86Standard_Boolean TDataStd_IntPackedMap::Clear ()
87{
88 if (!myMap->Map().IsEmpty())
89 {
90 Backup();
91 myMap = new TColStd_HPackedMapOfInteger;
92 return Standard_True;
93 }
94 return Standard_False;
95}
96
97//=======================================================================
98//function : Contains
99//purpose :
100//=======================================================================
101Standard_Boolean TDataStd_IntPackedMap::Contains(const Standard_Integer theKey) const
102{
103 return myMap->Map().Contains(theKey);
104}
105
106//=======================================================================
107//function : Add
108//purpose :
109//=======================================================================
110
111Standard_Boolean TDataStd_IntPackedMap::Add(const Standard_Integer theKey)
112{
113 Standard_Boolean aResult = !myMap->Map().Contains(theKey);
114 if (aResult)
115 {
116 Backup();
117 aResult = myMap->ChangeMap().Add(theKey);
118 }
119 return aResult;
120}
121//=======================================================================
122//function : Remove
123//purpose :
124//=======================================================================
125
126Standard_Boolean TDataStd_IntPackedMap::Remove(const Standard_Integer theKey)
127{
128 Standard_Boolean aResult = myMap->Map().Contains(theKey);
129 if (aResult)
130 {
131 Backup();
132 aResult = myMap->ChangeMap().Remove(theKey);
133 }
134 return aResult;
135}
136
137//=======================================================================
138//function : NewEmpty
139//purpose :
140//=======================================================================
141
142Handle(TDF_Attribute) TDataStd_IntPackedMap::NewEmpty () const
143{
144 return new TDataStd_IntPackedMap;
145}
146
147//=======================================================================
148//function : Restore
149//purpose :
150//=======================================================================
151
152void TDataStd_IntPackedMap::Restore (const Handle(TDF_Attribute)& theWith)
153{
154 Handle(TDataStd_IntPackedMap) aWith =
155 Handle(TDataStd_IntPackedMap)::DownCast(theWith);
156 if (aWith->myMap.IsNull())
157 myMap.Nullify();
158 else
159 {
160 myMap = new TColStd_HPackedMapOfInteger;
161 myMap->ChangeMap().Assign(aWith->myMap->Map());
162 myIsDelta = aWith->myIsDelta;
163 }
164}
165
166//=======================================================================
167//function : Paste
168//purpose :
169//=======================================================================
170
171void TDataStd_IntPackedMap::Paste (const Handle(TDF_Attribute)& theInto,
172 const Handle(TDF_RelocationTable)&) const
173{
174 Handle(TDataStd_IntPackedMap) anInto =
175 Handle(TDataStd_IntPackedMap)::DownCast(theInto);
176 if(!anInto.IsNull()) {
177 anInto->ChangeMap(myMap);
178 anInto->SetDelta(myIsDelta);
179 }
180}
181
182//=======================================================================
183//function : ID
184//purpose :
185//=======================================================================
186const Standard_GUID& TDataStd_IntPackedMap::ID() const
187{ return GetID(); }
188
189//=======================================================================
190//function : Dump
191//purpose :
192//=======================================================================
193
194Standard_OStream& TDataStd_IntPackedMap::Dump(Standard_OStream& theOS) const
195{
196 Standard_OStream& anOS = TDF_Attribute::Dump( theOS );
197 anOS << "IntPackedMap size = " << Extent();
eb901da6 198 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
7fd59977 199 anOS << endl;
200 return anOS;
201}
202
203//=======================================================================
204//function : DeltaOnModification
205//purpose :
206//=======================================================================
207
208Handle(TDF_DeltaOnModification) TDataStd_IntPackedMap::DeltaOnModification
209(const Handle(TDF_Attribute)& OldAttribute) const
210{
211 if(myIsDelta)
c5f3a425 212 return new TDataStd_DeltaOnModificationOfIntPackedMap(Handle(TDataStd_IntPackedMap)::DownCast (OldAttribute));
7fd59977 213 else return new TDF_DefaultDeltaOnModification(OldAttribute);
214}
215
216