Salome HOME
Base implementation of Notebook
[modules/kernel.git] / src / DF / DF_Label.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef DFLABEL_HXX
23 #define DFLABEL_HXX
24
25 #include "DF_definitions.hxx"
26 #include "DF_Attribute.hxx"
27
28 #include <string>
29 #include <vector>
30 #include <map>
31
32 class DF_Document;
33
34
35 class DF_LabelNode
36 {
37 public:
38   DF_LabelNode();
39   ~DF_LabelNode();
40   void Reset();
41 private:
42   int                                      _tag;
43   int                                      _depth;
44   DF_LabelNode*                            _father;
45   DF_LabelNode*                            _previous;
46   DF_LabelNode*                            _next;
47   DF_LabelNode*                            _firstChild;
48   DF_LabelNode*                            _lastChild;
49   DF_Document*                             _document;
50   std::map< std::string, DF_Attribute* >   _attributes;
51
52   friend class DF_Document;
53   friend class DF_Label;
54   friend class DF_ChildIterator;
55   friend class DF_Attribute;
56 };
57
58 //Class DF_Label defines a persistence reference in DF_Document that contains a tree of Labels.
59 //This reference is named "entry" and is a sequence of tags divided by ":". The root entry is "0:".
60 //For example "0:1:1" corresponds the following structure
61 // 0_
62 //   |
63 //   |_1_
64 //       |
65 //       |_ 1
66
67 class DF_Label {
68 public:
69
70   //Returns a Label by its entry, if isCreated true the Label will be created if not exists
71   Standard_EXPORT static DF_Label Label(const DF_Label& theLabel, const std::string& theEntry, bool isCreated = true);
72
73   //Constructors: creates a root label
74   Standard_EXPORT DF_Label();
75
76   //Copy constructor
77   Standard_EXPORT DF_Label(const DF_Label& theLabel);
78
79   //Creates a Label from the LabelNode
80   Standard_EXPORT DF_Label(DF_LabelNode* theNode);
81
82   //Operator =
83   Standard_EXPORT DF_Label& operator=(const DF_Label& theLabel);
84
85   //Destructor
86   Standard_EXPORT ~DF_Label();
87
88   //Returns a smart pointer to Document which contains this Label
89   Standard_EXPORT DF_Document* GetDocument() const;
90
91   //Returns true if theLabel equals to this label
92   Standard_EXPORT bool operator==(const DF_Label& theLabel);
93
94   //Returns true if theLabel doesn't equals to this label
95   Standard_EXPORT bool operator!=(const DF_Label& theLabel);
96
97   //Returns a tag of this Label
98   Standard_EXPORT int Tag() const;
99
100   //Returns true if this Label is attached to the tree in the Document.
101   Standard_EXPORT bool IsAttached();
102
103   //Searches an Attribute with given ID located on this Label.
104   //Returns true if the Attribute is found.
105   Standard_EXPORT DF_Attribute* FindAttribute(const std::string& theID) const;
106
107   //Returns true if there is an Attribute with given ID on this Label.
108   Standard_EXPORT bool IsAttribute(const std::string& theID) const;
109
110   //Adds theAttribute to the Label where this Attribute is located.
111   //Returns true if theAttribute was added.
112   Standard_EXPORT bool AddAttribute(DF_Attribute* theAttribute) const;
113
114   //Forgets an Attribute with given ID located on the this Label.
115   Standard_EXPORT bool ForgetAttribute(const std::string& theID) const;
116
117   //Forgets all Attributes located on this Label.
118   Standard_EXPORT bool ForgetAllAttributes(bool clearChildren = true) const;
119
120   //Returns Father of this Label.
121   Standard_EXPORT DF_Label Father() const;
122
123   //Return true if the label is not initialized
124   Standard_EXPORT bool IsNull() const;
125
126   //Return true if the label is a Root label
127   Standard_EXPORT bool IsRoot() const;
128
129   //Returns true if this Label has Attributes.
130   Standard_EXPORT bool HasAttributes() const;
131
132   //Returns a list of Attributes of this Label.
133   Standard_EXPORT std::vector<DF_Attribute*> GetAttributes() const;
134
135   //Returns true if this Label has a child Label.
136   Standard_EXPORT bool HasChild() const;
137
138   //Returns a number of child Labels.
139   Standard_EXPORT int NbChildren() const;
140
141   //Returns the depth (a number of fathers required to identify the Label) of this Label in the tree.
142   Standard_EXPORT int Depth() const;
143
144   //Returns true if this Label is a descendant of theLabel.
145   Standard_EXPORT bool IsDescendant(const DF_Label& theLabel);
146
147   //Returns the root Label of a Label tree to which this Label belongs.
148   Standard_EXPORT DF_Label Root() const;
149
150   //Finds a child Label of this Label with a given tag. If isCreate = true and there is no child
151   //Label with the given tag, the child Label is created.
152   Standard_EXPORT DF_Label FindChild(int theTag, bool isCreate = true);
153
154   //Creates a new child Label of this Label.
155   Standard_EXPORT DF_Label NewChild();
156
157   //Returns a string presentation of the entry
158   Standard_EXPORT std::string Entry() const;
159
160   //Returns true if theLabel is the same as me
161   Standard_EXPORT bool IsEqual(const DF_Label& theLabel);
162
163   Standard_EXPORT void dump();
164
165 private:
166   //Nullifies the content of the label
167   void Nullify();
168
169 friend class DF_Document;
170 friend class DF_ChildIterator;
171
172 private:
173   DF_LabelNode* _node;
174 };
175
176 #endif