Fusion: fixed adapt_class to be usable with Spirit, added adapt_class_named

[SVN r59340]
This commit is contained in:
Hartmut Kaiser
2010-01-29 15:03:35 +00:00
parent 0d5ff2fc01
commit 6647f0c8a4
5 changed files with 210 additions and 31 deletions

View File

@ -1,5 +1,6 @@
/*=============================================================================
Copyright (c) 2001-2009 Joel de Guzman
Copyright (c) 2009-2010 Hartmut Kaiser
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -28,6 +29,10 @@
#include <boost/preprocessor/cat.hpp>
#include <boost/mpl/int.hpp>
#include <boost/config/no_tr1/utility.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#define BOOST_FUSION_ADAPT_CLASS(name, bseq) \
BOOST_FUSION_ADAPT_CLASS_I( \
@ -75,49 +80,53 @@
{ \
template <> \
struct class_size<name> : mpl::int_<BOOST_PP_SEQ_SIZE(seq)> {}; \
template <typename T, int N> struct class_member_proxy; \
BOOST_PP_SEQ_FOR_EACH_I(BOOST_FUSION_ADAPT_CLASS_C, name, seq) \
}}} \
/***/
#define BOOST_FUSION_ADAPT_CLASS_C(r, name, i, xy) \
#define BOOST_FUSION_ADAPT_CLASS_C(r, fullname, i, xy) \
template <> \
struct class_member<name, i> \
struct class_member_proxy<fullname, i> \
{ \
typedef BOOST_PP_TUPLE_ELEM(4, 0, xy) type; \
typedef BOOST_PP_TUPLE_ELEM(4, 1, xy) get_type; \
struct proxy \
typedef BOOST_PP_TUPLE_ELEM(4, 0, xy) lvalue; \
typedef BOOST_PP_TUPLE_ELEM(4, 1, xy) rvalue; \
typedef remove_const<remove_reference<lvalue>::type>::type type; \
typedef add_reference<add_const<type>::type>::type cref_type; \
\
class_member_proxy(fullname& obj) : obj(obj) {} \
fullname& obj; \
\
class_member_proxy& operator=(cref_type val) \
{ \
typedef BOOST_PP_TUPLE_ELEM(4, 0, xy) type; \
typedef BOOST_PP_TUPLE_ELEM(4, 1, xy) get_type; \
typedef \
add_reference<add_const<type>::type>::type \
cref_type; \
BOOST_PP_TUPLE_ELEM(4, 3, xy); \
return *this; \
} \
\
proxy(name& obj) : obj(obj) {} \
name& obj; \
\
proxy& operator=(cref_type val) \
{ \
BOOST_PP_TUPLE_ELEM(4, 3, xy); \
return *this; \
} \
\
operator get_type() \
{ \
return BOOST_PP_TUPLE_ELEM(4, 2, xy); \
} \
}; \
\
static get_type call(name const& obj) \
operator lvalue() \
{ \
return BOOST_PP_TUPLE_ELEM(4, 2, xy); \
}; \
} \
}; \
\
static proxy call(name& obj) \
template <> \
struct class_member<fullname, i> \
{ \
typedef class_member_proxy<fullname, i> proxy; \
typedef proxy::type type; \
typedef proxy::rvalue get_type; \
\
static get_type call(fullname const& obj) \
{ \
return BOOST_PP_TUPLE_ELEM(4, 2, xy); \
} \
\
static proxy call(fullname& obj) \
{ \
return proxy(obj); \
}; \
} \
}; \
/***/
#endif