Version: 9.12.0
DF_Label.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 CEA, EDF, 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.
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.
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
#define Standard_EXPORT
Definition: DF_definitions.hxx:53
Definition: DF_Attribute.hxx:30
Definition: DF_ChildIterator.hxx:29
Definition: DF_Document.hxx:32
Definition: DF_Label.hxx:34
void Reset()
Definition: DF_Label.cxx:494
std::map< std::string, DF_Attribute * > _attributes
Definition: DF_Label.hxx:48
~DF_LabelNode()
Definition: DF_Label.cxx:480
DF_LabelNode * _father
Definition: DF_Label.hxx:42
DF_LabelNode * _lastChild
Definition: DF_Label.hxx:46
DF_LabelNode * _previous
Definition: DF_Label.hxx:43
int _depth
Definition: DF_Label.hxx:41
DF_LabelNode * _next
Definition: DF_Label.hxx:44
int _tag
Definition: DF_Label.hxx:40
DF_Document * _document
Definition: DF_Label.hxx:47
DF_LabelNode * _firstChild
Definition: DF_Label.hxx:45
DF_LabelNode()
Definition: DF_Label.cxx:467
Definition: DF_Label.hxx:65
bool HasAttributes() const
Definition: DF_Label.cxx:230
DF_Label NewChild()
Definition: DF_Label.cxx:378
std::string Entry() const
Definition: DF_Label.cxx:395
void Nullify()
Definition: DF_Label.cxx:432
int NbChildren() const
Definition: DF_Label.cxx:265
int Depth() const
Definition: DF_Label.cxx:281
DF_LabelNode * _node
Definition: DF_Label.hxx:174
bool operator!=(const DF_Label &theLabel)
Definition: DF_Label.cxx:116
int Tag() const
Definition: DF_Label.cxx:124
DF_Attribute * FindAttribute(const std::string &theID) const
Definition: DF_Label.cxx:139
DF_Label Root() const
Definition: DF_Label.cxx:305
DF_Label & operator=(const DF_Label &theLabel)
Definition: DF_Label.cxx:89
DF_Document * GetDocument() const
Definition: DF_Label.cxx:102
int LastChildTag() const
Definition: DF_Label.cxx:389
bool IsAttached()
Definition: DF_Label.cxx:131
void dump()
Definition: DF_Label.cxx:438
bool ForgetAttribute(const std::string &theID) const
Definition: DF_Label.cxx:172
bool HasChild() const
Definition: DF_Label.cxx:257
bool IsEqual(const DF_Label &theLabel)
Definition: DF_Label.cxx:424
bool IsNull() const
Definition: DF_Label.cxx:216
static DF_Label Label(const DF_Label &theLabel, const std::string &theEntry, bool isCreated=true)
Definition: DF_Label.cxx:37
bool AddAttribute(DF_Attribute *theAttribute) const
Definition: DF_Label.cxx:159
bool IsDescendant(const DF_Label &theLabel)
Definition: DF_Label.cxx:289
DF_Label Father() const
Definition: DF_Label.cxx:208
DF_Label()
Definition: DF_Label.cxx:78
bool IsAttribute(const std::string &theID) const
Definition: DF_Label.cxx:150
~DF_Label()
Definition: DF_Label.cxx:96
DF_Label FindChild(int theTag, bool isCreate=true)
Definition: DF_Label.cxx:314
bool operator==(const DF_Label &theLabel)
Definition: DF_Label.cxx:109
std::vector< DF_Attribute * > GetAttributes() const
Definition: DF_Label.cxx:238
bool IsRoot() const
Definition: DF_Label.cxx:222
bool ForgetAllAttributes(bool clearChildren=true) const
Definition: DF_Label.cxx:186