1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * As a special exception, you may use this file as part of a free
8  * software library without restriction. Specifically, if other files
9  * instantiate templates or use macros or inline functions from this
10  * file, or you compile this file and link it with other files to
11  * produce an executable, this file does not by itself cause the
12  * resulting executable to be covered by the GNU General Public
13  * License. This exception does not however invalidate any other
14  * reasons why the executable file might be covered by the GNU Library
15  * General Public License.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25  */
26 #ifndef cxxtools_xml_EndElement_h
27 #define cxxtools_xml_EndElement_h
28 
29 #include <cxxtools/xml/api.h>
30 #include <cxxtools/xml/node.h>
31 #include <cxxtools/string.h>
32 
33 
34 namespace cxxtools {
35 
36     namespace xml {
37 
38         /**
39          * @brief An end element (Node) which represents a closing tag of an XML document.
40          *
41          * An end element is created when the parser reaches an end tag, for example $&lt;/a>$.
42          * An EndElement object only stores the name of the tag. To access the attributes of the tag the
43          * start tag has to be read. The body of the tag can be accessed by reading the previous
44          * Character node(s).
45          *
46          * Use name() to get the name of the tag which was closed.
47          *
48          * When parsing $<a>test</a>$ a StartElement, a Character and finally an EndElement node is
49          * created. If an empty tag is parsed, like for example $</a>$, a StartElement and an EndElement
50          * is created.
51          *
52          * @see StartElement
53          * @see Node
54          */
55         class CXXTOOLS_XML_API EndElement : public Node
56         {
57             public:
58                 /**
59                  * @brief Constructs a new EndElement object with the given (optional) string as tag name.
60                  *
61                  * @param name The name of the EndElement object. This is an optional parameter.
62                  * Default is an empty string.
63                  */
64                 explicit EndElement(const String& name = String())
Node(Node::EndElement)65                 : Node(Node::EndElement),
66                   _name(name)
67                 { }
68 
69                 /**
70                  * @brief Clones this EndElement object by creating a duplicate on the heap and returning it.
71                  * @return A cloned version of this EndElement object.
72                  */
clone()73                 EndElement* clone() const
74                 {return new EndElement(*this);}
75 
clear()76                 void clear()
77                 { _name.clear(); }
78 
79                 /**
80                  * @brief Returns the tag name of the closing tag for which this EndElement object was created.
81                  *
82                  * When parsing <a>test</a> a StartElement, a Character and finally an EndElement node is
83                  * created. The EndElement has the name "a". If an empty tag is parsed, like for example </a>,
84                  * a StartElement and an EndElement ("a") is created.
85                  *
86                  * @return The tag name of the closing tag for which this EndElement object was created.
87                  */
name()88                 String& name()
89                 { return _name; }
90 
91                 /**
92                  * @brief Returns the tag name of the closing tag for which this EndElement object was created.
93                  *
94                  * When parsing <a>test</a> a StartElement, a Character and finally an EndElement node is
95                  * created. The EndElement has the name "a". If an empty tag is parsed, like for example </a>,
96                  * a StartElement and an EndElement ("a") is created.
97                  *
98                  * @return The tag name of the closing tag for which this EndElement object was created.
99                  */
name()100                 const String& name() const
101                 { return _name; }
102 
103                 /**
104                  * @brief Sets the tag name of the end tag for which this EndElement object was created.
105                  * @param name The new name for this EndElement object.
106                  */
setName(const String & name)107                 void setName(const String& name)
108                 { _name = name; }
109 
110                 /**
111                  * @brief Compares this EndElement object with the given node.
112                  *
113                  * This method returns $true$ if the given node also is a EndElement object and
114                  * the name of both EndElement objects is the same. Otherwise it returns $false$.
115                  *
116                  * @param node This Node object is compared to the current EndElement node object.
117                  * @return $true if this EndElement object is the same as the given node.
118                  */
119                 virtual bool operator==(const Node& node) const;
120 
121             private:
122                 //! The tag name of this end tag.
123                 String _name;
124         };
125 
126     }
127 
128 }
129 
130 #endif
131