PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/phoenix/bind/bind_member_variable.hpp

http://pythonocc.googlecode.com/
C++ Header | 105 lines | 87 code | 12 blank | 6 comment | 0 complexity | 829bbc0d2388381289c5611c1200b2fa MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2007 Joel de Guzman
  3
  4    Distributed under the Boost Software License, Version 1.0. (See accompanying
  5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6==============================================================================*/
  7#ifndef PHOENIX_BIND_BIND_MEMBER_VARIABLE_HPP
  8#define PHOENIX_BIND_BIND_MEMBER_VARIABLE_HPP
  9
 10#include <boost/mpl/if.hpp>
 11#include <boost/type_traits/is_const.hpp>
 12#include <boost/type_traits/remove_pointer.hpp>
 13#include <boost/type_traits/remove_reference.hpp>
 14
 15#include <boost/spirit/home/phoenix/core/actor.hpp>
 16#include <boost/spirit/home/phoenix/core/compose.hpp>
 17#include <boost/spirit/home/phoenix/core/reference.hpp>
 18#include <boost/spirit/home/phoenix/core/detail/function_eval.hpp>
 19#include <boost/mpl/if.hpp>
 20#include <boost/type_traits/is_const.hpp>
 21#include <boost/type_traits/remove_pointer.hpp>
 22#include <boost/type_traits/remove_reference.hpp>
 23
 24namespace boost { namespace phoenix
 25{
 26    namespace detail
 27    {
 28        template <typename RT, typename MP>
 29        struct member_variable
 30        {
 31            template <typename Class>
 32            struct result
 33            {
 34                typedef typename boost::mpl::if_<
 35                    boost::is_const<
 36                        typename boost::remove_pointer<
 37                            typename boost::remove_reference<Class>::type
 38                        >::type
 39                    >
 40                  , const RT&
 41                  , RT&
 42                >::type type;
 43            };
 44
 45            member_variable(MP mp)
 46                : mp(mp) {}
 47
 48            template <typename Class>
 49            RT& operator()(Class& obj) const
 50            {
 51                return obj.*mp;
 52            }
 53
 54            template <typename Class>
 55            RT& operator()(Class* obj) const
 56            {
 57                return obj->*mp;
 58            }
 59
 60            template <typename Class>
 61            RT const& operator()(Class const& obj) const
 62            {
 63                return obj.*mp;
 64            }
 65
 66            template <typename Class>
 67            RT const& operator()(Class const* obj) const
 68            {
 69                return obj->*mp;
 70            }
 71
 72            MP mp;
 73        };
 74    }
 75
 76    template <typename RT, typename ClassT, typename ClassA>
 77    inline actor<
 78        typename as_composite<
 79            detail::function_eval<1>
 80          , detail::member_variable<RT, RT ClassT::*>
 81          , ClassA
 82        >::type>
 83    bind(RT ClassT::*mp, ClassA const& obj)
 84    {
 85        typedef detail::member_variable<RT, RT ClassT::*> mp_type;
 86        return compose<detail::function_eval<1> >(mp_type(mp), obj);
 87    }
 88
 89    template <typename RT, typename ClassT>
 90    inline actor<
 91        typename as_composite<
 92            detail::function_eval<1>
 93          , detail::member_variable<RT, RT ClassT::*>
 94          , actor<reference<ClassT> >
 95        >::type>
 96    bind(RT ClassT::*mp, ClassT& obj)
 97    {
 98        typedef detail::member_variable<RT, RT ClassT::*> mp_type;
 99        return compose<detail::function_eval<1> >(
100            mp_type(mp)
101          , actor<reference<ClassT> >(reference<ClassT>(obj)));
102    }
103}}
104
105#endif