0030773: Application Framework - To allow to inherit existing attributes to reuse...
[occt.git] / src / TDataStd / TDataStd_IntPackedMap.hxx
1 // Created on: 2007-07-31
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _TDataStd_IntPackedMap_HeaderFile
17 #define _TDataStd_IntPackedMap_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <Standard_Boolean.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TColStd_HPackedMapOfInteger.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_OStream.hxx>
27
28 class TDataStd_DeltaOnModificationOfIntPackedMap;
29 class Standard_GUID;
30 class TDF_Label;
31 class TDF_Attribute;
32 class TDF_RelocationTable;
33 class TDF_DeltaOnModification;
34
35 class TDataStd_IntPackedMap;
36 DEFINE_STANDARD_HANDLE(TDataStd_IntPackedMap, TDF_Attribute)
37
38 //! Attribute for storing TColStd_PackedMapOfInteger
39 class TDataStd_IntPackedMap : public TDF_Attribute
40 {
41   friend class TDataStd_DeltaOnModificationOfIntPackedMap;
42   DEFINE_STANDARD_RTTIEXT(TDataStd_IntPackedMap, TDF_Attribute)
43 public:
44
45   //! class methods
46   //! =============
47   //! Returns the GUID of the attribute.
48   Standard_EXPORT static const Standard_GUID& GetID();
49   
50   //! Finds or creates an integer map attribute on the given label.
51   //! If <isDelta> == False, DefaultDeltaOnModification is used.
52   //! If <isDelta> == True, DeltaOnModification of the current attribute is used.
53   //! If attribute is already set, input parameter <isDelta> is refused and the found
54   //! attribute returned.
55   //! Attribute methods
56   //! ===================
57   Standard_EXPORT static Handle(TDataStd_IntPackedMap) Set (const TDF_Label& label, const Standard_Boolean isDelta = Standard_False);
58   
59   Standard_EXPORT TDataStd_IntPackedMap();
60   
61   Standard_EXPORT Standard_Boolean ChangeMap (const Handle(TColStd_HPackedMapOfInteger)& theMap);
62
63   Standard_EXPORT Standard_Boolean ChangeMap (const TColStd_PackedMapOfInteger& theMap);
64
65   const TColStd_PackedMapOfInteger& GetMap() const { return  myMap->Map(); }
66
67   const Handle(TColStd_HPackedMapOfInteger)& GetHMap() const { return myMap; }
68
69   Standard_EXPORT Standard_Boolean Clear();
70   
71   Standard_EXPORT Standard_Boolean Add (const Standard_Integer theKey);
72   
73   Standard_EXPORT Standard_Boolean Remove (const Standard_Integer theKey);
74   
75   Standard_EXPORT Standard_Boolean Contains (const Standard_Integer theKey) const;
76
77   Standard_Integer Extent() const { return myMap->Map().Extent(); }
78
79   Standard_Boolean IsEmpty() const { return myMap->Map().IsEmpty(); }
80
81   Standard_Boolean GetDelta() const { return myIsDelta; }
82
83   //! for  internal  use  only!
84   void SetDelta (const Standard_Boolean isDelta) { myIsDelta = isDelta; }
85
86   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
87   
88   Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
89   
90   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
91   
92   Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
93   
94   Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
95   
96   //! Makes a DeltaOnModification between <me> and
97   //! <anOldAttribute>.
98   Standard_EXPORT virtual Handle(TDF_DeltaOnModification) DeltaOnModification (const Handle(TDF_Attribute)& anOldAttribute) const Standard_OVERRIDE;
99   
100   //! Dumps the content of me into the stream
101   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
102
103 private:
104
105   void RemoveMap() { myMap.Nullify(); }
106
107 private:
108
109   Handle(TColStd_HPackedMapOfInteger) myMap;
110   Standard_Boolean myIsDelta;
111
112 };
113
114 #endif // _TDataStd_IntPackedMap_HeaderFile