Loading...
Searching...
No Matches
IosFormat.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#ifndef DRAIN_IOS_FORMAT_H_
33#define DRAIN_IOS_FORMAT_H_
34
35#include <drain/Log.h>
36#include <ios>
37
38
39namespace drain {
40
42
45class IosFormat {
46
47public:
48
49 inline
50 IosFormat(const std::ostream & ostr = std::cout){
51 copyFrom(ostr);
52 }
53
54 inline
55 void copyFrom(const std::ostream & ostr){
56 precision = ostr.precision();
57 fillChar = ostr.fill();
58 fieldWidth = ostr.width();
59 }
60
61
62 inline
63 void copyTo(std::ostream & ostr) const {
64 ostr.precision(precision);
65 ostr.fill(fillChar);
66 ostr.width(fieldWidth);
67 }
68
69
70 inline
71 char getFillChar() const {
72 return fillChar;
73 }
74
75 inline
76 void setFillChar(char c) {
77 this->fillChar = c;
78 }
79
80 inline
81 std::streamsize getFieldWidth() const {
82 return fieldWidth;
83 }
84
85 inline
86 void setFieldWidth(std::streamsize w) {
87 this->fieldWidth = w;
88 }
89
90 std::streamsize getPrecision() const {
91 return precision;
92 }
93
94 void setPrecision(std::streamsize precision) {
95 this->precision = precision;
96 }
97
98
99protected:
100
101 std::streamsize precision;
102 std::streamsize fieldWidth;
103 char fillChar;
104
105
106};
107
108inline
109std::ostream & operator<<(std::ostream & ostr, const IosFormat & iosformat){
110 if (iosformat.getFillChar())
111 ostr << iosformat.getFillChar();
112 ostr << iosformat.getFieldWidth() << "d";
113 ostr << "/0." << iosformat.getPrecision() << "f";
114 return ostr;
115}
116
117
118} // NAMESPACE
119
120#endif /* STRINGMAPPER_H_ */
121
122// Drain
Stores precision, fillChar and fieldWidth applied by STD streams.
Definition IosFormat.h:45
Definition DataSelector.cpp:1277