annotate DEPENDENCIES/generic/include/boost/log/expressions/formatters/if.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /*
Chris@101 2 * Copyright Andrey Semashev 2007 - 2015.
Chris@16 3 * Distributed under the Boost Software License, Version 1.0.
Chris@16 4 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 */
Chris@16 7 /*!
Chris@16 8 * \file formatters/if.hpp
Chris@16 9 * \author Andrey Semashev
Chris@16 10 * \date 17.11.2012
Chris@16 11 *
Chris@16 12 * The header contains implementation of a conditional formatter.
Chris@16 13 */
Chris@16 14
Chris@16 15 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_IF_HPP_INCLUDED_
Chris@16 16 #define BOOST_LOG_EXPRESSIONS_FORMATTERS_IF_HPP_INCLUDED_
Chris@16 17
Chris@16 18 #include <boost/mpl/bool.hpp>
Chris@16 19 #include <boost/phoenix/core/actor.hpp>
Chris@16 20 #include <boost/phoenix/core/meta_grammar.hpp>
Chris@16 21 #include <boost/phoenix/core/terminal_fwd.hpp>
Chris@16 22 #include <boost/phoenix/core/is_nullary.hpp>
Chris@16 23 #include <boost/phoenix/core/environment.hpp>
Chris@16 24 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
Chris@16 25 #include <boost/type_traits/remove_cv.hpp>
Chris@16 26 #include <boost/type_traits/remove_reference.hpp>
Chris@16 27 #include <boost/log/detail/config.hpp>
Chris@16 28 #include <boost/log/detail/custom_terminal_spec.hpp>
Chris@16 29 #include <boost/log/detail/header.hpp>
Chris@16 30
Chris@16 31 #ifdef BOOST_HAS_PRAGMA_ONCE
Chris@16 32 #pragma once
Chris@16 33 #endif
Chris@16 34
Chris@16 35 namespace boost {
Chris@16 36
Chris@16 37 BOOST_LOG_OPEN_NAMESPACE
Chris@16 38
Chris@16 39 namespace expressions {
Chris@16 40
Chris@16 41 namespace aux {
Chris@16 42
Chris@16 43 template< typename LeftT, typename CondT, typename ThenT >
Chris@16 44 class if_output_terminal
Chris@16 45 {
Chris@16 46 private:
Chris@16 47 //! Self type
Chris@16 48 typedef if_output_terminal this_type;
Chris@16 49
Chris@16 50 public:
Chris@16 51 //! Internal typedef for type categorization
Chris@16 52 typedef void _is_boost_log_terminal;
Chris@16 53
Chris@16 54 //! Result type definition
Chris@16 55 template< typename >
Chris@16 56 struct result;
Chris@16 57
Chris@101 58 template< typename ThisT, typename ContextT >
Chris@101 59 struct result< ThisT(ContextT) >
Chris@16 60 {
Chris@16 61 typedef typename remove_cv< typename remove_reference< ContextT >::type >::type context_type;
Chris@16 62 typedef typename phoenix::evaluator::impl<
Chris@16 63 typename LeftT::proto_base_expr&,
Chris@16 64 context_type,
Chris@16 65 phoenix::unused
Chris@16 66 >::result_type type;
Chris@16 67 };
Chris@16 68
Chris@16 69 private:
Chris@16 70 //! Left argument actor
Chris@16 71 LeftT m_left;
Chris@16 72 //! Condition expression
Chris@16 73 CondT m_cond;
Chris@16 74 //! Positive branch
Chris@16 75 ThenT m_then;
Chris@16 76
Chris@16 77 public:
Chris@16 78 //! Initializing constructor
Chris@16 79 if_output_terminal(LeftT const& left, CondT const& cond, ThenT const& then_) : m_left(left), m_cond(cond), m_then(then_)
Chris@16 80 {
Chris@16 81 }
Chris@16 82
Chris@16 83 //! Invokation operator
Chris@16 84 template< typename ContextT >
Chris@16 85 typename result< this_type(ContextT const&) >::type operator() (ContextT const& ctx)
Chris@16 86 {
Chris@16 87 typedef typename result< this_type(ContextT const&) >::type result_type;
Chris@16 88 result_type strm = phoenix::eval(m_left, ctx);
Chris@16 89 if (phoenix::eval(m_cond, ctx))
Chris@16 90 phoenix::eval(m_then, ctx);
Chris@16 91 return strm;
Chris@16 92 }
Chris@16 93
Chris@16 94 //! Invokation operator
Chris@16 95 template< typename ContextT >
Chris@16 96 typename result< const this_type(ContextT const&) >::type operator() (ContextT const& ctx) const
Chris@16 97 {
Chris@16 98 typedef typename result< const this_type(ContextT const&) >::type result_type;
Chris@16 99 result_type strm = phoenix::eval(m_left, ctx);
Chris@16 100 if (phoenix::eval(m_cond, ctx))
Chris@16 101 phoenix::eval(m_then, ctx);
Chris@16 102 return strm;
Chris@16 103 }
Chris@16 104
Chris@16 105 BOOST_DELETED_FUNCTION(if_output_terminal())
Chris@16 106 };
Chris@16 107
Chris@16 108 template< typename LeftT, typename CondT, typename ThenT, typename ElseT >
Chris@16 109 class if_else_output_terminal
Chris@16 110 {
Chris@16 111 private:
Chris@16 112 //! Self type
Chris@16 113 typedef if_else_output_terminal this_type;
Chris@16 114
Chris@16 115 public:
Chris@16 116 //! Internal typedef for type categorization
Chris@16 117 typedef void _is_boost_log_terminal;
Chris@16 118
Chris@16 119 //! Result type definition
Chris@16 120 template< typename >
Chris@16 121 struct result;
Chris@16 122
Chris@101 123 template< typename ThisT, typename ContextT >
Chris@101 124 struct result< ThisT(ContextT) >
Chris@16 125 {
Chris@16 126 typedef typename remove_cv< typename remove_reference< ContextT >::type >::type context_type;
Chris@16 127 typedef typename phoenix::evaluator::impl<
Chris@16 128 typename LeftT::proto_base_expr&,
Chris@16 129 context_type,
Chris@16 130 phoenix::unused
Chris@16 131 >::result_type type;
Chris@16 132 };
Chris@16 133
Chris@16 134 private:
Chris@16 135 //! Left argument actor
Chris@16 136 LeftT m_left;
Chris@16 137 //! Condition expression
Chris@16 138 CondT m_cond;
Chris@16 139 //! Positive branch
Chris@16 140 ThenT m_then;
Chris@16 141 //! Negative branch
Chris@16 142 ElseT m_else;
Chris@16 143
Chris@16 144 public:
Chris@16 145 //! Initializing constructor
Chris@16 146 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_)
Chris@16 147 {
Chris@16 148 }
Chris@16 149
Chris@16 150 //! Invokation operator
Chris@16 151 template< typename ContextT >
Chris@16 152 typename result< this_type(ContextT const&) >::type operator() (ContextT const& ctx)
Chris@16 153 {
Chris@16 154 typedef typename result< this_type(ContextT const&) >::type result_type;
Chris@16 155 result_type strm = phoenix::eval(m_left, ctx);
Chris@16 156 if (phoenix::eval(m_cond, ctx))
Chris@16 157 phoenix::eval(m_then, ctx);
Chris@16 158 else
Chris@16 159 phoenix::eval(m_else, ctx);
Chris@16 160 return strm;
Chris@16 161 }
Chris@16 162
Chris@16 163 //! Invokation operator
Chris@16 164 template< typename ContextT >
Chris@16 165 typename result< const this_type(ContextT const&) >::type operator() (ContextT const& ctx) const
Chris@16 166 {
Chris@16 167 typedef typename result< const this_type(ContextT const&) >::type result_type;
Chris@16 168 result_type strm = phoenix::eval(m_left, ctx);
Chris@16 169 if (phoenix::eval(m_cond, ctx))
Chris@16 170 phoenix::eval(m_then, ctx);
Chris@16 171 else
Chris@16 172 phoenix::eval(m_else, ctx);
Chris@16 173 return strm;
Chris@16 174 }
Chris@16 175
Chris@16 176 BOOST_DELETED_FUNCTION(if_else_output_terminal())
Chris@16 177 };
Chris@16 178
Chris@16 179
Chris@16 180 template< typename CondT, typename ThenT, typename ElseT >
Chris@16 181 struct if_then_else_gen
Chris@16 182 {
Chris@16 183 CondT m_cond;
Chris@16 184 ThenT m_then;
Chris@16 185 ElseT m_else;
Chris@16 186
Chris@16 187 if_then_else_gen(CondT const& cond, ThenT const& then_, ElseT const& else_) : m_cond(cond), m_then(then_), m_else(else_)
Chris@16 188 {
Chris@16 189 }
Chris@16 190 };
Chris@16 191
Chris@16 192 #ifndef BOOST_LOG_DOXYGEN_PASS
Chris@16 193
Chris@16 194 #define BOOST_LOG_AUX_OVERLOAD(left_ref, right_ref)\
Chris@16 195 template< typename LeftExprT, typename CondT, typename ThenT, typename ElseT >\
Chris@16 196 BOOST_FORCEINLINE phoenix::actor< if_else_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT, ElseT > >\
Chris@16 197 operator<< (phoenix::actor< LeftExprT > left_ref left, if_then_else_gen< CondT, ThenT, ElseT > right_ref right)\
Chris@16 198 {\
Chris@16 199 typedef if_else_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT, ElseT > terminal_type;\
Chris@16 200 phoenix::actor< terminal_type > actor = {{ terminal_type(left, right.m_cond, right.m_then, right.m_else) }};\
Chris@16 201 return actor;\
Chris@16 202 }
Chris@16 203
Chris@16 204 #include <boost/log/detail/generate_overloads.hpp>
Chris@16 205
Chris@16 206 #undef BOOST_LOG_AUX_OVERLOAD
Chris@16 207
Chris@16 208 #endif // BOOST_LOG_DOXYGEN_PASS
Chris@16 209
Chris@16 210 template< typename CondT, typename ThenT >
Chris@16 211 struct if_then_gen
Chris@16 212 {
Chris@16 213 struct else_gen
Chris@16 214 {
Chris@16 215 CondT m_cond;
Chris@16 216 ThenT m_then;
Chris@16 217
Chris@16 218 else_gen(CondT const& cond, ThenT const& then_) : m_cond(cond), m_then(then_)
Chris@16 219 {
Chris@16 220 }
Chris@16 221
Chris@16 222 template< typename ElseT >
Chris@16 223 BOOST_FORCEINLINE if_then_else_gen< CondT, ThenT, ElseT > operator[] (ElseT const& el)
Chris@16 224 {
Chris@16 225 return if_then_else_gen< CondT, ThenT, ElseT >(m_cond, m_then, el);
Chris@16 226 }
Chris@16 227 }
Chris@16 228 else_;
Chris@16 229
Chris@16 230 if_then_gen(CondT const& cond, ThenT const& then_) : else_(cond, then_) {}
Chris@16 231 };
Chris@16 232
Chris@16 233 #ifndef BOOST_LOG_DOXYGEN_PASS
Chris@16 234
Chris@16 235 #define BOOST_LOG_AUX_OVERLOAD(left_ref, right_ref)\
Chris@16 236 template< typename LeftExprT, typename CondT, typename ThenT >\
Chris@16 237 BOOST_FORCEINLINE phoenix::actor< if_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT > >\
Chris@16 238 operator<< (phoenix::actor< LeftExprT > left_ref left, if_then_gen< CondT, ThenT > right_ref right)\
Chris@16 239 {\
Chris@16 240 typedef if_output_terminal< phoenix::actor< LeftExprT >, CondT, ThenT > terminal_type;\
Chris@16 241 phoenix::actor< terminal_type > actor = {{ terminal_type(left, right.else_.m_cond, right.else_.m_then) }};\
Chris@16 242 return actor;\
Chris@16 243 }
Chris@16 244
Chris@16 245 #include <boost/log/detail/generate_overloads.hpp>
Chris@16 246
Chris@16 247 #undef BOOST_LOG_AUX_OVERLOAD
Chris@16 248
Chris@16 249 #endif // BOOST_LOG_DOXYGEN_PASS
Chris@16 250
Chris@16 251 template< typename CondT >
Chris@16 252 class if_gen
Chris@16 253 {
Chris@16 254 private:
Chris@16 255 CondT const& m_cond;
Chris@16 256
Chris@16 257 public:
Chris@16 258 explicit if_gen(CondT const& cond) : m_cond(cond)
Chris@16 259 {
Chris@16 260 }
Chris@16 261
Chris@16 262 template< typename ThenT >
Chris@16 263 BOOST_FORCEINLINE if_then_gen< CondT, ThenT > operator[] (ThenT const& then_) const
Chris@16 264 {
Chris@16 265 return if_then_gen< CondT, ThenT >(m_cond, then_);
Chris@16 266 }
Chris@16 267 };
Chris@16 268
Chris@16 269 } // namespace aux
Chris@16 270
Chris@16 271 /*!
Chris@16 272 * The function returns a conditional formatter generator object. The generator provides <tt>operator[]</tt> that can be used
Chris@16 273 * to construct the actual formatter. The formatter must participate in a streaming expression.
Chris@16 274 *
Chris@16 275 * \param cond A filter expression that will be used as the condition
Chris@16 276 */
Chris@16 277 template< typename CondT >
Chris@16 278 BOOST_FORCEINLINE aux::if_gen< CondT > if_(CondT const& cond)
Chris@16 279 {
Chris@16 280 return aux::if_gen< CondT >(cond);
Chris@16 281 }
Chris@16 282
Chris@16 283 } // namespace expressions
Chris@16 284
Chris@16 285 BOOST_LOG_CLOSE_NAMESPACE // namespace log
Chris@16 286
Chris@16 287 #ifndef BOOST_LOG_DOXYGEN_PASS
Chris@16 288
Chris@16 289 namespace phoenix {
Chris@16 290
Chris@16 291 namespace result_of {
Chris@16 292
Chris@16 293 template< typename LeftT, typename CondT, typename ThenT >
Chris@16 294 struct is_nullary< custom_terminal< boost::log::expressions::aux::if_output_terminal< LeftT, CondT, ThenT > > > :
Chris@16 295 public mpl::false_
Chris@16 296 {
Chris@16 297 };
Chris@16 298
Chris@16 299 template< typename LeftT, typename CondT, typename ThenT, typename ElseT >
Chris@16 300 struct is_nullary< custom_terminal< boost::log::expressions::aux::if_else_output_terminal< LeftT, CondT, ThenT, ElseT > > > :
Chris@16 301 public mpl::false_
Chris@16 302 {
Chris@16 303 };
Chris@16 304
Chris@16 305 } // namespace result_of
Chris@16 306
Chris@16 307 } // namespace phoenix
Chris@16 308
Chris@16 309 #endif
Chris@16 310
Chris@16 311 } // namespace boost
Chris@16 312
Chris@16 313 #include <boost/log/detail/footer.hpp>
Chris@16 314
Chris@16 315 #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_IF_HPP_INCLUDED_