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#include "UtilsXML.h"
49
50namespace drain {
51
52
53class NodeHTML;
54
56/*
57 typedef NodeHTML::xml_tree_t TreeHTML;
58
59 Note: the typedef defined in XML is not the same, it is
60 drain::UnorderedMultiTree<NodeXML<html::tag_t>,false, NodeXML<>::path_t> CoreTreeHTML;
61 That is, the first template is NodeXML<html::tag_t> and not the complete NodeHTML
62 */
63// typedef drain::UnorderedMultiTree<NodeHTML,false, NodeXML<>::path_t> TreeHTML;
64typedef DRAIN_XML_TREE(NodeHTML) TreeHTML;
65
66
67// typedef drain::UnorderedMultiTree<NodeHTML,false, NodeXML<>::path_t> TreeHTML;
68
69struct Html {
70
71 enum tag_t {
72 UNDEFINED=NodeXML<>::UNDEFINED,
73 COMMENT=NodeXML<>::COMMENT,
74 CTEXT=NodeXML<>::CTEXT,
75 SCRIPT=NodeXML<>::SCRIPT,
76 STYLE=NodeXML<>::STYLE,
77 STYLE_SELECT=NodeXML<>::STYLE_SELECT,
78 SCOPE_CURLY=XML::SCOPE_CURLY,
79 HTML=10,
80 HEAD, BASE, LINK, META, TITLE,
81 BODY, A, BR, CAPTION, DIV, H1, H2, H3, HR, IMG, LI, OL, P, PRE, SPAN, TABLE, TR, TH, TD, UL};
82
83
84};
85
86
87DRAIN_TYPENAME(Html);
88DRAIN_TYPENAME(Html::tag_t);
89DRAIN_ENUM_DICT(Html::tag_t);
90DRAIN_ENUM_OSTREAM(Html::tag_t)
91
92
93
94// Note: this specialization actually applies to all XML paths of default type, that is NodeXML<int> .
95template <>
96template <>
97inline
98void drain::NodeXML<>::path_t::appendElem(const Html::tag_t & type){
99 // void TreeHTML::path_t::appendElem(const Html::tag_t & type){
100 appendElem(Enum<Html::tag_t>::dict.getKey(type, false));
101}
102
106class NodeHTML : public Html, public NodeXML<Html::tag_t> {
107
108
109public:
110
111 // typedef int tag_t;
112
114 NodeHTML(const Html::tag_t & t = Html::tag_t(0));
115
117 NodeHTML(const NodeHTML & node);
118
119 inline
120 ~NodeHTML(){};
121
123 virtual
124 bool isSingular() const override final;
125
127 virtual
128 bool isExplicit() const override final;
129
130 inline
131 NodeHTML & operator=(const NodeHTML & node){
132 return XML::xmlAssignNode(*this, node);
133 }
134
135 template <class T>
136 inline
137 NodeHTML & operator=(const T & s){
138 set(s); // XML
139 return *this;
140 }
141
142 static
143 const FileInfo fileInfo;
144
145protected:
146
147 virtual
148 void handleType() override final;
149
150};
151
152
153DRAIN_TYPENAME(NodeHTML);
154
155DRAIN_XML_EASY_TYPE(TreeHTML)
156
157inline
158std::ostream & operator<<(std::ostream &ostr, const NodeHTML & node){
159 return node.nodeToStream(ostr);
160}
161
162template <> // T for tag type
163inline
164std::ostream & NodeXML<Html::tag_t>::docTypeToStream(std::ostream &ostr){
165 ostr << "<!DOCTYPE html>\n";
166 return ostr;
167}
168
169// Handles TAG type selection for some elements.
170template <>
171const NodeXML<Html::tag_t>::xml_default_elem_map_t NodeXML<Html::tag_t>::xml_default_elems;
172
174
177template <>
178inline
179void TreeHTML::initChild(TreeHTML & child) const {
181}
182
183
184DRAIN_GETKEY_ENUM(TreeHTML, Html::tag_t)
185// const TreeHTML::key_t & TreeHTML::getKey(const Html::tag_t & type){
186// return Enum<Html::tag_t>::dict.getKey(type, false);
187
188template <> // for T (Tree class)
189template <> // for K (path elem arg)
190inline
191const TreeHTML::key_t & TreeHTML::getKey(const ClassXML & cls){
192 return cls.strPrefixed();
193}
194
195
196template <>
197inline
198TreeHTML & TreeHTML::operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
199 return UtilsXML::assign(*this, l);
200}
201
203template <>
204template <>
205inline
206TreeHTML & TreeHTML::operator=(const std::string & arg){
207 UtilsXML::assignString(*this, arg);
208 return *this;
209}
210
211
212template <>
213template <class T>
214inline
215TreeHTML & TreeHTML::operator=(const T & arg){
216 return UtilsXML::assign(*this, arg);
217}
218
219
220inline
221std::ostream & operator<<(std::ostream &ostr, const TreeHTML & tree){
222 return NodeHTML::docToStream(ostr, tree);
223}
224
225
226
227} // drain::
228
229
230
231#endif // DRAIN_TREE_HTML
232
Definition FileInfo.h:47
Definition TreeHTML.h:106
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:192
virtual bool isExplicit() const override final
Tell if this element should always have separate opening and closing tags even when empty,...
Definition TreeHTML.cpp:213
Definition TreeXML.h:55
static std::ostream & docTypeToStream(std::ostream &ostr)
Write the XML definition beginning any XML document.
Definition TreeXML.h:358
virtual std::ostream & nodeToStream(std::ostream &ostr, tag_display_mode mode=EMPTY_TAG) const override
Dumps info. Future option: outputs leading and ending tag.
Definition TreeXML.h:412
void appendElem(const elem_t &elem)
Main method for adding elements.
Definition Path.h:279
static T & assign(T &dst, const T &src)
Assign another tree structure to another.
Definition UtilsXML.h:108
static TX & assignString(TX &tree, const std::string &s)
When assigning a string, create new element unless the element itself is of type CTEXT.
Definition UtilsXML.h:183
static bool initChildWithDefaultType(const T &tree, T &child)
Definition UtilsXML.h:91
static N & xmlAssignNode(N &dst, const N &src)
Assign tree node (data) to another.
Definition XML.h:887
Definition Data.h:1473
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
A container for a static dictionary of enumeration values.
Definition Enum.h:51
Definition TreeHTML.h:69