Loading...
Searching...
No Matches
TreeSLD.h
1/*
2
3MIT License
4
5Copyright (c) 2023 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 * TreeSLD.h
33 *
34 * Created on: Jun 24, 2012
35 * Author: mpeura
36 */
37
38#ifndef DRAIN_TREE_SLD
39#define DRAIN_TREE_SLD
40
41#include "drain/util/EnumFlags.h"
42#include "drain/util/FileInfo.h"
43#include "drain/util/Frame.h"
44#include "drain/util/TreeXML.h"
45
46namespace drain {
47
48namespace image {
49
50class NodeSLD;
51
52typedef UnorderedMultiTree<NodeSLD,false, drain::NodeXML<>::path_t> TreeSLD;
53//typedef drain::UnorderedMultiTree<NodeSLD,false, NodeXML<>::path_t> TreeSLD;
54
55struct SLD {
56
57
58 enum tag_t {
59 UNDEFINED=XML::UNDEFINED,
60 COMMENT=XML::COMMENT,
61 CTEXT=XML::CTEXT,
62 SCRIPT=XML::SCRIPT, // Not supported?
63 Abstract = 10,
64 ColorMap,
65 ColorMapEntry,
66 CssParameter,
67 FeatureTypeStyle,
68 Fill,
69 Graphic,
70 Mark,
71 Name,
72 NamedLayer,
73 Opacity,
74 PointSymbolizer,
75 RasterSymbolizer,
76 Rule,
77 Size,
78 StyledLayerDescriptor,
79 Title,
80 UserStyle,
81 WellKnownName,
82 };
83 // check CTEXT, maybe implement in XML
84
85};
86
87} // image::
88
89
90
91
92template <>
94
95DRAIN_ENUM_OSTREAM(image::SLD::tag_t)
96
97
98
99namespace image {
100
102
112class NodeSLD: public NodeXML<SLD::tag_t> {
113public:
114
115
116 static
117 const drain::FileInfo fileInfo;
118
119
121 NodeSLD(SLD::tag_t t = SLD::UNDEFINED);
122
124 NodeSLD(const NodeSLD & node);
125
126 inline virtual
127 ~NodeSLD(){};
128
130 inline
131 NodeSLD & operator=(const NodeSLD & node){
132 XML::xmlAssignNode(*this, node);
133 return *this;
134 }
135
137 inline
138 NodeSLD & operator=(const std::initializer_list<Variable::init_pair_t > &l){
139 set(l);
140 return *this;
141 }
142
143 template <class T>
144 inline
145 NodeSLD & operator=(const T & arg){
146 set(arg);
147 return *this;
148 }
149
150
151
153 virtual
154 void setAttribute(const std::string & key, const std::string &value) override;
155
157 virtual
158 void setAttribute(const std::string & key, const char *value) override;
159
161 virtual
162 bool isSingular() const override final;
163
165
174protected:
175
176
178
181 virtual
182 void handleType(const SLD::tag_t & t) override final;
183
184};
185
186
187/*
188template <typename P, typename A,typename V>
189void NodeSLD::setAlign(const P & pos, const A & axis, const V &value){
190 alignments[p][a] = v;
191}
192*/
193//typedef UnorderedMultiTree<NodeSLD,false, drain::NodeXML<>::path_t> TreeSLD;
194
195
196} // image::
197
198inline
199std::ostream & operator<<(std::ostream &ostr, const image::NodeSLD & node){
200 return node.nodeToStream(ostr);
201}
202
203inline
204std::ostream & operator<<(std::ostream &ostr, const image::TreeSLD & tree){
205 //return drain::NodeXML<const drain::image::NodeSLD>::docToStream(ostr, tree);
206 return image::NodeSLD::docToStream(ostr, tree);
207}
208
209
210} // drain::
211
212
213/*
214inline
215std::ostream & operator<<(std::ostream &ostr, const drain::image::TreeSLD & tree){
216 //return drain::NodeXML<const drain::image::NodeSLD>::docToStream(ostr, tree);
217 return drain::image::NodeSLD::docToStream(ostr, tree);
218}
219*/
220
221
222
223namespace drain {
224
225DRAIN_TYPENAME(image::NodeSLD);
226DRAIN_TYPENAME(image::SLD::tag_t);
227
228
229template <>
230const NodeXML<image::SLD::tag_t>::xml_default_elem_map_t NodeXML<image::SLD::tag_t>::xml_default_elems;
231
232/*
233template <>
234template <typename K, typename V>
235image::TreeSLD & image::TreeSLD::operator=(std::initializer_list<std::pair<K,V> > args){
236 drain::Logger mout(__FILE__, __FUNCTION__);
237 mout.attention("initlist pair<K,V>: ", args);
238 data.set(args); // what about TreeSLD & arg
239 return *this;
240}
241*/
242
243/*
244template <> // referring to Tree<NodeSLD>
245image::TreeSLD & image::TreeSLD::operator=(std::initializer_list<std::pair<const char *,const char *> > l);
246*/
247
248template <> // referring to Tree<NodeSLD>
249inline
250image::TreeSLD & image::TreeSLD::operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
251//image::TreeSLD & image::TreeSLD::operator=(std::initializer_list<std::pair<const char *,const char *> > l){
252 XML::xmlAssign(*this, l);
253 return *this;
254}
255
256
257template <>
258template <class T>
259inline
260image::TreeSLD & image::TreeSLD::operator=(const T & arg){
261 XML::xmlAssign(*this, arg);
262 return *this;
263}
264
265template <>
266template <>
267inline
268image::TreeSLD & image::TreeSLD::operator=(const std::string & arg){
269 XML::xmlAssignString(*this, arg);
270 return *this;
271}
272
273/*
274template <>
275template <>
276inline
277image::TreeSLD & image::TreeSLD::operator=(const char * arg){
278 XML::xmlAssignString(*this, arg);
279 return *this;
280}
281*/
282
283
284/*
285template <>
286template <>
287image::TreeSLD & image::TreeSLD::operator=(const char *arg){
288 return XML::xmlAssignString(*this, arg);
289}
290*/
291
292
293
294
295// Important! Useful and widely used – but fails with older C++ compilers ?
296template <>
297template <>
298inline
299image::TreeSLD & image::TreeSLD::operator()(const image::SLD::tag_t & type){
300 return XML::xmlSetType(*this, type);
301}
302
303template <>
304inline
305image::TreeSLD & image::TreeSLD::addChild(const image::TreeSLD::key_t & key){
306 return XML::xmlAddChild(*this, key);
307}
308
309/*
310template <> // for T (Tree class)
311template <> // for K (path elem arg)
312bool image::TreeSLD::hasChild(const image::svg::tag_t & type) const;
313*/
314
315template <> // for T (Tree class)
316template <> // for K (path elem arg)
317image::TreeSLD & image::TreeSLD::operator[](const image::SLD::tag_t & type);
318
319template <> // for T (Tree class)
320template <> // for K (path elem arg)
321const image::TreeSLD & image::TreeSLD::operator[](const image::SLD::tag_t & type) const ;
322
323} // drain::
324
325#endif // DRAIN_TREE_SLD
326
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
Definition FileInfo.h:48
Definition TreeXML.h:341
static std::ostream & docToStream(std::ostream &ostr, const V &tree)
Definition TreeXML.h:733
static X & xmlAssignNode(X &dst, const X &src)
Assign another tree structure to another.
Definition XML.h:554
Definition TreeSLD.h:112
NodeSLD & operator=(const std::initializer_list< Variable::init_pair_t > &l)
Copy data from a node. (Does not copy subtree.)
Definition TreeSLD.h:138
virtual void setAttribute(const std::string &key, const std::string &value) override
Set attribute value, handling units in string arguments, like in "50%" or "640px".
Definition TreeSLD.cpp:154
virtual void handleType(const SLD::tag_t &t) override final
Write transform, in addition to XML::ClassList.
Definition TreeSLD.cpp:121
virtual bool isSingular() const override final
Tell if this element should always have an explicit closing tag even when empty, like <STYLE></STYLE>
Definition TreeSLD.cpp:112
NodeSLD & operator=(const NodeSLD &node)
Copy data from a node. (Does not copy subtree.)
Definition TreeSLD.h:131
Definition DataSelector.cpp:1277
Wrapper for unique (static) dictionary of enum values.
Definition EnumFlags.h:66
Definition TreeSLD.h:55