DocType.h
1 /*
2  * Copyright (C) 2012 by 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_DocType_h
30 #define Pt_Xml_DocType_h
31 
32 #include <Pt/Xml/Api.h>
33 #include <Pt/Xml/Node.h>
34 #include <Pt/Xml/QName.h>
35 #include <Pt/String.h>
36 #include <Pt/Types.h>
37 #include <Pt/NonCopyable.h>
38 
39 namespace Pt {
40 
41 namespace Xml {
42 
43 class DocTypeDefinition;
44 
52 class PT_XML_API DocType : public Node
53  , private Pt::NonCopyable
54 {
55  public:
58  explicit DocType(DocTypeDefinition& dtd);
59 
62  ~DocType();
63 
66  void clear();
67 
70  bool isExternal() const;
71 
74  bool isInternal() const;
75 
78  void setInternal(bool hasInternal);
79 
82  const QName& rootName() const;
83 
86  const Pt::String& publicId() const
87  { return _publicId; }
88 
91  void setPublicId(const Pt::String& pubId)
92  { _publicId = pubId; }
93 
96  const Pt::String& systemId() const
97  { return _systemId; }
98 
101  void setSystemId(const Pt::String& sysId)
102  { _systemId = sysId; }
103 
105  inline static Node::Type nodeId()
106  { return Node::DocType; }
107 
108  private:
109  DocTypeDefinition* _dtd;
110  Pt::String _publicId;
111  Pt::String _systemId;
112  Pt::varint_t _internal;
113 };
114 
119 inline DocType* toDocType(Node* node)
120 {
121  return nodeCast<DocType>(node);
122 }
123 
128 inline const DocType* toDocType(const Node* node)
129 {
130  return nodeCast<DocType>(node);
131 }
132 
137 inline DocType& toDocType(Node& node)
138 {
139  return nodeCast<DocType>(node);
140 }
141 
146 inline const DocType& toDocType(const Node& node)
147 {
148  return nodeCast<DocType>(node);
149 }
150 
158 class PT_XML_API EndDocType : public Node
159  , private Pt::NonCopyable
160 {
161  public:
164  EndDocType();
165 
168  ~EndDocType();
169 
172  void clear();
173 
176  bool isExternal() const;
177 
180  bool isInternal() const;
181 
184  void setInternal(bool value);
185 
187  inline static Node::Type nodeId()
188  { return Node::EndDocType; }
189 
190  private:
191  Pt::varint_t _internal;
192 };
193 
199 {
200  return nodeCast<EndDocType>(node);
201 }
202 
207 inline const EndDocType* toEndDocType(const Node* node)
208 {
209  return nodeCast<EndDocType>(node);
210 }
211 
217 {
218  return nodeCast<EndDocType>(node);
219 }
220 
225 inline const EndDocType& toEndDocType(const Node& node)
226 {
227  return nodeCast<EndDocType>(node);
228 }
229 
230 } // namespace Xml
231 
232 } // namespace Pt
233 
234 #endif // Pt_Xml_DocType_h
A DocType node represents the begin of a DTD.
Definition: DocType.h:52
EndDocType & toEndDocType(Node &node)
Casts a generic node to a EndDocType node.
Definition: DocType.h:216
Protects derived classes from being copied.
Definition: NonCopyable.h:54
DocType * toDocType(Node *node)
Casts a generic node to a DocType node.
Definition: DocType.h:119
const EndDocType * toEndDocType(const Node *node)
Casts a generic node to a EndDocType node.
Definition: DocType.h:207
const EndDocType & toEndDocType(const Node &node)
Casts a generic node to a EndDocType node.
Definition: DocType.h:225
A qualified XML name.
Definition: QName.h:46
const DocType * toDocType(const Node *node)
Casts a generic node to a DocType node.
Definition: DocType.h:128
const DocType & toDocType(const Node &node)
Casts a generic node to a DocType node.
Definition: DocType.h:146
const Pt::String & publicId() const
Returns the public ID of the external subset.
Definition: DocType.h:86
The DocTypeDefinition of an XML document.
Definition: DocTypeDefinition.h:57
EndDocType * toEndDocType(Node *node)
Casts a generic node to a EndDocType node.
Definition: DocType.h:198
DocType & toDocType(Node &node)
Casts a generic node to a DocType node.
Definition: DocType.h:137
An EndDocType node represents the end of a DTD.
Definition: DocType.h:158
Unicode capable basic_string.
Definition: String.h:42
void setPublicId(const Pt::String &pubId)
Sets the public ID of the external subset.
Definition: DocType.h:91
void setSystemId(const Pt::String &sysId)
Sets the system ID of the external subset.
Definition: DocType.h:101
XML document node.
Definition: Node.h:50
const Pt::String & systemId() const
Returns the system ID of the external subset.
Definition: DocType.h:96