File indexing completed on 2025-01-18 09:39:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTER_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_FORMATTER_HPP_INCLUDED_
0017
0018 #include <locale>
0019 #include <ostream>
0020 #include <boost/ref.hpp>
0021 #include <boost/move/core.hpp>
0022 #include <boost/move/utility_core.hpp>
0023 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0024 #include <boost/type_traits/is_same.hpp>
0025 #include <boost/type_traits/remove_cv.hpp>
0026 #include <boost/log/detail/sfinae_tools.hpp>
0027 #endif
0028 #include <boost/log/detail/config.hpp>
0029 #include <boost/log/detail/light_function.hpp>
0030 #include <boost/log/attributes/attribute_value_set.hpp>
0031 #include <boost/log/attributes/value_visitation.hpp>
0032 #include <boost/log/core/record_view.hpp>
0033 #include <boost/log/utility/formatting_ostream.hpp>
0034 #include <boost/log/utility/functional/bind_output.hpp>
0035 #include <boost/log/expressions/message.hpp>
0036 #include <boost/log/detail/header.hpp>
0037
0038 #ifdef BOOST_HAS_PRAGMA_ONCE
0039 #pragma once
0040 #endif
0041
0042 namespace boost {
0043
0044 BOOST_LOG_OPEN_NAMESPACE
0045
0046 namespace expressions {
0047
0048 namespace aux {
0049
0050
0051
0052
0053 template< typename StreamT >
0054 class stream_ref :
0055 public reference_wrapper< StreamT >
0056 {
0057 public:
0058 typedef typename StreamT::char_type char_type;
0059 typedef typename StreamT::traits_type traits_type;
0060 typedef typename StreamT::allocator_type allocator_type;
0061 typedef typename StreamT::streambuf_type streambuf_type;
0062 typedef typename StreamT::string_type string_type;
0063 typedef typename StreamT::ostream_type ostream_type;
0064 typedef typename StreamT::pos_type pos_type;
0065 typedef typename StreamT::off_type off_type;
0066 typedef typename StreamT::int_type int_type;
0067
0068 typedef typename StreamT::failure failure;
0069 typedef typename StreamT::fmtflags fmtflags;
0070 typedef typename StreamT::iostate iostate;
0071 typedef typename StreamT::openmode openmode;
0072 typedef typename StreamT::seekdir seekdir;
0073 typedef typename StreamT::Init Init;
0074
0075 typedef typename StreamT::event event;
0076 typedef typename StreamT::event_callback event_callback;
0077
0078 typedef typename StreamT::sentry sentry;
0079
0080 static BOOST_CONSTEXPR_OR_CONST fmtflags boolalpha = StreamT::boolalpha;
0081 static BOOST_CONSTEXPR_OR_CONST fmtflags dec = StreamT::dec;
0082 static BOOST_CONSTEXPR_OR_CONST fmtflags fixed = StreamT::fixed;
0083 static BOOST_CONSTEXPR_OR_CONST fmtflags hex = StreamT::hex;
0084 static BOOST_CONSTEXPR_OR_CONST fmtflags internal = StreamT::internal;
0085 static BOOST_CONSTEXPR_OR_CONST fmtflags left = StreamT::left;
0086 static BOOST_CONSTEXPR_OR_CONST fmtflags oct = StreamT::oct;
0087 static BOOST_CONSTEXPR_OR_CONST fmtflags right = StreamT::right;
0088 static BOOST_CONSTEXPR_OR_CONST fmtflags scientific = StreamT::scientific;
0089 static BOOST_CONSTEXPR_OR_CONST fmtflags showbase = StreamT::showbase;
0090 static BOOST_CONSTEXPR_OR_CONST fmtflags showpoint = StreamT::showpoint;
0091 static BOOST_CONSTEXPR_OR_CONST fmtflags skipws = StreamT::skipws;
0092 static BOOST_CONSTEXPR_OR_CONST fmtflags unitbuf = StreamT::unitbuf;
0093 static BOOST_CONSTEXPR_OR_CONST fmtflags uppercase = StreamT::uppercase;
0094 static BOOST_CONSTEXPR_OR_CONST fmtflags adjustfield = StreamT::adjustfield;
0095 static BOOST_CONSTEXPR_OR_CONST fmtflags basefield = StreamT::basefield;
0096 static BOOST_CONSTEXPR_OR_CONST fmtflags floatfield = StreamT::floatfield;
0097
0098 static BOOST_CONSTEXPR_OR_CONST iostate badbit = StreamT::badbit;
0099 static BOOST_CONSTEXPR_OR_CONST iostate eofbit = StreamT::eofbit;
0100 static BOOST_CONSTEXPR_OR_CONST iostate failbit = StreamT::failbit;
0101 static BOOST_CONSTEXPR_OR_CONST iostate goodbit = StreamT::goodbit;
0102
0103 static BOOST_CONSTEXPR_OR_CONST openmode app = StreamT::app;
0104 static BOOST_CONSTEXPR_OR_CONST openmode ate = StreamT::ate;
0105 static BOOST_CONSTEXPR_OR_CONST openmode binary = StreamT::binary;
0106 static BOOST_CONSTEXPR_OR_CONST openmode in = StreamT::in;
0107 static BOOST_CONSTEXPR_OR_CONST openmode out = StreamT::out;
0108 static BOOST_CONSTEXPR_OR_CONST openmode trunc = StreamT::trunc;
0109
0110 static BOOST_CONSTEXPR_OR_CONST seekdir beg = StreamT::beg;
0111 static BOOST_CONSTEXPR_OR_CONST seekdir cur = StreamT::cur;
0112 static BOOST_CONSTEXPR_OR_CONST seekdir end = StreamT::end;
0113
0114 static BOOST_CONSTEXPR_OR_CONST event erase_event = StreamT::erase_event;
0115 static BOOST_CONSTEXPR_OR_CONST event imbue_event = StreamT::imbue_event;
0116 static BOOST_CONSTEXPR_OR_CONST event copyfmt_event = StreamT::copyfmt_event;
0117
0118
0119 BOOST_FORCEINLINE explicit stream_ref(StreamT& strm) : reference_wrapper< StreamT >(strm)
0120 {
0121 }
0122
0123 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0124 template< typename T >
0125 BOOST_FORCEINLINE StreamT& operator<< (T&& val) const
0126 {
0127 StreamT& strm = this->get();
0128 strm << static_cast< T&& >(val);
0129 return strm;
0130 }
0131 #if defined(BOOST_MSVC) && BOOST_MSVC < 1800
0132
0133 template< typename T, unsigned int N >
0134 BOOST_FORCEINLINE StreamT& operator<< (T (&val)[N]) const
0135 {
0136 StreamT& strm = this->get();
0137 strm << val;
0138 return strm;
0139 }
0140 #endif
0141 #else
0142 template< typename T >
0143 BOOST_FORCEINLINE StreamT& operator<< (T& val) const
0144 {
0145 StreamT& strm = this->get();
0146 strm << val;
0147 return strm;
0148 }
0149
0150 template< typename T >
0151 BOOST_FORCEINLINE StreamT& operator<< (T const& val) const
0152 {
0153 StreamT& strm = this->get();
0154 strm << val;
0155 return strm;
0156 }
0157 #endif
0158
0159 BOOST_FORCEINLINE void attach(string_type& str) const { this->get().attach(str); }
0160 BOOST_FORCEINLINE void detach() const { this->get().detach(); }
0161 BOOST_FORCEINLINE string_type const& str() const { return this->get().str(); }
0162 BOOST_FORCEINLINE ostream_type& stream() const { return this->get().stream(); }
0163 BOOST_FORCEINLINE fmtflags flags() const { return this->get().flags(); }
0164 BOOST_FORCEINLINE fmtflags flags(fmtflags f) const { return this->get().flags(f); }
0165 BOOST_FORCEINLINE fmtflags setf(fmtflags f) const { return this->get().setf(f); }
0166 BOOST_FORCEINLINE fmtflags setf(fmtflags f, fmtflags mask) const { return this->get().setf(f, mask); }
0167 BOOST_FORCEINLINE void unsetf(fmtflags f) const { this->get().unsetf(f); }
0168
0169 BOOST_FORCEINLINE std::streamsize precision() const { return this->get().precision(); }
0170 BOOST_FORCEINLINE std::streamsize precision(std::streamsize p) const { return this->get().precision(p); }
0171
0172 BOOST_FORCEINLINE std::streamsize width() const { return this->get().width(); }
0173 BOOST_FORCEINLINE std::streamsize width(std::streamsize w) const { return this->get().width(w); }
0174
0175 BOOST_FORCEINLINE std::locale getloc() const { return this->get().getloc(); }
0176 BOOST_FORCEINLINE std::locale imbue(std::locale const& loc) const { return this->get().imbue(loc); }
0177
0178 static BOOST_FORCEINLINE int xalloc() { return StreamT::xalloc(); }
0179 BOOST_FORCEINLINE long& iword(int index) const { return this->get().iword(index); }
0180 BOOST_FORCEINLINE void*& pword(int index) const { return this->get().pword(index); }
0181
0182 BOOST_FORCEINLINE void register_callback(event_callback fn, int index) const { this->get().register_callback(fn, index); }
0183
0184 static BOOST_FORCEINLINE bool sync_with_stdio(bool sync = true) { return StreamT::sync_with_stdio(sync); }
0185
0186 BOOST_EXPLICIT_OPERATOR_BOOL()
0187 BOOST_FORCEINLINE bool operator! () const { return !this->get(); }
0188
0189 BOOST_FORCEINLINE iostate rdstate() const { return this->get().rdstate(); }
0190 BOOST_FORCEINLINE void clear(iostate state = goodbit) const { this->get().clear(state); }
0191 BOOST_FORCEINLINE void setstate(iostate state) const { this->get().setstate(state); }
0192 BOOST_FORCEINLINE bool good() const { return this->get().good(); }
0193 BOOST_FORCEINLINE bool eof() const { return this->get().eof(); }
0194 BOOST_FORCEINLINE bool fail() const { return this->get().fail(); }
0195 BOOST_FORCEINLINE bool bad() const { return this->get().bad(); }
0196
0197 BOOST_FORCEINLINE iostate exceptions() const { return this->get().exceptions(); }
0198 BOOST_FORCEINLINE void exceptions(iostate s) const { this->get().exceptions(s); }
0199
0200 BOOST_FORCEINLINE ostream_type* tie() const { return this->get().tie(); }
0201 BOOST_FORCEINLINE ostream_type* tie(ostream_type* strm) const { return this->get().tie(strm); }
0202
0203 BOOST_FORCEINLINE streambuf_type* rdbuf() const { return this->get().rdbuf(); }
0204
0205 BOOST_FORCEINLINE StreamT& copyfmt(std::basic_ios< char_type, traits_type >& rhs) const { return this->get().copyfmt(rhs); }
0206 BOOST_FORCEINLINE StreamT& copyfmt(StreamT& rhs) const { return this->get().copyfmt(rhs); }
0207
0208 BOOST_FORCEINLINE char_type fill() const { return this->get().fill(); }
0209 BOOST_FORCEINLINE char_type fill(char_type ch) const { return this->get().fill(ch); }
0210
0211 BOOST_FORCEINLINE char narrow(char_type ch, char def) const { return this->get().narrow(ch, def); }
0212 BOOST_FORCEINLINE char_type widen(char ch) const { return this->get().widen(ch); }
0213
0214 BOOST_FORCEINLINE StreamT& flush() const { return this->get().flush(); }
0215
0216 BOOST_FORCEINLINE pos_type tellp() const { return this->get().tellp(); }
0217 BOOST_FORCEINLINE StreamT& seekp(pos_type pos) const { return this->get().seekp(pos); }
0218 BOOST_FORCEINLINE StreamT& seekp(off_type off, std::ios_base::seekdir dir) const { return this->get().seekp(off, dir); }
0219
0220 template< typename CharT >
0221 BOOST_FORCEINLINE typename boost::log::aux::enable_if_streamable_char_type< CharT, StreamT& >::type
0222 put(CharT c) const { return this->get().put(c); }
0223
0224 template< typename CharT >
0225 BOOST_FORCEINLINE typename boost::log::aux::enable_if_streamable_char_type< CharT, StreamT& >::type
0226 write(const CharT* p, std::streamsize size) const { return this->get().write(p, size); }
0227 };
0228
0229 template< typename StreamT >
0230 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::boolalpha;
0231 template< typename StreamT >
0232 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::dec;
0233 template< typename StreamT >
0234 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::fixed;
0235 template< typename StreamT >
0236 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::hex;
0237 template< typename StreamT >
0238 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::internal;
0239 template< typename StreamT >
0240 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::left;
0241 template< typename StreamT >
0242 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::oct;
0243 template< typename StreamT >
0244 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::right;
0245 template< typename StreamT >
0246 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::scientific;
0247 template< typename StreamT >
0248 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::showbase;
0249 template< typename StreamT >
0250 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::showpoint;
0251 template< typename StreamT >
0252 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::skipws;
0253 template< typename StreamT >
0254 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::unitbuf;
0255 template< typename StreamT >
0256 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::uppercase;
0257 template< typename StreamT >
0258 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::adjustfield;
0259 template< typename StreamT >
0260 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::basefield;
0261 template< typename StreamT >
0262 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::fmtflags stream_ref< StreamT >::floatfield;
0263
0264 template< typename StreamT >
0265 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::iostate stream_ref< StreamT >::badbit;
0266 template< typename StreamT >
0267 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::iostate stream_ref< StreamT >::eofbit;
0268 template< typename StreamT >
0269 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::iostate stream_ref< StreamT >::failbit;
0270 template< typename StreamT >
0271 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::iostate stream_ref< StreamT >::goodbit;
0272
0273 template< typename StreamT >
0274 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::openmode stream_ref< StreamT >::app;
0275 template< typename StreamT >
0276 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::openmode stream_ref< StreamT >::ate;
0277 template< typename StreamT >
0278 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::openmode stream_ref< StreamT >::binary;
0279 template< typename StreamT >
0280 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::openmode stream_ref< StreamT >::in;
0281 template< typename StreamT >
0282 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::openmode stream_ref< StreamT >::out;
0283 template< typename StreamT >
0284 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::openmode stream_ref< StreamT >::trunc;
0285
0286 template< typename StreamT >
0287 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::seekdir stream_ref< StreamT >::beg;
0288 template< typename StreamT >
0289 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::seekdir stream_ref< StreamT >::cur;
0290 template< typename StreamT >
0291 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::seekdir stream_ref< StreamT >::end;
0292
0293 template< typename StreamT >
0294 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::event stream_ref< StreamT >::erase_event;
0295 template< typename StreamT >
0296 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::event stream_ref< StreamT >::imbue_event;
0297 template< typename StreamT >
0298 BOOST_CONSTEXPR_OR_CONST typename stream_ref< StreamT >::event stream_ref< StreamT >::copyfmt_event;
0299
0300
0301 struct message_formatter
0302 {
0303 typedef void result_type;
0304
0305 message_formatter() : m_MessageName(expressions::tag::message::get_name())
0306 {
0307 }
0308
0309 template< typename StreamT >
0310 BOOST_FORCEINLINE result_type operator() (record_view const& rec, StreamT& strm) const
0311 {
0312 boost::log::visit< expressions::tag::message::value_type >(m_MessageName, rec, boost::log::bind_output(strm));
0313 }
0314
0315 private:
0316 const attribute_name m_MessageName;
0317 };
0318
0319 }
0320
0321 }
0322
0323
0324
0325
0326 template< typename CharT >
0327 class basic_formatter
0328 {
0329 typedef basic_formatter this_type;
0330 BOOST_COPYABLE_AND_MOVABLE(this_type)
0331
0332 public:
0333
0334 typedef void result_type;
0335
0336
0337 typedef CharT char_type;
0338
0339 typedef basic_formatting_ostream< char_type > stream_type;
0340
0341 private:
0342
0343 typedef boost::log::aux::light_function< void (record_view const&, expressions::aux::stream_ref< stream_type >) > formatter_type;
0344
0345 private:
0346
0347 formatter_type m_Formatter;
0348
0349 public:
0350
0351
0352
0353 basic_formatter() : m_Formatter(expressions::aux::message_formatter())
0354 {
0355 }
0356
0357
0358
0359 basic_formatter(basic_formatter const& that) : m_Formatter(that.m_Formatter)
0360 {
0361 }
0362
0363
0364
0365 basic_formatter(BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT : m_Formatter(boost::move(that.m_Formatter))
0366 {
0367 }
0368
0369
0370
0371
0372 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0373 template< typename FunT >
0374 basic_formatter(FunT&& fun) : m_Formatter(boost::forward< FunT >(fun))
0375 {
0376 }
0377 #elif !defined(BOOST_MSVC) || BOOST_MSVC >= 1600
0378 template< typename FunT >
0379 basic_formatter(FunT const& fun, typename boost::disable_if_c< move_detail::is_rv< FunT >::value, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) : m_Formatter(fun)
0380 {
0381 }
0382 #else
0383
0384 template< typename FunT >
0385 basic_formatter(FunT const& fun) : m_Formatter(fun)
0386 {
0387 }
0388 template< typename FunT >
0389 basic_formatter(rv< FunT >& fun) : m_Formatter(fun)
0390 {
0391 }
0392 template< typename FunT >
0393 basic_formatter(rv< FunT > const& fun) : m_Formatter(static_cast< FunT const& >(fun))
0394 {
0395 }
0396 basic_formatter(rv< this_type > const& that) : m_Formatter(that.m_Formatter)
0397 {
0398 }
0399 #endif
0400
0401
0402
0403
0404 basic_formatter& operator= (BOOST_RV_REF(this_type) that) BOOST_NOEXCEPT
0405 {
0406 m_Formatter.swap(that.m_Formatter);
0407 return *this;
0408 }
0409
0410
0411
0412 basic_formatter& operator= (BOOST_COPY_ASSIGN_REF(this_type) that)
0413 {
0414 m_Formatter = that.m_Formatter;
0415 return *this;
0416 }
0417
0418
0419
0420 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0421 template< typename FunT >
0422 basic_formatter& operator= (FunT&& fun)
0423 {
0424 this_type(boost::forward< FunT >(fun)).swap(*this);
0425 return *this;
0426 }
0427 #else
0428 template< typename FunT >
0429 typename boost::disable_if_c< is_same< typename remove_cv< FunT >::type, this_type >::value, this_type& >::type
0430 operator= (FunT const& fun)
0431 {
0432 this_type(fun).swap(*this);
0433 return *this;
0434 }
0435 #endif
0436
0437
0438
0439
0440
0441
0442
0443 result_type operator() (record_view const& rec, stream_type& strm) const
0444 {
0445 m_Formatter(rec, expressions::aux::stream_ref< stream_type >(strm));
0446 }
0447
0448
0449
0450
0451 void reset()
0452 {
0453 m_Formatter = expressions::aux::message_formatter();
0454 }
0455
0456
0457
0458
0459 void swap(basic_formatter& that) BOOST_NOEXCEPT
0460 {
0461 m_Formatter.swap(that.m_Formatter);
0462 }
0463 };
0464
0465 template< typename CharT >
0466 inline void swap(basic_formatter< CharT >& left, basic_formatter< CharT >& right) BOOST_NOEXCEPT
0467 {
0468 left.swap(right);
0469 }
0470
0471 #ifdef BOOST_LOG_USE_CHAR
0472 typedef basic_formatter< char > formatter;
0473 #endif
0474 #ifdef BOOST_LOG_USE_WCHAR_T
0475 typedef basic_formatter< wchar_t > wformatter;
0476 #endif
0477
0478 BOOST_LOG_CLOSE_NAMESPACE
0479
0480 }
0481
0482 #include <boost/log/detail/footer.hpp>
0483
0484 #endif