StreamBuilder.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  * StringTools.h
33  *
34  * Created on: Feb, 2022
35  * Author: mpeura
36  */
37 
38 #ifndef DRAIN_STREAM_BUILDER
39 #define DRAIN_STREAM_BUILDER
40 
41 /*
42 #include <limits>
43 #include <iterator>
44 #include <sstream>
45 #include <iostream>
46 #include <list>
47 #include <map>
48 */
49 
50 //#include "RegExp.h"
51 #include <iostream>
52 #include <string>
53 #include <sstream>
54 
55 namespace drain {
56 
57 // TODO:
58 template <char SEP=0>
59 class StreamBuilder : public std::stringstream {
60 
61 public:
62 
63  template<typename ... TT>
64  StreamBuilder(const TT &... args){
65  create(args...);
66  }
67 
68  template<typename ... TT>
69  StreamBuilder & create(const TT &... args) {
70  std::stringstream::str("");
71  return add(args...);
72  }
73 
74  template<class T, typename ... TT>
75  StreamBuilder & add(const T & arg, const TT &... args) {
76  if (SEP && (tellp() > 0)){
77  *this << (SEP);
78  }
79  *this << arg;
80  return add(args...);
81  }
82 
83 
84 protected:
85 
86  /*
87  template<class T, typename ... TT>
88  StreamBuilder & addSeparated(const T & arg, const TT &... args) {
89  if (SEP){
90  *this << (SEP);
91  }
92  *this << arg;
93  return addSeparated(args...);
94  }
95 
96  // Terminal
97  inline
98  StreamBuilder & addSeparated(){
99  return *this;
100  };
101  */
102 
103  // Terminal
104  inline
105  StreamBuilder & add(){
106  return *this;
107  };
108 
109 };
110 
111 
112 } // drain::
113 
114 #endif /* DRAIN_STREAM_BUILDER */
115 
Definition: StreamBuilder.h:59
Definition: DataSelector.cpp:1277