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, PRE, SPAN, TABLE, TR, TH, TD, UL};
78
79
80};
81
82template <>
84
88//class NodeHTML : public HTML, public NodeXML<html::tag_t> {
89class NodeHTML : public Html, public NodeXML<Html::tag_t> {
90// class NodeHTML : public NodeXML<html::tag_t> {
91
92
93public:
94
95 // typedef int tag_t;
96
98 NodeHTML(const Html::tag_t & t = Html::tag_t(0));
99
101 NodeHTML(const NodeHTML & node);
102
103 inline
104 ~NodeHTML(){};
105
107 virtual
108 bool isSingular() const override final;
109
111 virtual
112 bool isExplicit() const override final;
113
114 inline
115 NodeHTML & operator=(const NodeHTML & node){
116 return XML::xmlAssignNode(*this, node);
117 }
118
119 template <class T>
120 inline
121 NodeHTML & operator=(const T & s){
122 set(s); // XML
123 return *this;
124 }
125
126 /*
127 inline
128 NodeHTML & operator=(const std::initializer_list<std::pair<const char *,const drain::Variable> > &l){
129 set(l);
130 return *this;
131 }
132 */
133
134 /*
135 static // virtual
136 inline
137 std::ostream & docTypeToStream(std::ostream &ostr){
138 ostr << "<!DOCTYPE html>\n";
139 return ostr;
140 }
141 */
142
143 static
144 const FileInfo fileInfo;
145
146 // virtual void handleType(const Html::tag_t &t) override final;
147
148protected:
149
150 virtual
151 void handleType() override final;
152
153};
154
155
156
157
158
159// This is the way!
160template <> // for T (Tree class)
161inline
162std::ostream & NodeXML<Html::tag_t>::docTypeToStream(std::ostream &ostr){
163 ostr << "<!DOCTYPE html>\n";
164 return ostr;
165}
166
167template <> // for T (Tree class)
168template <> // for K (path elem arg)
169TreeHTML & TreeHTML::operator[](const Html::tag_t & type);
170
171template <> // for T (Tree class)
172template <> // for K (path elem arg)
173const TreeHTML & TreeHTML::operator[](const Html::tag_t & type) const;
174
175
176template <>
177inline
178//TreeHTML & TreeHTML::operator=(std::initializer_list<std::pair<const char *,const char *> > l){
179TreeHTML & TreeHTML::operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
180 return XML::xmlAssign(*this, l);
181}
182
184template <>
185template <>
186inline
187TreeHTML & TreeHTML::operator=(const std::string & arg){
188 XML::xmlAssignString(*this, arg);
189 return *this;
190}
191
192
193template <>
194template <class T>
195inline
196TreeHTML & TreeHTML::operator=(const T & arg){
197 return XML::xmlAssign(*this, arg);
198}
199
200/*
201inline
202std::ostream & operator<<(std::ostream &ostr, const NodeHTML & node){
203 return drain::Sprinter::toStream(ostr, node.getAttributes());
204}
205*/
206
207inline
208std::ostream & operator<<(std::ostream &ostr, const NodeHTML & node){
209 return node.nodeToStream(ostr);
210}
211
212
213inline
214std::ostream & operator<<(std::ostream &ostr, const TreeHTML & tree){
215 return NodeHTML::docToStream(ostr, tree);
216}
217
218/*
219inline
220std::ostream & operator<<(std::ostream &ostr, const TreeHTML & tree){
221 //ostr << "<!DOCTYPE html>\n";
222 //return drain::NodeXML<>::docToStream(ostr, tree);
223 drain::NodeHTML::toStream(ostr, tree);
224 return ostr;
225}
226*/
227
228
229
230// template <>
231// bool NodeXML<html::tag_t>::isSelfClosing() const;
232
233//template <>
234//bool NodeXML<html::tag_t>::isSingular() const;
235
236
237DRAIN_TYPENAME(NodeHTML);
238DRAIN_TYPENAME(Html);
239DRAIN_TYPENAME(Html::tag_t);
240
241
242// Important TAG type initialisations for elements.
243template <>
244const NodeXML<Html::tag_t>::xml_default_elem_map_t NodeXML<Html::tag_t>::xml_default_elems;
245
246// Preferred template specification
247template <>
248inline
249TreeHTML & TreeHTML::addChild(const TreeHTML::key_t & key){
250 return XML::xmlAddChild(*this, key);
251}
252
253
254// Preferred template specification
255template <>
256template <>
257inline
258TreeHTML & TreeHTML::operator()(const Html::tag_t & type){
259 return XML::xmlSetType(*this, type);
260}
261
262
263
264} // drain::
265
266#endif // DRAIN_TREE_HTML
267
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
Definition FileInfo.h:48
Definition TreeHTML.h:89
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:168
virtual bool isExplicit() const override final
Tell if this element should always have separate opening and closing tags even when empty,...
Definition TreeHTML.cpp:189
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 T & xmlAssign(T &dst, const T &src)
Assign another tree structure to another.
Definition XML.h:609
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:725
static TX & xmlSetType(TX &tree, const typename TX::node_data_t::xml_tag_t &type)
Definition XML.h:762
static T & xmlAddChild(T &tree, const std::string &key)
Definition XML.h:775
static N & xmlAssignNode(N &dst, const N &src)
Assign tree node (data) to another.
Definition XML.h:654
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.
A container for a static dictionary of enumeration values.
Definition EnumFlags.h:69
Definition TreeHTML.h:66