File indexing completed on 2025-01-18 09:39:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_IF_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_FORMATTERS_IF_HPP_INCLUDED_
0017
0018 #include <boost/mpl/bool.hpp>
0019 #include <boost/phoenix/core/actor.hpp>
0020 #include <boost/phoenix/core/meta_grammar.hpp>
0021 #include <boost/phoenix/core/terminal_fwd.hpp>
0022 #include <boost/phoenix/core/is_nullary.hpp>
0023 #include <boost/phoenix/core/environment.hpp>
0024 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
0025 #include <boost/type_traits/remove_cv.hpp>
0026 #include <boost/type_traits/remove_reference.hpp>
0027 #include <boost/log/detail/config.hpp>
0028 #include <boost/log/detail/custom_terminal_spec.hpp>
0029 #include <boost/log/detail/header.hpp>
0030
0031 #ifdef BOOST_HAS_PRAGMA_ONCE
0032 #pragma once
0033 #endif
0034
0035 namespace boost {
0036
0037 BOOST_LOG_OPEN_NAMESPACE
0038
0039 namespace expressions {
0040
0041 namespace aux {
0042
0043 template< typename LeftT, typename CondT, typename ThenT >
0044 class if_output_terminal
0045 {
0046 private:
0047
0048 typedef if_output_terminal this_type;
0049
0050 public:
0051 #ifndef BOOST_LOG_DOXYGEN_PASS
0052
0053 typedef void _is_boost_log_terminal;
0054 #endif
0055
0056
0057 template< typename >
0058 struct result;
0059
0060 template< typename ThisT, typename ContextT >
0061 struct result< ThisT(ContextT) >
0062 {
0063 typedef typename remove_cv< typename remove_reference< ContextT >::type >::type context_type;
0064 typedef typename phoenix::evaluator::impl<
0065 typename LeftT::proto_base_expr&,
0066 context_type,
0067 phoenix::unused
0068 >::result_type type;
0069 };
0070
0071 private:
0072
0073 LeftT m_left;
0074
0075 CondT m_cond;
0076
0077 ThenT m_then;
0078
0079 public:
0080
0081 if_output_terminal(LeftT const& left, CondT const& cond, ThenT const& then_) : m_left(left), m_cond(cond), m_then(then_)
0082 {
0083 }
0084
0085
0086 template< typename ContextT >
0087 typename result< this_type(ContextT const&) >::type operator() (ContextT const& ctx)
0088 {
0089 typedef typename result< this_type(ContextT const&) >::type result_type;
0090 result_type strm = phoenix::eval(m_left, ctx);
0091 if (phoenix::eval(m_cond, ctx))
0092 phoenix::eval(m_then, ctx);
0093 return strm;
0094 }
0095
0096
0097 template< typename ContextT >
0098 typename result< const this_type(ContextT const&) >::type operator() (ContextT const& ctx) const
0099 {
0100 typedef typename result< const this_type(ContextT const&) >::type result_type;
0101 result_type strm = phoenix::eval(m_left, ctx);
0102 if (phoenix::eval(m_cond, ctx))
0103 phoenix::eval(m_then, ctx);
0104 return strm;
0105 }
0106
0107 BOOST_DELETED_FUNCTION(if_output_terminal())
0108 };
0109
0110 template< typename LeftT, typename CondT, typename ThenT, typename ElseT >
0111 class if_else_output_terminal
0112 {
0113 private:
0114
0115 typedef if_else_output_terminal this_type;
0116
0117 public:
0118 #ifndef BOOST_LOG_DOXYGEN_PASS
0119
0120 typedef void _is_boost_log_terminal;
0121 #endif
0122
0123
0124 template< typename >
0125 struct result;
0126
0127 template< typename ThisT, typename ContextT >
0128 struct result< ThisT(ContextT) >
0129 {
0130 typedef typename remove_cv< typename remove_reference< ContextT >::type >::type context_type;
0131 typedef typename phoenix::evaluator::impl<
0132 typename LeftT::proto_base_expr&,
0133 context_type,
0134 phoenix::unused
0135 >::result_type type;
0136 };
0137
0138 private:
0139
0140 LeftT m_left;
0141
0142 CondT m_cond;
0143
0144 ThenT m_then;
0145
0146 ElseT m_else;
0147
0148 public:
0149
0150 if_else_output_terminal(LeftT const& left, CondT const& cond, ThenT const& then_, ElseT const& else_) : m_left(left), m_cond(cond), m_then(then_), m_else(else_)
0151 {
0152 }
0153
0154
0155 template< typename ContextT >
0156 typename result< this_type(ContextT const&) >::type operator() (ContextT const& ctx)
0157 {
0158 typedef typename result< this_type(ContextT const&) >::type result_type;
0159 result_type strm = phoenix::eval(m_left, ctx);
0160 if (phoenix::eval(m_cond, ctx))
0161 phoenix::eval(m_then, ctx);
0162 else
0163 phoenix::eval(m_else, ctx);
0164 return strm;
0165 }
0166
0167
0168 template< typename ContextT >
0169 typename result< const this_type(ContextT const&) >::type operator() (ContextT const& ctx) const
0170 {
0171 typedef typename result< const this_type(ContextT const&) >::type result_type;
0172 result_type strm = phoenix::eval(m_left, ctx);
0173 if (phoenix::eval(m_cond, ctx))
0174 phoenix::eval(m_then, ctx);
0175 else
0176 phoenix::eval(m_else, ctx);
0177 return strm;
0178 }
0179
0180 BOOST_DELETED_FUNCTION(if_else_output_terminal())
0181 };
0182
0183
0184 template< typename CondT, typename ThenT, typename ElseT >
0185 struct if_then_else_gen
0186 {
0187 CondT m_cond;
0188 ThenT m_then;
0189 ElseT m_else;
0190
0191 if_then_else_gen(CondT const& cond, ThenT const& then_, ElseT const& else_) : m_cond(cond), m_then(then_), m_else(else_)
0192 {
0193 }
0194 };
0195
0196 #ifndef BOOST_LOG_DOXYGEN_PASS
0197
0198 #define BOOST_LOG_AUX_OVERLOAD(left_ref, right_ref)\
0199 template< typename LeftExprT, typename CondT, typename ThenT, typename ElseT >\
0200 BOOST_FORCEINLINE phoenix::actor< if_else_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT, ElseT > >\
0201 operator<< (phoenix::actor< LeftExprT > left_ref left, if_then_else_gen< CondT, ThenT, ElseT > right_ref right)\
0202 {\
0203 typedef if_else_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT, ElseT > terminal_type;\
0204 phoenix::actor< terminal_type > actor = {{ terminal_type(left, right.m_cond, right.m_then, right.m_else) }};\
0205 return actor;\
0206 }
0207
0208 #include <boost/log/detail/generate_overloads.hpp>
0209
0210 #undef BOOST_LOG_AUX_OVERLOAD
0211
0212 #endif
0213
0214 template< typename CondT, typename ThenT >
0215 struct if_then_gen
0216 {
0217 struct else_gen
0218 {
0219 CondT m_cond;
0220 ThenT m_then;
0221
0222 else_gen(CondT const& cond, ThenT const& then_) : m_cond(cond), m_then(then_)
0223 {
0224 }
0225
0226 template< typename ElseT >
0227 BOOST_FORCEINLINE if_then_else_gen< CondT, ThenT, ElseT > operator[] (ElseT const& el)
0228 {
0229 return if_then_else_gen< CondT, ThenT, ElseT >(m_cond, m_then, el);
0230 }
0231 }
0232 else_;
0233
0234 if_then_gen(CondT const& cond, ThenT const& then_) : else_(cond, then_) {}
0235 };
0236
0237 #ifndef BOOST_LOG_DOXYGEN_PASS
0238
0239 #define BOOST_LOG_AUX_OVERLOAD(left_ref, right_ref)\
0240 template< typename LeftExprT, typename CondT, typename ThenT >\
0241 BOOST_FORCEINLINE phoenix::actor< if_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT > >\
0242 operator<< (phoenix::actor< LeftExprT > left_ref left, if_then_gen< CondT, ThenT > right_ref right)\
0243 {\
0244 typedef if_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT > terminal_type;\
0245 phoenix::actor< terminal_type > actor = {{ terminal_type(left, right.else_.m_cond, right.else_.m_then) }};\
0246 return actor;\
0247 }
0248
0249 #include <boost/log/detail/generate_overloads.hpp>
0250
0251 #undef BOOST_LOG_AUX_OVERLOAD
0252
0253 #endif
0254
0255 template< typename CondT >
0256 class if_gen
0257 {
0258 private:
0259 CondT const& m_cond;
0260
0261 public:
0262 explicit if_gen(CondT const& cond) : m_cond(cond)
0263 {
0264 }
0265
0266 template< typename ThenT >
0267 BOOST_FORCEINLINE if_then_gen< CondT, ThenT > operator[] (ThenT const& then_) const
0268 {
0269 return if_then_gen< CondT, ThenT >(m_cond, then_);
0270 }
0271 };
0272
0273 }
0274
0275
0276
0277
0278
0279
0280
0281 template< typename CondT >
0282 BOOST_FORCEINLINE aux::if_gen< CondT > if_(CondT const& cond)
0283 {
0284 return aux::if_gen< CondT >(cond);
0285 }
0286
0287 }
0288
0289 BOOST_LOG_CLOSE_NAMESPACE
0290
0291 #ifndef BOOST_LOG_DOXYGEN_PASS
0292
0293 namespace phoenix {
0294
0295 namespace result_of {
0296
0297 template< typename LeftT, typename CondT, typename ThenT >
0298 struct is_nullary< custom_terminal< boost::log::expressions::aux::if_output_terminal< LeftT, CondT, ThenT > > > :
0299 public mpl::false_
0300 {
0301 };
0302
0303 template< typename LeftT, typename CondT, typename ThenT, typename ElseT >
0304 struct is_nullary< custom_terminal< boost::log::expressions::aux::if_else_output_terminal< LeftT, CondT, ThenT, ElseT > > > :
0305 public mpl::false_
0306 {
0307 };
0308
0309 }
0310
0311 }
0312
0313 #endif
0314
0315 }
0316
0317 #include <boost/log/detail/footer.hpp>
0318
0319 #endif