Loading...
Searching...
No Matches
TextReader.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#ifndef TEXTREADER_H_
32#define TEXTREADER_H_
33
34#include <iostream>
35#include <sstream>
36#include <string>
37
38
39
40namespace drain
41{
42
44
49
50public:
51
53
58 static inline
59 std::string scanSegment(std::istream & istr, const std::string & endChars){
60 std::stringstream sstr;
61 scanSegment(istr, endChars, sstr);
62 return sstr.str();
63 }
64
66
69 static
70 char scanSegment(std::istream & istr, const std::string & endChars, std::ostream & ostr);
71
75 template <class T>
76 static
77 char scanSegmentToValue(std::istream & istr, const std::string & endChars, T & dst);
78
80
83 static
84 char skipChars(std::istream & istr, const std::string skipChars); // = " \t\n\r"
85
89 static inline
90 char skipWhiteSpace(std::istream & istr){
91 return skipChars(istr, " \t\n\r");
92 }
93
94};
95
96// Specified implementation
97template <>
98char TextReader::scanSegmentToValue(std::istream & istr, const std::string & endChars, std::string & dst);
99
100// Default implementation for basic (numeric) types
101template <class T>
102char TextReader::scanSegmentToValue(std::istream & istr, const std::string & endChars, T & dst){
103 std::stringstream sstr;
104 char result = scanSegment(istr, endChars, sstr);
105 sstr >> dst;
106 return result;
107}
108
109
110
111} // ::drain
112
113#endif
Utility for scanning text segments.
Definition TextReader.h:48
static char skipChars(std::istream &istr, const std::string skipChars)
Read stream until a char not in skipChars or end-of-file is encountered.
Definition TextReader.cpp:52
static char skipWhiteSpace(std::istream &istr)
Definition TextReader.h:90
static char scanSegmentToValue(std::istream &istr, const std::string &endChars, T &dst)
Definition TextReader.h:102
static std::string scanSegment(std::istream &istr, const std::string &endChars)
Read input stream until any char in endChars is encountered. The end char will not be included,...
Definition TextReader.h:59
Definition DataSelector.cpp:1277