Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SVOutStream.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2015.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hendrik Weisser $
32 // $Authors: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_FORMAT_SVOUTSTREAM_H
36 #define OPENMS_FORMAT_SVOUTSTREAM_H
37 
39 #include <ostream>
40 #include <boost/math/special_functions/fpclassify.hpp> // for "isnan"
41 
42 namespace OpenMS
43 {
45  enum Newline {nl};
46 
54  class OPENMS_DLLAPI SVOutStream :
55  public std::ostream
56  {
57 public:
66  SVOutStream(std::ostream& out, const String& sep = "\t",
67  const String& replacement = "_",
69 
70 
76  SVOutStream& operator<<(String str); // use call-by-value here
77 
78 
84  SVOutStream& operator<<(const std::string& str);
85 
86 
92  SVOutStream& operator<<(const char* c_str);
93 
94 
100  SVOutStream& operator<<(const char c);
101 
103  SVOutStream& operator<<(std::ostream& (*fp)(std::ostream&));
104 
111 
113  template <typename T>
114  SVOutStream& operator<<(const T& value)
115  {
116  if (!newline_) (std::ostream&) *this << sep_;
117  else newline_ = false;
118  (std::ostream&) *this << value;
119  return *this;
120  }
121 
123  SVOutStream& write(const String& str); // write unmodified string
124 
125 
131  bool modifyStrings(bool modify);
132 
133 
135  template <typename NumericT>
136  SVOutStream& writeValueOrNan(NumericT thing)
137  {
138  if ((boost::math::isfinite)(thing)) return operator<<(thing);
139 
140  bool old = modifyStrings(false);
141  if ((boost::math::isnan)(thing)) operator<<(nan_);
142  else if (thing < 0) operator<<("-" + inf_);
143  else operator<<(inf_);
144  modifyStrings(old);
145  return *this;
146  }
147 
148 protected:
151 
154 
157 
160 
163 
166 
168  bool newline_;
169 
171  std::stringstream ss_;
172  };
173 
174 }
175 
176 #endif
A more convenient string class.
Definition: String.h:57
Definition: String.h:80
const double c
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::stringstream ss_
Stream for testing if a manipulator is "std::endl".
Definition: SVOutStream.h:171
bool newline_
Are we at the beginning of a line? (Otherwise, insert separator before next item.) ...
Definition: SVOutStream.h:168
String nan_
String to use for NaN values.
Definition: SVOutStream.h:156
Definition: SVOutStream.h:45
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
SVOutStream & operator<<(const T &value)
Generic stream output operator (for non-character-based types)
Definition: SVOutStream.h:114
String replacement_
Replacement for separator.
Definition: SVOutStream.h:153
String inf_
String to use for Inf values.
Definition: SVOutStream.h:159
SVOutStream & writeValueOrNan(NumericT thing)
Write a numeric value or "nan"/"inf"/"-inf", if applicable (would not be needed for Linux) ...
Definition: SVOutStream.h:136
QuotingMethod
How to handle embedded quotes when quoting strings.
Definition: String.h:80
String sep_
Separator string.
Definition: SVOutStream.h:150
Stream class for writing to comma/tab/...-separated values files.
Definition: SVOutStream.h:54
Newline
custom newline indicator
Definition: SVOutStream.h:45
String::QuotingMethod quoting_
String quoting method.
Definition: SVOutStream.h:162
bool modify_strings_
On/off switch for modification of strings.
Definition: SVOutStream.h:165

OpenMS / TOPP release 2.0.0 Documentation generated on Fri May 29 2015 17:20:31 using doxygen 1.8.9.1