Salome HOME
Removed includes and libraries of OCC
[modules/kernel.git] / src / DF / DF_Label.hxx
1 #ifndef DFLABEL_HXX
2 #define DFLABEL_HXX
3
4 #include "DF_definitions.hxx"
5 #include "DF_Attribute.hxx"
6
7 #include <string>
8 #include <vector>
9 #include <map>
10
11 class DF_Document;
12
13
14 class DF_LabelNode
15 {
16 public:
17   DF_LabelNode();
18   ~DF_LabelNode();
19   void Reset();
20 private:
21   int                                      _tag;
22   int                                      _depth;
23   DF_LabelNode*                            _father;
24   DF_LabelNode*                            _previous;
25   DF_LabelNode*                            _next;
26   DF_LabelNode*                            _firstChild;
27   DF_LabelNode*                            _lastChild;
28   DF_Document*                             _document;
29   std::map< std::string, DF_Attribute* >   _attributes;
30
31   friend class DF_Document;
32   friend class DF_Label;
33   friend class DF_ChildIterator;
34   friend class DF_Attribute;
35 };
36
37 //Class DF_Label defines a persistence reference in DF_Document that contains a tree of Labels.
38 //This reference is named "entry" and is a sequence of tags divided by ":". The root entry is "0:".
39 //For example "0:1:1" corresponds the following structure
40 // 0_
41 //   |
42 //   |_1_
43 //       |
44 //       |_ 1
45
46 class DF_Label {
47 public:
48
49   //Returns a Label by its entry, if isCreated true the Label will be created if not exists
50   Standard_EXPORT static DF_Label Label(const DF_Label& theLabel, const std::string& theEntry, bool isCreated = true);
51
52   //Constructors: creates a root label
53   Standard_EXPORT DF_Label();
54
55   //Copy constructor
56   Standard_EXPORT DF_Label(const DF_Label& theLabel);
57
58   //Creates a Label from the LabelNode
59   Standard_EXPORT DF_Label(DF_LabelNode* theNode);
60
61   //Operator =
62   Standard_EXPORT DF_Label& operator=(const DF_Label& theLabel);
63
64   //Destructor
65   Standard_EXPORT ~DF_Label();
66
67   //Returns a smart pointer to Document which contains this Label
68   Standard_EXPORT DF_Document* GetDocument() const;
69
70   //Returns true if theLabel equals to this label
71   Standard_EXPORT bool operator==(const DF_Label& theLabel);
72
73   //Returns true if theLabel doesn't equals to this label
74   Standard_EXPORT bool operator!=(const DF_Label& theLabel);
75
76   //Returns a tag of this Label
77   Standard_EXPORT int Tag() const;
78
79   //Returns true if this Label is attached to the tree in the Document.
80   Standard_EXPORT bool IsAttached();
81
82   //Searches an Attribute with given ID located on this Label.
83   //Returns true if the Attribute is found.
84   Standard_EXPORT DF_Attribute* FindAttribute(const std::string& theID) const;
85
86   //Returns true if there is an Attribute with given ID on this Label.
87   Standard_EXPORT bool IsAttribute(const std::string& theID) const;
88
89   //Adds theAttribute to the Label where this Attribute is located.
90   //Returns true if theAttribute was added.
91   Standard_EXPORT bool AddAttribute(DF_Attribute* theAttribute) const;
92
93   //Forgets an Attribute with given ID located on the this Label.
94   Standard_EXPORT bool ForgetAttribute(const std::string& theID) const;
95
96   //Forgets all Attributes located on this Label.
97   Standard_EXPORT bool ForgetAllAttributes(bool clearChildren = true) const;
98
99   //Returns Father of this Label.
100   Standard_EXPORT DF_Label Father() const;
101
102   //Return true if the label is not initialized
103   Standard_EXPORT bool IsNull() const;
104
105   //Return true if the label is a Root label
106   Standard_EXPORT bool IsRoot() const;
107
108   //Returns true if this Label has Attributes.
109   Standard_EXPORT bool HasAttributes() const;
110
111   //Returns a list of Attributes of this Label.
112   Standard_EXPORT std::vector<DF_Attribute*> GetAttributes() const;
113
114   //Returns true if this Label has a child Label.
115   Standard_EXPORT bool HasChild() const;
116
117   //Returns a number of child Labels.
118   Standard_EXPORT int NbChildren() const;
119
120   //Returns the depth (a number of fathers required to identify the Label) of this Label in the tree.
121   Standard_EXPORT int Depth() const;
122
123   //Returns true if this Label is a descendant of theLabel.
124   Standard_EXPORT bool IsDescendant(const DF_Label& theLabel);
125
126   //Returns the root Label of a Label tree to which this Label belongs.
127   Standard_EXPORT DF_Label Root() const;
128
129   //Finds a child Label of this Label with a given tag. If isCreate = true and there is no child
130   //Label with the given tag, the child Label is created.
131   Standard_EXPORT DF_Label FindChild(int theTag, bool isCreate = true);
132
133   //Creates a new child Label of this Label.
134   Standard_EXPORT DF_Label NewChild();
135
136   //Returns a string presentation of the entry
137   Standard_EXPORT std::string Entry() const;
138
139   //Returns true if theLabel is the same as me
140   Standard_EXPORT bool IsEqual(const DF_Label& theLabel);
141
142   Standard_EXPORT void dump();
143
144 private:
145   //Nullifies the content of the label
146   void Nullify();
147
148 friend class DF_Document;
149 friend class DF_ChildIterator;
150
151 private:
152   DF_LabelNode* _node;
153 };
154
155 #endif