Loading...
Searching...
No Matches
Version.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
33
34#ifndef DRAIN_VERSION_T
35#define DRAIN_VERSION_T
36
37#include <sstream>
38
39namespace drain {
40
41
46template <typename V=void, char SEP='.'>
47struct Version {
48
49
50 template<typename ... TT>
51 Version(int i, const TT &... args){
52 set(i, args...);
53 }
54
55
56 inline
57 const std::string & str() const {
58 return _str;
59 }
60
61 inline
62 std::ostream & toStream(std::ostream & ostr) const {
63 ostr << _str;
64 return ostr;
65 }
66
67 inline
68 operator const std::string &() const {
69 return _str;
70 }
71
72 template<typename ... TT>
73 inline
74 void set(TT... args){
75 std::stringstream sstr;
76 build(sstr, args...);
77 _str = sstr.str();
78 };
79
80
81protected:
82
83 std::string _str;
84
85 /*
86 template <typename T>
87 inline
88 bool addSeparator(){
89 return (SEP != 0);
90 }
91 */
92
93
94 template<typename T, typename ... TT>
95 inline
96 void build(std::stringstream & sstr, const T & arg, TT... args){
97 if (SEP && (sstr.tellp() > 0)){
98 sstr << SEP;
99 }
100 sstr << arg;
101 build(sstr, args...);
102 };
103
104 template <typename ... TT>
105 inline
106 void build(std::stringstream & sstr, const std::string &arg, TT... args){
107 // No separator for strings
108 sstr << arg;
109 build(sstr, args...);
110 };
111
112 template <typename ... TT>
113 inline
114 void build(std::stringstream & sstr, char arg, TT... args){
115 // No separator for strings
116 sstr << arg;
117 build(sstr, args...);
118 };
119
120 template<typename ... TT>
121 inline
122 void build(std::stringstream & sstr, const char *arg, TT... args){
123 // No separator for strings
124 sstr << arg;
125 build(sstr, args...);
126 };
127
128 inline
129 void build(std::stringstream & sstr){
130 };
131
132
133};
134
135/*
136template <typename V=void, char SEP='.'>
137template <>
138inline
139bool Version<V,SEP>::addSeparator<std::string>(){
140 return false;
141}
142*/
143
144template <typename V>
145std::ostream & operator<<(std::ostream & ostr, const Version<V> & version){
146 version.toStream(ostr);
147 return ostr;
148}
149
150/*
151 * template<typename V=void, char SEP='.'>
152struct Version {
153
154 typedef unsigned short index_t;
155 // typedef int index_t;
156
157 template<typename ... TT>
158 Version(const TT &... args){
159 append(args...);
160 updateStr();
161 }
162
163 inline
164 Version(const std::initializer_list<index_t> & args) : id(args){
165 updateStr();
166 }
167
168 inline
169 operator const std::string &() const {
170 return idStr;
171 }
172
173 inline
174 operator const std::vector<index_t> &() const {
175 return id;
176 }
177
178 inline
179 const std::string & str() const {
180 return idStr;
181 }
182
183 inline
184 std::ostream & toStream(std::ostream & ostr) const {
185 ostr << idStr;
186 return ostr;
187 }
188
189private:
190
191 inline
192 void updateStr(){
193 std::stringstream sstr;
194 char sep=0;
195 for (index_t i: id){
196 if (sep){
197 sstr.put(sep);
198 }
199 else {
200 sep = SEP;
201 }
202 sstr << i;
203 }
204 idStr = sstr.str();
205 };
206
207 template<typename ... TT>
208 inline
209 void append(const index_t & i, TT... args){
210 id.push_back(i);
211 append(args...);
212 };
213
214 inline
215 void append(){
216 };
217
218 std::vector<index_t> id;
219
220 std::string idStr;
221
222};
223 *
224 */
225
226} // drain
227
228#endif
Definition DataSelector.cpp:1277
Definition Version.h:47