1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "DF_definitions.hxx"
24 #include "DF_Attribute.hxx"
42 DF_LabelNode* _father;
43 DF_LabelNode* _previous;
45 DF_LabelNode* _firstChild;
46 DF_LabelNode* _lastChild;
47 DF_Document* _document;
48 std::map< std::string, DF_Attribute* > _attributes;
50 friend class DF_Document;
51 friend class DF_Label;
52 friend class DF_ChildIterator;
53 friend class DF_Attribute;
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
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);
71 //Constructors: creates a root label
72 Standard_EXPORT DF_Label();
75 Standard_EXPORT DF_Label(const DF_Label& theLabel);
77 //Creates a Label from the LabelNode
78 Standard_EXPORT DF_Label(DF_LabelNode* theNode);
81 Standard_EXPORT DF_Label& operator=(const DF_Label& theLabel);
84 Standard_EXPORT ~DF_Label();
86 //Returns a smart pointer to Document which contains this Label
87 Standard_EXPORT DF_Document* GetDocument() const;
89 //Returns true if theLabel equals to this label
90 Standard_EXPORT bool operator==(const DF_Label& theLabel);
92 //Returns true if theLabel doesn't equals to this label
93 Standard_EXPORT bool operator!=(const DF_Label& theLabel);
95 //Returns a tag of this Label
96 Standard_EXPORT int Tag() const;
98 //Returns true if this Label is attached to the tree in the Document.
99 Standard_EXPORT bool IsAttached();
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;
105 //Returns true if there is an Attribute with given ID on this Label.
106 Standard_EXPORT bool IsAttribute(const std::string& theID) const;
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;
112 //Forgets an Attribute with given ID located on the this Label.
113 Standard_EXPORT bool ForgetAttribute(const std::string& theID) const;
115 //Forgets all Attributes located on this Label.
116 Standard_EXPORT bool ForgetAllAttributes(bool clearChildren = true) const;
118 //Returns Father of this Label.
119 Standard_EXPORT DF_Label Father() const;
121 //Return true if the label is not initialized
122 Standard_EXPORT bool IsNull() const;
124 //Return true if the label is a Root label
125 Standard_EXPORT bool IsRoot() const;
127 //Returns true if this Label has Attributes.
128 Standard_EXPORT bool HasAttributes() const;
130 //Returns a list of Attributes of this Label.
131 Standard_EXPORT std::vector<DF_Attribute*> GetAttributes() const;
133 //Returns true if this Label has a child Label.
134 Standard_EXPORT bool HasChild() const;
136 //Returns a number of child Labels.
137 Standard_EXPORT int NbChildren() const;
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;
142 //Returns true if this Label is a descendant of theLabel.
143 Standard_EXPORT bool IsDescendant(const DF_Label& theLabel);
145 //Returns the root Label of a Label tree to which this Label belongs.
146 Standard_EXPORT DF_Label Root() const;
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);
152 //Creates a new child Label of this Label.
153 Standard_EXPORT DF_Label NewChild();
155 //Returns a string presentation of the entry
156 Standard_EXPORT std::string Entry() const;
158 //Returns true if theLabel is the same as me
159 Standard_EXPORT bool IsEqual(const DF_Label& theLabel);
161 Standard_EXPORT void dump();
164 //Nullifies the content of the label
167 friend class DF_Document;
168 friend class DF_ChildIterator;