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