1 // Created on: 2007-07-31
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
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 //=======================================================================
27 //=======================================================================
29 const Standard_GUID& TDataStd_IntPackedMap::GetID()
31 static Standard_GUID theGUID ("7031faff-161e-44df-8239-7c264a81f5a1");
35 //=======================================================================
38 //=======================================================================
40 Handle(TDataStd_IntPackedMap) TDataStd_IntPackedMap::Set (const TDF_Label& theLabel,
41 const Standard_Boolean isDelta)
43 Handle(TDataStd_IntPackedMap) anAtt;
44 if (!theLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
46 anAtt = new TDataStd_IntPackedMap;
48 anAtt->SetDelta(isDelta);
49 theLabel.AddAttribute(anAtt);
53 //=======================================================================
54 //function : Constructor
56 //=======================================================================
57 TDataStd_IntPackedMap::TDataStd_IntPackedMap ()
58 :myIsDelta(Standard_False)
60 myMap = new TColStd_HPackedMapOfInteger ();
62 //=======================================================================
63 //function : ChangeMap
65 //=======================================================================
67 Standard_Boolean TDataStd_IntPackedMap::ChangeMap (const Handle(TColStd_HPackedMapOfInteger)& theMap)
69 if(theMap.IsNull()) return Standard_False;
72 if (!myMap->Map().IsEqual(theMap->Map()))
75 myMap->ChangeMap().Assign(theMap->Map());
79 return Standard_False;
81 //=======================================================================
84 //=======================================================================
86 Standard_Boolean TDataStd_IntPackedMap::Clear ()
88 if (!myMap->Map().IsEmpty())
91 myMap = new TColStd_HPackedMapOfInteger;
94 return Standard_False;
97 //=======================================================================
100 //=======================================================================
101 Standard_Boolean TDataStd_IntPackedMap::Contains(const Standard_Integer theKey) const
103 return myMap->Map().Contains(theKey);
106 //=======================================================================
109 //=======================================================================
111 Standard_Boolean TDataStd_IntPackedMap::Add(const Standard_Integer theKey)
113 Standard_Boolean aResult = !myMap->Map().Contains(theKey);
117 aResult = myMap->ChangeMap().Add(theKey);
121 //=======================================================================
124 //=======================================================================
126 Standard_Boolean TDataStd_IntPackedMap::Remove(const Standard_Integer theKey)
128 Standard_Boolean aResult = myMap->Map().Contains(theKey);
132 aResult = myMap->ChangeMap().Remove(theKey);
137 //=======================================================================
138 //function : NewEmpty
140 //=======================================================================
142 Handle(TDF_Attribute) TDataStd_IntPackedMap::NewEmpty () const
144 return new TDataStd_IntPackedMap;
147 //=======================================================================
150 //=======================================================================
152 void TDataStd_IntPackedMap::Restore (const Handle(TDF_Attribute)& theWith)
154 Handle(TDataStd_IntPackedMap) aWith =
155 Handle(TDataStd_IntPackedMap)::DownCast(theWith);
156 if (aWith->myMap.IsNull())
160 myMap = new TColStd_HPackedMapOfInteger;
161 myMap->ChangeMap().Assign(aWith->myMap->Map());
162 myIsDelta = aWith->myIsDelta;
166 //=======================================================================
169 //=======================================================================
171 void TDataStd_IntPackedMap::Paste (const Handle(TDF_Attribute)& theInto,
172 const Handle(TDF_RelocationTable)&) const
174 Handle(TDataStd_IntPackedMap) anInto =
175 Handle(TDataStd_IntPackedMap)::DownCast(theInto);
176 if(!anInto.IsNull()) {
177 anInto->ChangeMap(myMap);
178 anInto->SetDelta(myIsDelta);
182 //=======================================================================
185 //=======================================================================
186 const Standard_GUID& TDataStd_IntPackedMap::ID() const
189 //=======================================================================
192 //=======================================================================
194 Standard_OStream& TDataStd_IntPackedMap::Dump(Standard_OStream& theOS) const
196 Standard_OStream& anOS = TDF_Attribute::Dump( theOS );
197 anOS << "IntPackedMap size = " << Extent();
198 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
203 //=======================================================================
204 //function : DeltaOnModification
206 //=======================================================================
208 Handle(TDF_DeltaOnModification) TDataStd_IntPackedMap::DeltaOnModification
209 (const Handle(TDF_Attribute)& OldAttribute) const
212 return new TDataStd_DeltaOnModificationOfIntPackedMap(*((Handle(TDataStd_IntPackedMap)*)&OldAttribute));
213 else return new TDF_DefaultDeltaOnModification(OldAttribute);