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 under
8 // the terms of the GNU Lesser General Public License 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.
17 #include <Standard_GUID.hxx>
18 #include <Standard_Type.hxx>
19 #include <TColStd_HPackedMapOfInteger.hxx>
20 #include <TColStd_PackedMapOfInteger.hxx>
21 #include <TDataStd_DeltaOnModificationOfIntPackedMap.hxx>
22 #include <TDataStd_IntPackedMap.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TDF_DefaultDeltaOnModification.hxx>
25 #include <TDF_DeltaOnModification.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_RelocationTable.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_IntPackedMap,TDF_Attribute)
31 //=======================================================================
34 //=======================================================================
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;
88 //=======================================================================
89 //function : ChangeMap
91 //=======================================================================
92 Standard_Boolean TDataStd_IntPackedMap::ChangeMap (const TColStd_PackedMapOfInteger& theMap)
94 if (!myMap->Map().IsEqual(theMap))
97 myMap->ChangeMap().Assign(theMap);
100 return Standard_False;
102 //=======================================================================
105 //=======================================================================
107 Standard_Boolean TDataStd_IntPackedMap::Clear ()
109 if (!myMap->Map().IsEmpty())
112 myMap = new TColStd_HPackedMapOfInteger;
113 return Standard_True;
115 return Standard_False;
118 //=======================================================================
119 //function : Contains
121 //=======================================================================
122 Standard_Boolean TDataStd_IntPackedMap::Contains(const Standard_Integer theKey) const
124 return myMap->Map().Contains(theKey);
127 //=======================================================================
130 //=======================================================================
132 Standard_Boolean TDataStd_IntPackedMap::Add(const Standard_Integer theKey)
134 Standard_Boolean aResult = !myMap->Map().Contains(theKey);
138 aResult = myMap->ChangeMap().Add(theKey);
142 //=======================================================================
145 //=======================================================================
147 Standard_Boolean TDataStd_IntPackedMap::Remove(const Standard_Integer theKey)
149 Standard_Boolean aResult = myMap->Map().Contains(theKey);
153 aResult = myMap->ChangeMap().Remove(theKey);
158 //=======================================================================
159 //function : NewEmpty
161 //=======================================================================
163 Handle(TDF_Attribute) TDataStd_IntPackedMap::NewEmpty () const
165 return new TDataStd_IntPackedMap;
168 //=======================================================================
171 //=======================================================================
173 void TDataStd_IntPackedMap::Restore (const Handle(TDF_Attribute)& theWith)
175 Handle(TDataStd_IntPackedMap) aWith =
176 Handle(TDataStd_IntPackedMap)::DownCast(theWith);
177 if (aWith->myMap.IsNull())
181 myMap = new TColStd_HPackedMapOfInteger;
182 myMap->ChangeMap().Assign(aWith->myMap->Map());
183 myIsDelta = aWith->myIsDelta;
187 //=======================================================================
190 //=======================================================================
192 void TDataStd_IntPackedMap::Paste (const Handle(TDF_Attribute)& theInto,
193 const Handle(TDF_RelocationTable)&) const
195 Handle(TDataStd_IntPackedMap) anInto =
196 Handle(TDataStd_IntPackedMap)::DownCast(theInto);
197 if(!anInto.IsNull()) {
198 anInto->ChangeMap(myMap);
199 anInto->SetDelta(myIsDelta);
203 //=======================================================================
206 //=======================================================================
207 const Standard_GUID& TDataStd_IntPackedMap::ID() const
210 //=======================================================================
213 //=======================================================================
215 Standard_OStream& TDataStd_IntPackedMap::Dump(Standard_OStream& theOS) const
217 Standard_OStream& anOS = TDF_Attribute::Dump( theOS );
218 anOS << "IntPackedMap size = " << Extent();
219 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
224 //=======================================================================
225 //function : DeltaOnModification
227 //=======================================================================
229 Handle(TDF_DeltaOnModification) TDataStd_IntPackedMap::DeltaOnModification
230 (const Handle(TDF_Attribute)& OldAttribute) const
233 return new TDataStd_DeltaOnModificationOfIntPackedMap(Handle(TDataStd_IntPackedMap)::DownCast (OldAttribute));
234 else return new TDF_DefaultDeltaOnModification(OldAttribute);