Back to index

salome-kernel  6.5.0
DF_Label.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef DFLABEL_HXX
00021 #define DFLABEL_HXX
00022 
00023 #include "DF_definitions.hxx"
00024 #include "DF_Attribute.hxx"
00025 
00026 #include <string>
00027 #include <vector>
00028 #include <map>
00029 
00030 class DF_Document;
00031 
00032 
00033 class DF_LabelNode
00034 {
00035 public:
00036   DF_LabelNode();
00037   ~DF_LabelNode();
00038   void Reset();
00039 private:
00040   int                                      _tag;
00041   int                                      _depth;
00042   DF_LabelNode*                            _father;
00043   DF_LabelNode*                            _previous;
00044   DF_LabelNode*                            _next;
00045   DF_LabelNode*                            _firstChild;
00046   DF_LabelNode*                            _lastChild;
00047   DF_Document*                             _document;
00048   std::map< std::string, DF_Attribute* >   _attributes;
00049 
00050   friend class DF_Document;
00051   friend class DF_Label;
00052   friend class DF_ChildIterator;
00053   friend class DF_Attribute;
00054 };
00055 
00056 //Class DF_Label defines a persistence reference in DF_Document that contains a tree of Labels.
00057 //This reference is named "entry" and is a sequence of tags divided by ":". The root entry is "0:".
00058 //For example "0:1:1" corresponds the following structure
00059 // 0_
00060 //   |
00061 //   |_1_
00062 //       |
00063 //       |_ 1
00064 
00065 class DF_Label {
00066 public:
00067 
00068   //Returns a Label by its entry, if isCreated true the Label will be created if not exists
00069   Standard_EXPORT static DF_Label Label(const DF_Label& theLabel, const std::string& theEntry, bool isCreated = true);
00070 
00071   //Constructors: creates a root label
00072   Standard_EXPORT DF_Label();
00073 
00074   //Copy constructor
00075   Standard_EXPORT DF_Label(const DF_Label& theLabel);
00076 
00077   //Creates a Label from the LabelNode
00078   Standard_EXPORT DF_Label(DF_LabelNode* theNode);
00079 
00080   //Operator =
00081   Standard_EXPORT DF_Label& operator=(const DF_Label& theLabel);
00082 
00083   //Destructor
00084   Standard_EXPORT ~DF_Label();
00085 
00086   //Returns a smart pointer to Document which contains this Label
00087   Standard_EXPORT DF_Document* GetDocument() const;
00088 
00089   //Returns true if theLabel equals to this label
00090   Standard_EXPORT bool operator==(const DF_Label& theLabel);
00091 
00092   //Returns true if theLabel doesn't equals to this label
00093   Standard_EXPORT bool operator!=(const DF_Label& theLabel);
00094 
00095   //Returns a tag of this Label
00096   Standard_EXPORT int Tag() const;
00097 
00098   //Returns true if this Label is attached to the tree in the Document.
00099   Standard_EXPORT bool IsAttached();
00100 
00101   //Searches an Attribute with given ID located on this Label.
00102   //Returns true if the Attribute is found.
00103   Standard_EXPORT DF_Attribute* FindAttribute(const std::string& theID) const;
00104 
00105   //Returns true if there is an Attribute with given ID on this Label.
00106   Standard_EXPORT bool IsAttribute(const std::string& theID) const;
00107 
00108   //Adds theAttribute to the Label where this Attribute is located.
00109   //Returns true if theAttribute was added.
00110   Standard_EXPORT bool AddAttribute(DF_Attribute* theAttribute) const;
00111 
00112   //Forgets an Attribute with given ID located on the this Label.
00113   Standard_EXPORT bool ForgetAttribute(const std::string& theID) const;
00114 
00115   //Forgets all Attributes located on this Label.
00116   Standard_EXPORT bool ForgetAllAttributes(bool clearChildren = true) const;
00117 
00118   //Returns Father of this Label.
00119   Standard_EXPORT DF_Label Father() const;
00120 
00121   //Return true if the label is not initialized
00122   Standard_EXPORT bool IsNull() const;
00123 
00124   //Return true if the label is a Root label
00125   Standard_EXPORT bool IsRoot() const;
00126 
00127   //Returns true if this Label has Attributes.
00128   Standard_EXPORT bool HasAttributes() const;
00129 
00130   //Returns a list of Attributes of this Label.
00131   Standard_EXPORT std::vector<DF_Attribute*> GetAttributes() const;
00132 
00133   //Returns true if this Label has a child Label.
00134   Standard_EXPORT bool HasChild() const;
00135 
00136   //Returns a number of child Labels.
00137   Standard_EXPORT int NbChildren() const;
00138 
00139   //Returns the depth (a number of fathers required to identify the Label) of this Label in the tree.
00140   Standard_EXPORT int Depth() const;
00141 
00142   //Returns true if this Label is a descendant of theLabel.
00143   Standard_EXPORT bool IsDescendant(const DF_Label& theLabel);
00144 
00145   //Returns the root Label of a Label tree to which this Label belongs.
00146   Standard_EXPORT DF_Label Root() const;
00147 
00148   //Finds a child Label of this Label with a given tag. If isCreate = true and there is no child
00149   //Label with the given tag, the child Label is created.
00150   Standard_EXPORT DF_Label FindChild(int theTag, bool isCreate = true);
00151 
00152   //Creates a new child Label of this Label.
00153   Standard_EXPORT DF_Label NewChild();
00154 
00155   //Returns a string presentation of the entry
00156   Standard_EXPORT std::string Entry() const;
00157 
00158   //Returns true if theLabel is the same as me
00159   Standard_EXPORT bool IsEqual(const DF_Label& theLabel);
00160 
00161   Standard_EXPORT void dump();
00162 
00163 private:
00164   //Nullifies the content of the label
00165   void Nullify();
00166 
00167 friend class DF_Document;
00168 friend class DF_ChildIterator;
00169 
00170 private:
00171   DF_LabelNode* _node;
00172 };
00173 
00174 #endif