MLPACK  1.0.10
prefixedoutstream.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
24 #define __MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
25 
26 #include <iostream>
27 #include <iomanip>
28 #include <string>
29 #include <streambuf>
30 
31 #include <boost/lexical_cast.hpp>
32 #include <boost/utility/enable_if.hpp>
33 #include <boost/type_traits.hpp>
34 
37 
38 namespace mlpack {
39 namespace util {
40 
67 {
68  public:
76  const char* prefix,
77  bool ignoreInput = false,
78  bool fatal = false) :
79  destination(destination),
81  prefix(prefix),
82  // We want the first call to operator<< to prefix the prefix so we set
83  // carriageReturned to true.
84  carriageReturned(true),
85  fatal(fatal)
86  { /* nothing to do */ }
87 
89  PrefixedOutStream& operator<<(bool val);
91  PrefixedOutStream& operator<<(short val);
93  PrefixedOutStream& operator<<(unsigned short val);
95  PrefixedOutStream& operator<<(int val);
97  PrefixedOutStream& operator<<(unsigned int val);
99  PrefixedOutStream& operator<<(long val);
101  PrefixedOutStream& operator<<(unsigned long val);
103  PrefixedOutStream& operator<<(float val);
105  PrefixedOutStream& operator<<(double val);
107  PrefixedOutStream& operator<<(long double val);
109  PrefixedOutStream& operator<<(void* val);
111  PrefixedOutStream& operator<<(const char* str);
113  PrefixedOutStream& operator<<(std::string& str);
115  PrefixedOutStream& operator<<(std::streambuf* sb);
117  PrefixedOutStream& operator<<(std::ostream& (*pf)(std::ostream&));
119  PrefixedOutStream& operator<<(std::ios& (*pf)(std::ios&));
121  PrefixedOutStream& operator<<(std::ios_base& (*pf)(std::ios_base&));
122 
124  template<typename T>
125  PrefixedOutStream& operator<<(const T& s);
126 
128  std::ostream& destination;
129 
132 
133  private:
134  HAS_MEM_FUNC(ToString, HasToString)
135 
136 
137  template<typename T>
138  void CallBaseLogic(const T& s,
139  typename boost::disable_if<
140  boost::is_class<T>
141  >::type* = 0);
142 
144  template<typename T>
145  void CallBaseLogic(const T& s,
146  typename boost::enable_if<
147  boost::is_class<T>
148  >::type* = 0,
149  typename boost::disable_if<
150  HasToString<T, std::string(T::*)() const>
151  >::type* = 0);
152 
154  template<typename T>
155  void CallBaseLogic(const T& s,
156  typename boost::enable_if<
157  boost::is_class<T>
158  >::type* = 0,
159  typename boost::enable_if<
160  HasToString<T, std::string(T::*)() const>
161  >::type* = 0);
162 
170  template<typename T>
171  void BaseLogic(const T& val);
172 
176  inline void PrefixIfNeeded();
177 
179  std::string prefix;
180 
184 
187  bool fatal;
188 };
189 
190 }; // namespace util
191 }; // namespace mlpack
192 
193 // Template definitions.
194 #include "prefixedoutstream_impl.hpp"
195 
196 #endif