Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:47:40

0001 /*==============================================================================
0002     Copyright (c) 2001-2010 Joel de Guzman
0003     Copyright (c) 2010 Eric Niebler
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 ==============================================================================*/
0008 #ifndef BOOST_PHOENIX_STATEMENT_IF_HPP
0009 #define BOOST_PHOENIX_STATEMENT_IF_HPP
0010 
0011 #include <boost/phoenix/config.hpp>
0012 #include <boost/phoenix/core/limits.hpp>
0013 #include <boost/phoenix/core/actor.hpp>
0014 #include <boost/phoenix/core/call.hpp>
0015 #include <boost/phoenix/core/expression.hpp>
0016 #include <boost/phoenix/core/meta_grammar.hpp>
0017 #include <boost/phoenix/core/is_actor.hpp>
0018 
0019 #ifdef BOOST_MSVC
0020 #pragma warning(push)
0021 #pragma warning(disable: 4355) // 'this' used in base member initializer list
0022 #endif
0023 
0024 namespace boost { namespace phoenix
0025 {
0026     template <typename> struct if_actor;
0027 }}
0028     
0029 BOOST_PHOENIX_DEFINE_EXPRESSION_EXT(
0030     if_actor
0031   , (boost)(phoenix)(if_)
0032   , (meta_grammar) // Cond
0033     (meta_grammar) // Then
0034 )
0035     
0036 BOOST_PHOENIX_DEFINE_EXPRESSION(
0037     (boost)(phoenix)(if_else_statement)
0038   , (meta_grammar) // Cond
0039     (meta_grammar) // Then
0040     (meta_grammar) // Else
0041 )
0042 
0043 namespace boost { namespace phoenix
0044 {
0045     ////////////////////////////////////////////////////////////////////////////
0046     // If-Else statements
0047     ////////////////////////////////////////////////////////////////////////////
0048     
0049     // Function for evaluating lambdas like:
0050     // if_( foo )[ bar ]
0051     // and
0052     // if_( foo )[ bar ].else_[ baz ]
0053     struct if_else_eval
0054     {
0055         typedef void result_type;
0056         
0057         template<typename Cond, typename Then, typename Context>
0058         result_type
0059         operator()(Cond const & cond, Then const & then, Context const & ctx) const
0060         {
0061             if(boost::phoenix::eval(cond, ctx))
0062                 boost::phoenix::eval(then, ctx);
0063         }
0064         
0065         template<typename Cond, typename Then, typename Else, typename Context>
0066         result_type
0067         operator()(
0068               Cond const & cond
0069             , Then const & then
0070             , Else const & else_
0071             , Context const & ctx
0072         ) const
0073         {
0074             if(boost::phoenix::eval(cond, ctx))
0075                 boost::phoenix::eval(then, ctx);
0076             else
0077                 boost::phoenix::eval(else_, ctx);
0078         }
0079     };
0080     
0081     template <typename Dummy>
0082     struct default_actions::when<rule::if_, Dummy>
0083         : call<if_else_eval, Dummy>
0084     {};
0085     
0086     template <typename Dummy>
0087     struct default_actions::when<rule::if_else_statement, Dummy>
0088         : call<if_else_eval, Dummy>
0089     {};
0090 
0091 
0092     // Generator for .else_[ expr ] branch.
0093     template<typename Cond, typename Then>
0094     struct else_gen
0095     {
0096         else_gen(Cond const & cond_, Then const & then_)
0097             : cond(cond_)
0098             , then(then_) {}
0099 
0100         template<typename Else>
0101         typename expression::if_else_statement<Cond, Then, Else>::type const
0102         operator[](Else const & else_) const
0103         {
0104             return expression::if_else_statement<Cond, Then, Else>::make(cond, then, else_);
0105         }
0106 
0107         Cond cond;
0108         Then then;
0109     };
0110 
0111     // We subclass actor so we can provide the member else_ (which is an
0112     // else_gen responsible for the .else_[ expr ] branch).
0113     template<typename Expr>
0114     struct if_actor : actor<Expr>
0115     {
0116         typedef actor<Expr> base_type;
0117 
0118         if_actor(base_type const & base)
0119             : base_type(base)
0120             , else_(proto::child_c<0>(*this), proto::child_c<1>(*this))
0121         {}
0122 
0123         typedef typename proto::result_of::child_c<Expr, 0>::type cond_type;
0124         typedef typename proto::result_of::child_c<Expr, 1>::type then_type;
0125 
0126         else_gen<cond_type, then_type> else_;
0127     };
0128 
0129     template <typename Expr>
0130     struct is_actor<if_actor<Expr> >
0131         : mpl::true_
0132     {};
0133 
0134     // Generator for if( cond )[ then ] branch.
0135     template<typename Cond>
0136     struct if_gen
0137     {
0138         if_gen(Cond const & cond_)
0139             : cond(cond_) {}
0140 
0141         template<typename Then>
0142         typename expression::if_<Cond, Then>::type const
0143         operator[](Then const & then) const
0144         {
0145             return expression::if_<Cond, Then>::make(cond, then);
0146         }
0147 
0148         Cond cond;
0149     };
0150 
0151     template<typename Cond>
0152     inline
0153     if_gen<Cond> const
0154     if_(Cond const & cond)
0155     {
0156         return if_gen<Cond>(cond);
0157     }
0158  
0159 }}
0160 
0161 #ifdef BOOST_MSVC
0162 #pragma warning(pop)
0163 #endif
0164 
0165 #endif