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