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
38namespace drain {
39
40
42
49template <typename T>
50class StringWrapper : public std::string {
51
52public:
53
54 inline
56 };
57
59 //template <typename T>
60 inline
61 StringWrapper(const T & x){
62 set(x);
63 };
64
65 // imitating std::string
66 StringWrapper<T> & operator=(const std::string & s){
67 assign(s);
68 return *this;
69 }
70
71 StringWrapper<T> & operator=(const char *s){
72 assign(s);
73 return *this;
74 }
75
76 StringWrapper<T> & operator=(char c){
77 std::string::operator=(c);
78 return *this;
79 }
80
82 template <typename T2>
84 assign(s);
85 return *this;
86 }
87
88 template <typename T2>
89 StringWrapper<T> & operator=(const T2 & x){
90 set(x);
91 return *this;
92 }
93
94
95 inline
96 void set(const std::string & s=""){
97 std::string::assign(s);
98 };
99
100 inline
101 void set(const StringWrapper & e){
102 std::string::assign(e);
103 };
104
105 inline
106 void set(const char *s){
107 std::string::assign(s);
108 };
109
110
112
118 //template <typename T2>
119 inline
120 void set(const T & x){
121 Converter<T>::convert(x, *this);
122 };
123
124 inline
125 bool operator==(const T & x){
126 std::string s;
128 return *this == s;
129 }
130
131
132};
133
134
135
136} // drain::
137
138#endif /* STRING_H_ */
139
Utility class with static conversions.
Definition Converter.h:53
String-like object easily supporting conversion from other types, like Enum values.
Definition StringWrapper.h:50
StringWrapper(const T &x)
All the other constructors, including default constructor.
Definition StringWrapper.h:61
StringWrapper< T > & operator=(const StringWrapper< T2 > &s)
Copy string of another StringWrapper.
Definition StringWrapper.h:83
void set(const T &x)
Set the value from an other, user-defined dictionary.
Definition StringWrapper.h:120
Definition DataSelector.cpp:1277