ClassXML.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood 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 <ostream>
43 
44 //#include <drain/Sprinter.h>
45 //#include <drain/FlexibleVariable.h>
46 
47 #include "EnumFlags.h"
48 #include "ReferenceMap.h"
49 #include "TreeUnordered.h"
50 
51 namespace drain {
52 
53 
54 
56 
59 class ClassListXML : public std::set<std::string> {
60 
61 public:
62 
63  template <typename ... TT>
64  inline
65  ClassListXML(const TT &... args){
66  add(args...);
67  };
68 
70  template <typename ... TT>
71  inline
72  void add(const std::string & arg, const TT &... args) {
73  if (!arg.empty()){
74  insert(arg);
75  }
76  add(args...);
77  };
78 
79  template <typename ... TT>
80  inline
81  void add(const char *arg, const TT &... args) {
82  add(std::string(arg), args...);
83  }
84 
86 
92  template <typename E, typename ...TT>
93  inline
94  void add(const E & arg, const TT &... args) {
95  insert(drain::EnumDict<E>::dict.getKey(arg));
96  add(args...);
97  };
98 
99 
100  /* Compiler cannot derive (inner?) template
101  template <typename T, typename ... TT>
102  inline // drain::EnumFlagger<
103  void add(const typename drain::EnumFlagger<SingleFlagger<T> >::ivalue_t & enumArg, const TT &... args) {
104  // std::cerr << "ENUMS:" << enumArg.str() << '\n';
105  insert(enumArg.str());
106  add(args...);
107  };
108 
109  template <typename EE>
110  inline // drain::EnumFlagger<
111  void add2(const typename SingleFlagger<EE>::ivalue_t & enumArg) {
112  // std::cerr << "ENUMS:" << enumArg.str() << '\n';
113  insert(enumArg.str());
114  // add(args...);
115  };
116  */
117 
118  inline
119  bool has(const std::string & arg) const {
120  return (find(arg) != end());
121  };
122 
123  inline
124  bool has(const char *arg) const {
125  return (find(arg) != end());
126  };
127 
128  template <typename E>
129  inline
130  bool has(const E & arg) const {
131  return (find(drain::EnumDict<E>::dict.getKey(arg)) != end());
132  };
133 
134 
135  inline
136  void remove(const std::string & arg) {
137  iterator it = find(arg);
138  if (it != end()){
139  erase(it);
140  }
141  };
142 
144  static
145  const SprinterLayout layout; // = {" "}; // , "\n", "=", ""};
146 
147 protected:
148 
149  inline
150  void add(){};
151 
152 };
153 
154 
155 inline
156 std::ostream & operator<<(std::ostream &ostr, const ClassListXML & cls){
157  // static const SprinterLayout layout = {" "}; // , "\n", "=", ""};
158  Sprinter::sequenceToStream(ostr, (const std::set<std::string> &)cls, ClassListXML::layout);
159  return ostr;
160 }
161 
162 
163 
164 
165 
166 } // drain::
167 
168 #endif /* TREEXML_H_ */
169 
Container for style classes. Essentially a set of strings, with space-separated output support.
Definition: ClassXML.h:59
void add(const std::string &arg, const TT &... args)
Add one or several classes.
Definition: ClassXML.h:72
void add(const E &arg, const TT &... args)
Add one or several classes.
Definition: ClassXML.h:94
static const SprinterLayout layout
Uses spaces as separators.
Definition: ClassXML.h:141
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:321
Definition: DataSelector.cpp:1277
Wrapper for unique (static) dictionary of enum values.
Definition: EnumFlags.h:66
Definition: Sprinter.h:137