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