Loading...
Searching...
No Matches
ClassXML.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 * ClassXML.h
33 *
34 * Author: mpeura
35 */
36
37
38
39#ifndef DRAIN_CLASS_XML
40#define DRAIN_CLASS_XML
41
42#include <drain/Enum.h>
43#include <ostream>
44
45//#include <drain/Sprinter.h>
46//#include <drain/FlexibleVariable.h>
47
48#include "ReferenceMap.h"
49#include "TreeUnordered.h"
50
51namespace drain {
52
53
55// Note: Currently separate from ClassListXML
56//class ClassXML : public StringWrapper<std::string> {
57class ClassXML : public MultiEnumWrapper {
58
59public:
60
61 inline
62 ClassXML(const std::string & s="") : MultiEnumWrapper(s){};
63
64 template <typename T>
65 inline
66 ClassXML(const T & arg) : MultiEnumWrapper(arg){};
67 //ClassXML(const T & x) : StringWrapper<std::string>(drain::Enum<T>::dict.getKey(x)){};
68
69 // inline
70 // ClassXML(const ClassXML & e) : MultiEnumWrapper((const std::string &)e){};
71
72 inline
73 ClassXML(const char *arg) : MultiEnumWrapper(std::string(arg)){};
74
75
76 virtual inline
77 ~ClassXML(){};
78
79 /*
80 inline
81 operator const std::string & () const {
82 return *this;
83 }
84 inline
85 const std::string & str() const {
86 return *this;
87 }
88 */
89
90 const std::string & strPrefixed() const {
91 prefixed = ".";
92 prefixed += *this;
93 return prefixed;
94 }
95
96protected:
97
98 // Class name prefixed with ".".
99 mutable
100 std::string prefixed;
101
102};
103
104
106
109// Note: Currently separate from ClassXML
110class ClassListXML : public std::set<std::string> {
111
112public:
113
114 template <typename ... TT>
115 inline
116 ClassListXML(const TT &... args){
117 add(args...);
118 };
119
121 template <typename ... TT>
122 inline
123 void add(const std::string & arg, const TT &... args) {
124 if (!arg.empty()){
125 insert(arg);
126 }
127 add(args...);
128 };
129
131 template <typename ... TT>
132 inline
133 void add(const char *arg, const TT &... args) {
134 add(std::string(arg), args...);
135 }
136
138 template <typename ... TT>
139 inline
140 void add(const ClassXML & arg, const TT &... args) {
141 if (!arg.empty()){
142 insert(arg);
143 }
144 add(args...);
145 };
146
148
154 template <typename E, typename ...TT>
155 inline
156 void add(const E & arg, const TT &... args) {
157 insert(drain::Enum<E>::dict.getKey(arg));
158 add(args...);
159 };
160
161
162 /* Compiler cannot derive (inner?) template
163 template <typename T, typename ... TT>
164 inline // drain::EnumFlagger<
165 void add(const typename drain::EnumFlagger<SingleFlagger<T> >::ivalue_t & enumArg, const TT &... args) {
166 // std::cerr << "ENUMS:" << enumArg.str() << '\n';
167 insert(enumArg.str());
168 add(args...);
169 };
170
171 template <typename EE>
172 inline // drain::EnumFlagger<
173 void add2(const typename SingleFlagger<EE>::ivalue_t & enumArg) {
174 // std::cerr << "ENUMS:" << enumArg.str() << '\n';
175 insert(enumArg.str());
176 // add(args...);
177 };
178 */
179
180 inline
181 bool has(const std::string & arg) const {
182 return (find(arg) != end());
183 };
184
185 inline
186 bool has(const char *arg) const {
187 return (find(arg) != end());
188 };
189
190 template <typename E>
191 inline
192 bool has(const E & arg) const {
193 return (find(drain::Enum<E>::dict.getKey(arg)) != end());
194 };
195
196
197 inline
198 void remove(const std::string & arg) {
199 iterator it = find(arg);
200 if (it != end()){
201 erase(it);
202 }
203 };
204
206 static
207 const SprinterLayout layout; // = {" "}; // , "\n", "=", ""};
208
209protected:
210
211 inline
212 void add(){};
213
214};
215
216
217inline
218std::ostream & operator<<(std::ostream &ostr, const ClassListXML & cls){
219 // static const SprinterLayout layout = {" "}; // , "\n", "=", ""};
220 Sprinter::sequenceToStream(ostr, (const std::set<std::string> &)cls, ClassListXML::layout);
221 return ostr;
222}
223
224
225
226
227
228} // drain::
229
230#endif /* TREEXML_H_ */
231
Container for style classes. Essentially a set of strings, with space-separated output support.
Definition ClassXML.h:110
void add(const std::string &arg, const TT &... args)
Add one or several classes.
Definition ClassXML.h:123
void add(const char *arg, const TT &... args)
Add one or several classes.
Definition ClassXML.h:133
void add(const E &arg, const TT &... args)
Add one or several classes.
Definition ClassXML.h:156
static const SprinterLayout layout
Uses spaces as separators.
Definition ClassXML.h:207
void add(const ClassXML &arg, const TT &... args)
Add one or several classes.
Definition ClassXML.h:140
A wrapper marking string an CSS effect.
Definition ClassXML.h:57
Definition Enum.h:260
static std::ostream & sequenceToStream(std::ostream &ostr, const T &x, const SprinterLayout &layout)
Convenience: if sequence type (array, list, set, map) not given, assume array.
Definition Sprinter.h:325
Definition DataSelector.cpp:1277
A container for a static dictionary of enumeration values.
Definition Enum.h:51
Definition Sprinter.h:137