prefixedoutstream.hpp
Go to the documentation of this file.00001
00023 #ifndef __MLPACK_CORE_IO_PREFIXEDOUTSTREAM_HPP
00024 #define __MLPACK_CORE_IO_PREFIXEDOUTSTREAM_HPP
00025
00026 #include <iostream>
00027 #include <iomanip>
00028 #include <string>
00029 #include <streambuf>
00030
00031 #include <boost/lexical_cast.hpp>
00032 #include <boost/utility/enable_if.hpp>
00033 #include <boost/type_traits.hpp>
00034
00035 #include <mlpack/core/util/sfinae_utility.hpp>
00036 #include <mlpack/core/util/string_util.hpp>
00037
00038 namespace mlpack {
00039 namespace util {
00040
00066 class PrefixedOutStream
00067 {
00068 public:
00075 PrefixedOutStream(std::ostream& destination,
00076 const char* prefix,
00077 bool ignoreInput = false,
00078 bool fatal = false) :
00079 destination(destination),
00080 ignoreInput(ignoreInput),
00081 prefix(prefix),
00082
00083
00084 carriageReturned(true),
00085 fatal(fatal)
00086 { }
00087
00089 PrefixedOutStream& operator<<(bool val);
00091 PrefixedOutStream& operator<<(short val);
00093 PrefixedOutStream& operator<<(unsigned short val);
00095 PrefixedOutStream& operator<<(int val);
00097 PrefixedOutStream& operator<<(unsigned int val);
00099 PrefixedOutStream& operator<<(long val);
00101 PrefixedOutStream& operator<<(unsigned long val);
00103 PrefixedOutStream& operator<<(float val);
00105 PrefixedOutStream& operator<<(double val);
00107 PrefixedOutStream& operator<<(long double val);
00109 PrefixedOutStream& operator<<(void* val);
00111 PrefixedOutStream& operator<<(const char* str);
00113 PrefixedOutStream& operator<<(std::string& str);
00115 PrefixedOutStream& operator<<(std::streambuf* sb);
00117 PrefixedOutStream& operator<<(std::ostream& (*pf)(std::ostream&));
00119 PrefixedOutStream& operator<<(std::ios& (*pf)(std::ios&));
00121 PrefixedOutStream& operator<<(std::ios_base& (*pf)(std::ios_base&));
00122
00124 template<typename T>
00125 PrefixedOutStream& operator<<(const T& s);
00126
00128 std::ostream& destination;
00129
00131 bool ignoreInput;
00132
00133 private:
00134 HAS_MEM_FUNC(ToString, HasToString)
00135
00136
00137 template<typename T>
00138 void CallBaseLogic(const T& s,
00139 typename boost::disable_if<
00140 boost::is_class<T>
00141 >::type* = 0);
00142
00144 template<typename T>
00145 void CallBaseLogic(const T& s,
00146 typename boost::enable_if<
00147 boost::is_class<T>
00148 >::type* = 0,
00149 typename boost::disable_if<
00150 HasToString<T, std::string(T::*)() const>
00151 >::type* = 0);
00152
00154 template<typename T>
00155 void CallBaseLogic(const T& s,
00156 typename boost::enable_if<
00157 boost::is_class<T>
00158 >::type* = 0,
00159 typename boost::enable_if<
00160 HasToString<T, std::string(T::*)() const>
00161 >::type* = 0);
00162
00170 template<typename T>
00171 void BaseLogic(const T& val);
00172
00176 inline void PrefixIfNeeded();
00177
00179 std::string prefix;
00180
00183 bool carriageReturned;
00184
00187 bool fatal;
00188 };
00189
00190 };
00191 };
00192
00193
00194 #include "prefixedoutstream_impl.hpp"
00195
00196 #endif