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 <list>
37#include <string>
38
39
40
41namespace drain
42{
43
45
50
51public:
52
54
59 static inline
60 std::string scanSegment(std::istream & istr, const std::string & endChars){
61 std::stringstream sstr;
62 scanSegment(istr, endChars, sstr);
63 return sstr.str();
64 }
65
67
70 static
71 char scanSegment(std::istream & istr, const std::string & endChars, std::ostream & ostr);
72
76 template <class T>
77 static
78 char scanSegmentToValue(std::istream & istr, const std::string & endChars, T & dst);
79
81
84 static
85 char skipChars(std::istream & istr, const std::string skipChars); // = " \t\n\r"
86
90 static inline
91 char skipWhiteSpace(std::istream & istr){
92 return skipChars(istr, " \t\n\r");
93 }
94
95};
96
97// Specified implementation
98template <>
99char TextReader::scanSegmentToValue(std::istream & istr, const std::string & endChars, std::string & dst);
100
101// Default implementation for basic (numeric) types
102template <class T>
103char TextReader::scanSegmentToValue(std::istream & istr, const std::string & endChars, T & dst){
104 std::stringstream sstr;
105 char result = scanSegment(istr, endChars, sstr);
106 sstr >> dst;
107 return result;
108}
109
110
111
112} // ::drain
113
114#endif
Utility for scanning text segments.
Definition TextReader.h:49
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:53
static char skipWhiteSpace(std::istream &istr)
Definition TextReader.h:91
static char scanSegmentToValue(std::istream &istr, const std::string &endChars, T &dst)
Definition TextReader.h:103
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:60
Definition DataSelector.cpp:1277