1 // Created on: 2007-07-31
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <TDataStd_IntPackedMap.ixx>
23 #include <TColStd_PackedMapOfInteger.hxx>
24 #include <TColStd_HPackedMapOfInteger.hxx>
25 #include <TDF_DefaultDeltaOnModification.hxx>
26 #include <TDataStd_DeltaOnModificationOfIntPackedMap.hxx>
27 #include <Standard_GUID.hxx>
28 #include <TDF_Label.hxx>
29 #include <TDF_Attribute.hxx>
30 //=======================================================================
33 //=======================================================================
35 const Standard_GUID& TDataStd_IntPackedMap::GetID()
37 static Standard_GUID theGUID ("7031faff-161e-44df-8239-7c264a81f5a1");
41 //=======================================================================
44 //=======================================================================
46 Handle(TDataStd_IntPackedMap) TDataStd_IntPackedMap::Set (const TDF_Label& theLabel,
47 const Standard_Boolean isDelta)
49 Handle(TDataStd_IntPackedMap) anAtt;
50 if (!theLabel.FindAttribute(TDataStd_IntPackedMap::GetID(), anAtt))
52 anAtt = new TDataStd_IntPackedMap;
54 anAtt->SetDelta(isDelta);
55 theLabel.AddAttribute(anAtt);
59 //=======================================================================
60 //function : Constructor
62 //=======================================================================
63 TDataStd_IntPackedMap::TDataStd_IntPackedMap ()
64 :myIsDelta(Standard_False)
66 myMap = new TColStd_HPackedMapOfInteger ();
68 //=======================================================================
69 //function : ChangeMap
71 //=======================================================================
73 Standard_Boolean TDataStd_IntPackedMap::ChangeMap (const Handle(TColStd_HPackedMapOfInteger)& theMap)
75 if(theMap.IsNull()) return Standard_False;
78 if (!myMap->Map().IsEqual(theMap->Map()))
81 myMap->ChangeMap().Assign(theMap->Map());
85 return Standard_False;
87 //=======================================================================
90 //=======================================================================
92 Standard_Boolean TDataStd_IntPackedMap::Clear ()
94 if (!myMap->Map().IsEmpty())
97 myMap = new TColStd_HPackedMapOfInteger;
100 return Standard_False;
103 //=======================================================================
104 //function : Contains
106 //=======================================================================
107 Standard_Boolean TDataStd_IntPackedMap::Contains(const Standard_Integer theKey) const
109 return myMap->Map().Contains(theKey);
112 //=======================================================================
115 //=======================================================================
117 Standard_Boolean TDataStd_IntPackedMap::Add(const Standard_Integer theKey)
119 Standard_Boolean aResult = !myMap->Map().Contains(theKey);
123 aResult = myMap->ChangeMap().Add(theKey);
127 //=======================================================================
130 //=======================================================================
132 Standard_Boolean TDataStd_IntPackedMap::Remove(const Standard_Integer theKey)
134 Standard_Boolean aResult = myMap->Map().Contains(theKey);
138 aResult = myMap->ChangeMap().Remove(theKey);
143 //=======================================================================
144 //function : NewEmpty
146 //=======================================================================
148 Handle(TDF_Attribute) TDataStd_IntPackedMap::NewEmpty () const
150 return new TDataStd_IntPackedMap;
153 //=======================================================================
156 //=======================================================================
158 void TDataStd_IntPackedMap::Restore (const Handle(TDF_Attribute)& theWith)
160 Handle(TDataStd_IntPackedMap) aWith =
161 Handle(TDataStd_IntPackedMap)::DownCast(theWith);
162 if (aWith->myMap.IsNull())
166 myMap = new TColStd_HPackedMapOfInteger;
167 myMap->ChangeMap().Assign(aWith->myMap->Map());
168 myIsDelta = aWith->myIsDelta;
172 //=======================================================================
175 //=======================================================================
177 void TDataStd_IntPackedMap::Paste (const Handle(TDF_Attribute)& theInto,
178 const Handle(TDF_RelocationTable)&) const
180 Handle(TDataStd_IntPackedMap) anInto =
181 Handle(TDataStd_IntPackedMap)::DownCast(theInto);
182 if(!anInto.IsNull()) {
183 anInto->ChangeMap(myMap);
184 anInto->SetDelta(myIsDelta);
188 //=======================================================================
191 //=======================================================================
192 const Standard_GUID& TDataStd_IntPackedMap::ID() const
195 //=======================================================================
198 //=======================================================================
200 Standard_OStream& TDataStd_IntPackedMap::Dump(Standard_OStream& theOS) const
202 Standard_OStream& anOS = TDF_Attribute::Dump( theOS );
203 anOS << "IntPackedMap size = " << Extent();
204 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
209 //=======================================================================
210 //function : DeltaOnModification
212 //=======================================================================
214 Handle(TDF_DeltaOnModification) TDataStd_IntPackedMap::DeltaOnModification
215 (const Handle(TDF_Attribute)& OldAttribute) const
218 return new TDataStd_DeltaOnModificationOfIntPackedMap(*((Handle(TDataStd_IntPackedMap)*)&OldAttribute));
219 else return new TDF_DefaultDeltaOnModification(OldAttribute);