Entity.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_Entity_h
30#define Pt_Xml_Entity_h
31
32#include <Pt/Xml/Api.h>
33#include <Pt/Xml/Node.h>
34#include <Pt/NonCopyable.h>
35#include <Pt/String.h>
36#include <map>
37
38namespace Pt {
39
40namespace Xml {
41
44class Entity
45{
46 public:
49 explicit Entity(const Pt::String& name)
50 : _name(name)
51 , _ndata(false)
52 {}
53
56 const Pt::String& name() const
57 { return _name; }
58
61 bool isExternal() const
62 { return ! _publicId.empty() || ! _systemId.empty(); }
63
66 bool isInternal() const
67 { return _publicId.empty() && _systemId.empty(); }
68
71 const Pt::String& value() const
72 { return _value; }
73
77 { return _value; }
78
81 void setValue(const Pt::String& val)
82 { _value = val; }
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
106 bool isUnparsed() const
107 { return _ndata; }
108
111 void setUnparsed(const Pt::String& notation)
112 {
113 _ndata = true;
114 _value = notation;
115 }
116
120 { return _value; }
121
122 private:
123 Pt::String _name;
124 Pt::String _publicId;
125 Pt::String _systemId;
126 Pt::String _value;
127 bool _ndata;
128};
129
136class EntityReference : public Node
137 , private NonCopyable
138{
139 public:
144 , _entity(0)
145 { }
146
149 void clear()
150 {
151 _name.clear();
152 _entity = 0;
153 }
154
157 const Pt::String& name() const
158 { return _name; }
159
163 { return _name; }
164
168 { _name = name; }
169
172 const Entity* get() const
173 { return _entity; }
174
177 void setEntity(const Entity* entity)
178 { _entity = entity; }
179
181 inline static Node::Type nodeId()
182 { return Node::EntityReference; }
183
184 private:
185 Pt::String _name;
186 const Entity* _entity;
187};
188
194{
195 return nodeCast<EntityReference>(node);
196}
197
202inline const EntityReference* toEntityReference(const Node* node)
203{
204 return nodeCast<EntityReference>(node);
205}
206
212{
213 return nodeCast<EntityReference>(node);
214}
215
220inline const EntityReference& toEntityReference(const Node& node)
221{
222 return nodeCast<EntityReference>(node);
223}
224
227bool resolveDefaultEntity(String& entity);
228
231bool resolveCharacterEntity(String& entity);
232
233} // namespace Xml
234
235} // namespace Pt
236
237#endif // Pt_Xml_Entity_h
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
Unicode capable basic_string.
Definition Api-String.h:67
const EntityReference * toEntityReference(const Node *node)
Casts a generic node to an EntityReference node.
Definition Entity.h:202
EntityReference & toEntityReference(Node &node)
Casts a generic node to an EntityReference node.
Definition Entity.h:211
void setEntity(const Entity *entity)
Sets the entity this reference refers to.
Definition Entity.h:177
void setName(const Pt::String &name)
Sets the name of the entity this reference refers to.
Definition Entity.h:167
EntityReference()
Creates an EntityReference object.
Definition Entity.h:142
const EntityReference & toEntityReference(const Node &node)
Casts a generic node to an EntityReference node.
Definition Entity.h:220
const Pt::String & name() const
Returns the name of the entity this reference refers to.
Definition Entity.h:157
Pt::String & name()
Returns the name of the entity this reference refers to.
Definition Entity.h:162
EntityReference * toEntityReference(Node *node)
Casts a generic node to an EntityReference node.
Definition Entity.h:193
void clear()
Clears all content.
Definition Entity.h:149
const Entity * get() const
Returns the entity this reference refers to or a nullptr.
Definition Entity.h:172
An entity declaration in a DTD.
Definition Entity.h:45
const Pt::String & systemId() const
Returns the system ID of the entity.
Definition Entity.h:96
bool isExternal() const
Returns true if the entity in external.
Definition Entity.h:61
void setUnparsed(const Pt::String &notation)
Sets the notation of an unparsed entity (NDATA).
Definition Entity.h:111
const Pt::String & value() const
Returns the value of the entity.
Definition Entity.h:71
void setSystemId(const Pt::String &sysId)
Sets the system ID of the entity.
Definition Entity.h:101
Entity(const Pt::String &name)
Constructs with entity name.
Definition Entity.h:49
bool isUnparsed() const
Indicates if the entity is unparsed (NDATA).
Definition Entity.h:106
const Pt::String & notationName() const
Returns the name of the notation.
Definition Entity.h:119
void setValue(const Pt::String &val)
Sets the value of the entity.
Definition Entity.h:81
const Pt::String & publicId() const
Returns the public ID of the entity.
Definition Entity.h:86
const Pt::String & name() const
Returns the name of the entity.
Definition Entity.h:56
void setPublicId(const Pt::String &pubId)
Sets the public ID of the entity.
Definition Entity.h:91
Pt::String & value()
Returns the value of the entity.
Definition Entity.h:76
bool isInternal() const
Returns true if the entity in internal.
Definition Entity.h:66
Node(Type type)
Constructs a new Node object with the specified node type.
Definition Node.h:80
Read and write XML ducuments.
Core module.
Definition Allocator.h:33