mlpack  master
prefixedoutstream.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
14 #define MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
15 
16 #include <iostream>
17 #include <iomanip>
18 #include <string>
19 #include <streambuf>
20 #include <stdexcept>
21 
23 
24 namespace mlpack {
25 namespace util {
26 
53 {
54  public:
65  const char* prefix,
66  bool ignoreInput = false,
67  bool fatal = false) :
68  destination(destination),
70  prefix(prefix),
71  // We want the first call to operator<< to prefix the prefix so we set
72  // carriageReturned to true.
73  carriageReturned(true),
74  fatal(fatal)
75  { /* nothing to do */ }
76 
78  PrefixedOutStream& operator<<(bool val);
80  PrefixedOutStream& operator<<(short val);
82  PrefixedOutStream& operator<<(unsigned short val);
84  PrefixedOutStream& operator<<(int val);
86  PrefixedOutStream& operator<<(unsigned int val);
88  PrefixedOutStream& operator<<(long val);
90  PrefixedOutStream& operator<<(unsigned long val);
92  PrefixedOutStream& operator<<(float val);
94  PrefixedOutStream& operator<<(double val);
96  PrefixedOutStream& operator<<(long double val);
98  PrefixedOutStream& operator<<(void* val);
100  PrefixedOutStream& operator<<(const char* str);
104  PrefixedOutStream& operator<<(std::streambuf* sb);
106  PrefixedOutStream& operator<<(std::ostream& (*pf)(std::ostream&));
108  PrefixedOutStream& operator<<(std::ios& (*pf)(std::ios&));
110  PrefixedOutStream& operator<<(std::ios_base& (*pf)(std::ios_base&));
111 
113  template<typename T>
114  PrefixedOutStream& operator<<(const T& s);
115 
117  std::ostream& destination;
118 
121 
122  private:
130  template<typename T>
131  void BaseLogic(const T& val);
132 
136  inline void PrefixIfNeeded();
137 
140 
144 
147  bool fatal;
148 };
149 
150 } // namespace util
151 } // namespace mlpack
152 
153 // Template definitions.
154 #include "prefixedoutstream_impl.hpp"
155 
156 #endif
std::ostream & destination
The output stream that all data is to be sent to; example: std::cout.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
PrefixedOutStream & operator<<(bool val)
Write a bool to the stream.
bool fatal
If true, a std::runtime_error exception will be thrown when a CR is encountered.
std::string prefix
Contains the prefix we must prepend to each line.
PrefixedOutStream(std::ostream &destination, const char *prefix, bool ignoreInput=false, bool fatal=false)
Set up the PrefixedOutStream.
bool ignoreInput
Discards input, prints nothing if true.
bool carriageReturned
If true, the previous call to operator<< encountered a CR, and a prefix will be necessary.
void BaseLogic(const T &val)
Conducts the base logic required in all the operator << overloads.
void PrefixIfNeeded()
Output the prefix, but only if we need to and if we are allowed to.
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
Definition: CMakeLists.txt:18
Allows us to output to an ostream with a prefix at the beginning of each line, in the same way we wou...