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-2013.
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 {
51  class OPENMS_DLLAPI SVOutStream :
52  public std::ostream
53  {
54 public:
63  SVOutStream(std::ostream & out, const String & sep = "\t",
64  const String & replacement = "_",
66 
67 
73  SVOutStream & operator<<(String str); // use call-by-value here
74 
75 
81  SVOutStream & operator<<(const std::string & str);
82 
83 
89  SVOutStream & operator<<(const char * c_str);
90 
91 
97  SVOutStream & operator<<(const char c);
98 
99 
101  SVOutStream & operator<<(std::ostream & (*fp)(std::ostream &));
102 
103 
105  template <typename T>
106  SVOutStream & operator<<(const T & value)
107  {
108  if (!newline_) (std::ostream &) * this << sep_;
109  else newline_ = false;
110  (std::ostream &) * this << value;
111  return *this;
112  }
113 
115  SVOutStream & write(const String & str); // write unmodified string
116 
117 
123  bool modifyStrings(bool modify);
124 
125 
127  template <typename NumericT>
128  SVOutStream & writeValueOrNan(NumericT thing)
129  {
130  if ((boost::math::isfinite)(thing)) return operator<<(thing);
131 
132  bool old = modifyStrings(false);
133  if ((boost::math::isnan)(thing)) operator<<(nan_);
134  else if (thing < 0) operator<<("-" + inf_);
135  else operator<<(inf_);
136  modifyStrings(old);
137  return *this;
138  }
139 
140 protected:
143 
146 
149 
152 
155 
158 
160  bool newline_;
161  };
162 
163 }
164 
165 #endif
A more convenient string class.
Definition: String.h:56
Definition: String.h:79
std::ostream & operator<<(std::ostream &os, const ItraqQuantifier::ItraqQuantifierStats &stats)
const double c
QuotingMethod
How to handle embedded quotes when quoting strings.
Definition: String.h:79
bool newline_
Are we at the beginning of a line? (Otherwise, insert separator before next item.) ...
Definition: SVOutStream.h:160
String nan_
String to use for NaN values.
Definition: SVOutStream.h:148
SVOutStream & operator<<(const T &value)
Generic stream output operator (for non-character-based types)
Definition: SVOutStream.h:106
String replacement_
Replacement for separator.
Definition: SVOutStream.h:145
String inf_
String to use for Inf values.
Definition: SVOutStream.h:151
SVOutStream & writeValueOrNan(NumericT thing)
Write a numeric value or &quot;nan&quot;/&quot;inf&quot;/&quot;-inf&quot;, if applicable (would not be needed for Linux) ...
Definition: SVOutStream.h:128
String sep_
Separator string.
Definition: SVOutStream.h:142
Stream class for writing to comma/tab/...-separated values files.
Definition: SVOutStream.h:51
String::QuotingMethod quoting_
String quoting method.
Definition: SVOutStream.h:154
bool modify_strings_
On/off switch for modification of strings.
Definition: SVOutStream.h:157

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:21 using doxygen 1.8.5