EndElement.h
1 /*
2  * Copyright (C) 2012 Marc Boris Duerner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 #ifndef Pt_Xml_EndElement_h
30 #define Pt_Xml_EndElement_h
31 
32 #include <Pt/Xml/Api.h>
33 #include <Pt/Xml/Node.h>
34 #include <Pt/Xml/QName.h>
35 #include <Pt/Xml/Namespace.h>
36 #include <Pt/NonCopyable.h>
37 
38 namespace Pt {
39 
40 namespace Xml {
41 
44 class EndElement : public Node
45  , private NonCopyable
46 {
47  public:
51  : Node(Node::EndElement)
52  , _name(0)
53  , _namespace(0)
54  { }
55 
58  void clear()
59  {
60  _name = 0;
61  _namespace = 0;
62  _nsmap.clear();
63  }
64 
67  const QName& name() const
68  { return *_name; }
69 
72  void setName(const QName& name, const Namespace& ns)
73  {
74  _name = &name;
75  _namespace = &ns;
76  }
77 
80  const String& namespaceUri() const
81  { return _namespace->namespaceUri(); }
82 
83  NamespaceMapping& namespaceMapping()
84  { return _nsmap; }
85 
86  const NamespaceMapping& namespaceMapping() const
87  { return _nsmap; }
88 
90  inline static const Node::Type nodeId()
91  { return Node::EndElement; }
92 
93  private:
94  const QName* _name;
95  const Namespace* _namespace;
96  NamespaceMapping _nsmap;
97 };
98 
104 {
105  return nodeCast<EndElement>(node);
106 }
107 
112 inline const EndElement* toEndElement(const Node* node)
113 {
114  return nodeCast<EndElement>(node);
115 }
116 
122 {
123  return nodeCast<EndElement>(node);
124 }
125 
130 inline const EndElement& toEndElement(const Node& node)
131 {
132  return nodeCast<EndElement>(node);
133 }
134 
135 } // namespace Xml
136 
137 } // namespace Pt
138 
139 #endif // Pt_Xml_EndElement_h
A namespace used in an XML document.
Definition: Namespace.h:46
const String & namespaceUri() const
Returns the namespace Uri for this element name.
Definition: EndElement.h:80
Represents a closing element tag in an XML document.
Definition: EndElement.h:44
Protects derived classes from being copied.
Definition: NonCopyable.h:54
A qualified XML name.
Definition: QName.h:46
EndElement * toEndElement(Node *node)
Casts a generic node to an EndElement node.
Definition: EndElement.h:103
const QName & name() const
Returns the qualified element name.
Definition: EndElement.h:67
void clear()
Clears all content.
Definition: EndElement.h:58
const String & namespaceUri() const
Returns the namespace URI.
Definition: Namespace.h:74
const EndElement & toEndElement(const Node &node)
Casts a generic node to an EndElement node.
Definition: EndElement.h:130
EndElement & toEndElement(Node &node)
Casts a generic node to an EndElement node.
Definition: EndElement.h:121
EndElement()
Constructs an empty EndElement.
Definition: EndElement.h:50
Unicode capable basic_string.
Definition: String.h:42
void setName(const QName &name, const Namespace &ns)
Returns the qualified element name.
Definition: EndElement.h:72
XML document node.
Definition: Node.h:50
const EndElement * toEndElement(const Node *node)
Casts a generic node to an EndElement node.
Definition: EndElement.h:112