Loading...
Searching...
No Matches
StringWrapper.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#ifndef DRAIN_WRAPPER
33#define DRAIN_WRAPPER
34
35
36//#include "Converter.h"
37#include "Convert.h"
38
39namespace drain {
40
41
43
50template <typename T>
51class StringWrapper : public std::string {
52
53public:
54
55 inline
57 };
58
60 //template <typename T>
61 inline
62 StringWrapper(const T & x){
63 set(x);
64 };
65
66 // imitating std::string
67 StringWrapper<T> & operator=(const std::string & s){
68 assign(s);
69 return *this;
70 }
71
72 StringWrapper<T> & operator=(const char *s){
73 assign(s);
74 return *this;
75 }
76
77 StringWrapper<T> & operator=(char c){
78 std::string::operator=(c);
79 return *this;
80 }
81
83 template <typename T2>
85 assign(s);
86 return *this;
87 }
88
89 template <typename T2>
90 StringWrapper<T> & operator=(const T2 & x){
91 set(x);
92 return *this;
93 }
94
95
96 inline
97 void set(const std::string & s=""){
98 std::string::assign(s);
99 };
100
101 inline
102 void set(const StringWrapper & e){
103 std::string::assign(e);
104 };
105
106 inline
107 void set(const char *s){
108 std::string::assign(s);
109 };
110
111
113
119 //template <typename T2>
120 inline
121 void set(const T & x){
122 //Converter<T>::convert(x, *this);
123 Convert::convert(x, *this);
124 };
125
126 inline
127 bool operator==(const T & x){
128 std::string s;
129 //Converter<T>::convert(x, s);
130 Convert::convert(x, s);
131 return *this == s;
132 }
133
134
135};
136
137
138
139} // drain::
140
141#endif
142
static void convert(const T1 &src, T2 &dst)
General case: dispatch to Converter<T1> traits.
Definition Convert.h:130
String-like object easily supporting conversion from other types, like Enum values.
Definition StringWrapper.h:51
StringWrapper(const T &x)
All the other constructors, including default constructor.
Definition StringWrapper.h:62
StringWrapper< T > & operator=(const StringWrapper< T2 > &s)
Copy string of another StringWrapper.
Definition StringWrapper.h:84
void set(const T &x)
Set the value from an other, user-defined dictionary.
Definition StringWrapper.h:121
Definition DataSelector.cpp:1277