Loading...
Searching...
No Matches
TreeHTML.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31/*
32 * TreeXML.h
33 *
34 * Created on: Jun 24, 2012
35 * Author: mpeura
36 */
37
38
39
40#ifndef DRAIN_TREE_HTML
41#define DRAIN_TREE_HTML
42
43#include <ostream>
44
45#include "FileInfo.h"
46#include "ReferenceMap.h"
47#include "TreeXML.h"
48
49namespace drain {
50
51
52class NodeHTML;
53
55/*
56 typedef NodeHTML::xml_tree_t TreeHTML;
57
58 Note: the typedef defined in XML is not the same, it is
59 drain::UnorderedMultiTree<NodeXML<html::tag_t>,false, NodeXML<>::path_t> CoreTreeHTML;
60 That is, the first template is NodeXML<html::tag_t> and not the complete NodeHTML
61 */
62typedef drain::UnorderedMultiTree<NodeHTML,false, NodeXML<>::path_t> TreeHTML;
63
64// typedef drain::UnorderedMultiTree<NodeHTML,false, NodeXML<>::path_t> TreeHTML;
65
66struct html {
67
68 enum tag_t {
69 UNDEFINED=NodeXML<>::UNDEFINED,
70 COMMENT=NodeXML<>::COMMENT,
71 CTEXT=NodeXML<>::CTEXT,
72 SCRIPT=NodeXML<>::SCRIPT,
73 STYLE=NodeXML<>::STYLE,
74 STYLE_SELECT=NodeXML<>::STYLE_SELECT,
75 HTML,
76 HEAD, BASE, LINK, META, TITLE,
77 BODY, A, BR, CAPTION, DIV, H1, H2, H3, HR, IMG, LI, OL, P, SPAN, TABLE, TR, TH, TD, UL};
78
79 // check CTEXT, maybe implement in XML
80 // typedef NodeHTML xml_nod e_t;
81 // typedef TreeHTML tree_t;
82
83};
84
85template <>
87
91//class NodeHTML : public HTML, public NodeXML<html::tag_t> {
92class NodeHTML : public html, public NodeXML<html::tag_t> {
93// class NodeHTML : public NodeXML<html::tag_t> {
94
95
96public:
97
98 // typedef int tag_t;
99
101 NodeHTML(const html::tag_t & t = html::tag_t(0));
102
104 NodeHTML(const NodeHTML & node);
105
106 inline
107 ~NodeHTML(){};
108
110 virtual
111 bool isSingular() const override final;
112
114 virtual
115 bool isExplicit() const override final;
116
117 inline
118 NodeHTML & operator=(const NodeHTML & node){
119 return XML::xmlAssignNode(*this, node);
120 }
121
122 template <class T>
123 inline
124 NodeHTML & operator=(const T & s){
125 set(s); // XML
126 return *this;
127 }
128
129 /*
130 inline
131 NodeHTML & operator=(const std::initializer_list<std::pair<const char *,const drain::Variable> > &l){
132 set(l);
133 return *this;
134 }
135 */
136
137 /*
138 static // virtual
139 inline
140 std::ostream & docTypeToStream(std::ostream &ostr){
141 ostr << "<!DOCTYPE html>\n";
142 return ostr;
143 }
144 */
145
146 static
147 const FileInfo fileInfo;
148
149protected:
150
151 virtual
152 void handleType(const html::tag_t &t) override final;
153
154};
155
156
157
158
159
160// This is the way!
161template <> // for T (Tree class)
162inline
163std::ostream & NodeXML<html::tag_t>::docTypeToStream(std::ostream &ostr){
164 ostr << "<!DOCTYPE html>\n";
165 return ostr;
166}
167
168template <> // for T (Tree class)
169template <> // for K (path elem arg)
170TreeHTML & TreeHTML::operator[](const html::tag_t & type);
171
172template <> // for T (Tree class)
173template <> // for K (path elem arg)
174const TreeHTML & TreeHTML::operator[](const html::tag_t & type) const;
175
176
177template <>
178inline
179//TreeHTML & TreeHTML::operator=(std::initializer_list<std::pair<const char *,const char *> > l){
180TreeHTML & TreeHTML::operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
181 return XML::xmlAssign(*this, l);
182}
183
185template <>
186template <>
187inline
188TreeHTML & TreeHTML::operator=(const std::string & arg){
189 XML::xmlAssignString(*this, arg);
190 return *this;
191}
192
193
194template <>
195template <class T>
196inline
197TreeHTML & TreeHTML::operator=(const T & arg){
198 return XML::xmlAssign(*this, arg);
199}
200
201/*
202inline
203std::ostream & operator<<(std::ostream &ostr, const NodeHTML & node){
204 return drain::Sprinter::toStream(ostr, node.getAttributes());
205}
206*/
207
208inline
209std::ostream & operator<<(std::ostream &ostr, const NodeHTML & node){
210 return node.nodeToStream(ostr);
211}
212
213
214inline
215std::ostream & operator<<(std::ostream &ostr, const TreeHTML & tree){
216 return NodeHTML::docToStream(ostr, tree);
217}
218
219/*
220inline
221std::ostream & operator<<(std::ostream &ostr, const TreeHTML & tree){
222 //ostr << "<!DOCTYPE html>\n";
223 //return drain::NodeXML<>::docToStream(ostr, tree);
224 drain::NodeHTML::toStream(ostr, tree);
225 return ostr;
226}
227*/
228
229
230
231// template <>
232// bool NodeXML<html::tag_t>::isSelfClosing() const;
233
234//template <>
235//bool NodeXML<html::tag_t>::isSingular() const;
236
237
238DRAIN_TYPENAME(NodeHTML);
239DRAIN_TYPENAME(html);
240DRAIN_TYPENAME(html::tag_t);
241
242
243// Important TAG type initialisations for elements.
244template <>
245const NodeXML<html::tag_t>::xml_default_elem_map_t NodeXML<html::tag_t>::xml_default_elems;
246
247// Preferred template specification
248template <>
249inline
250TreeHTML & TreeHTML::addChild(const TreeHTML::key_t & key){
251 return XML::xmlAddChild(*this, key);
252}
253
254
255// Preferred template specification
256template <>
257template <>
258inline
259TreeHTML & TreeHTML::operator()(const html::tag_t & type){
260 return XML::xmlSetType(*this, type);
261}
262
263
264
265} // drain::
266
267#endif // DRAIN_TREE_HTML
268
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
Definition FileInfo.h:48
Definition TreeHTML.h:92
virtual bool isSingular() const override final
Tell if this element should always be a single tag, not separate opening and closing tags.
Definition TreeHTML.cpp:163
virtual void handleType(const html::tag_t &t) override final
Internal function called after setType()
Definition TreeHTML.cpp:147
virtual bool isExplicit() const override final
Tell if this element should always have separate opening and closing tags even when empty,...
Definition TreeHTML.cpp:184
Definition TreeXML.h:341
static std::ostream & docTypeToStream(std::ostream &ostr)
Write the XML definition beginning any XML document.
Definition TreeXML.h:751
static std::ostream & docToStream(std::ostream &ostr, const V &tree)
Definition TreeXML.h:733
static TX & xmlAssignString(TX &tree, const std::string &s)
When assigning a string, create new element unless the element itself is of type CTEXT.
Definition XML.h:618
static TX & xmlSetType(TX &tree, const typename TX::node_data_t::xml_tag_t &type)
Definition XML.h:679
static T & xmlAddChild(T &tree, const std::string &key)
Definition XML.h:692
static X & xmlAssignNode(X &dst, const X &src)
Assign another tree structure to another.
Definition XML.h:554
static TX & xmlAssign(TX &dst, const TX &src)
Assign another tree structure to another.
Definition XML.h:513
Definition DataSelector.cpp:1277
drain::UnorderedMultiTree< NodeHTML, false, NodeXML<>::path_t > TreeHTML
The HTML data structure.
Definition TreeHTML.h:62
DRAIN_TYPENAME(void)
Add a specialization for each type of those you want to support.
Wrapper for unique (static) dictionary of enum values.
Definition EnumFlags.h:66
Definition TreeHTML.h:66