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#include <vector>
39
40namespace drain {
41
42template<typename V=void, char SEP='.'>
43struct Version {
44
45 typedef unsigned short index_t;
46 // typedef int index_t;
47
48 template<typename ... TT>
49 Version(const TT &... args){
50 append(args...);
51 updateStr();
52 }
53
54 inline
55 Version(const std::initializer_list<index_t> & args) : id(args){
56 updateStr();
57 }
58
59 inline
60 operator const std::string &() const {
61 return idStr;
62 }
63
64 inline
65 operator const std::vector<index_t> &() const {
66 return id;
67 }
68
69 inline
70 const std::string & str() const {
71 return idStr;
72 }
73
74 inline
75 std::ostream & toStream(std::ostream & ostr) const {
76 ostr << idStr;
77 return ostr;
78 }
79
80private:
81
82 inline
83 void updateStr(){
84 std::stringstream sstr;
85 char sep=0;
86 for (index_t i: id){
87 if (sep){
88 sstr.put(sep);
89 }
90 else {
91 sep = SEP;
92 }
93 sstr << i;
94 }
95 idStr = sstr.str();
96 };
97
98 template<typename ... TT>
99 inline
100 void append(const index_t & i, TT... args){
101 id.push_back(i);
102 append(args...);
103 };
104
105 inline
106 void append(){
107 };
108
109 std::vector<index_t> id;
110
111 std::string idStr;
112
113};
114
115template<typename V>
116std::ostream & operator<<(std::ostream & ostr, const Version<V> & version){
117 version.toStream(ostr);
118 return ostr;
119}
120
121} // drain
122
123#endif
Definition DataSelector.cpp:1277
Definition Version.h:43