forked from boostorg/fusion
better adapt structs/classes implementation
[SVN r59913]
This commit is contained in:
@@ -1,14 +1,35 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
Copyright (c) 2010 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_ADAPTED_DETAIL_CLASS_ADAPT_BASE_HPP
|
||||
#define BOOST_FUSION_ADAPTED_DETAIL_CLASS_ADAPT_BASE_HPP
|
||||
#ifndef BOOST_FUSION_ADAPTED_CLASS_DETAIL_ADAPT_BASE_HPP
|
||||
#define BOOST_FUSION_ADAPTED_CLASS_DETAIL_ADAPT_BASE_HPP
|
||||
|
||||
#include <boost/fusion/adapted/struct/detail/adapt_base.hpp>
|
||||
#include <boost/preprocessor/control/if.hpp>
|
||||
#include <boost/preprocessor/seq/seq.hpp>
|
||||
#include <boost/preprocessor/seq/elem.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
|
||||
//cschmidt: Spirit relies on Fusion defining class_member_proxy in the
|
||||
//boost::fusion::extension namespace, with two nested types named lvalue and
|
||||
//rvalue.
|
||||
|
||||
#define BOOST_FUSION_ADAPT_CLASS_GET_IDENTITY_TEMPLATE_IMPL(TEMPLATE_PARAMS_SEQ)\
|
||||
typename detail::get_identity< \
|
||||
lvalue \
|
||||
, BOOST_PP_SEQ_ELEM(1,TEMPLATE_PARAMS_SEQ) \
|
||||
>::type
|
||||
|
||||
#define BOOST_FUSION_ADAPT_CLASS_GET_IDENTITY_NON_TEMPLATE_IMPL( \
|
||||
TEMPLATE_PARAMS_SEQ) \
|
||||
\
|
||||
lvalue
|
||||
|
||||
#define BOOST_FUSION_ADAPT_CLASS_C_BASE(\
|
||||
TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE) \
|
||||
@@ -21,9 +42,8 @@
|
||||
, I \
|
||||
> \
|
||||
{ \
|
||||
typedef \
|
||||
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) \
|
||||
type; \
|
||||
typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) lvalue; \
|
||||
typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) rvalue; \
|
||||
\
|
||||
class_member_proxy(BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj)\
|
||||
: obj(obj) \
|
||||
@@ -31,13 +51,13 @@
|
||||
\
|
||||
template<class Arg> \
|
||||
class_member_proxy& \
|
||||
operator=(Arg val) \
|
||||
operator=(Arg const& val) \
|
||||
{ \
|
||||
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 3, ATTRIBUTE); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
operator type() \
|
||||
operator lvalue() \
|
||||
{ \
|
||||
return BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 2, ATTRIBUTE); \
|
||||
} \
|
||||
@@ -50,34 +70,46 @@
|
||||
> \
|
||||
struct struct_member<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ), I> \
|
||||
{ \
|
||||
typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \
|
||||
typedef \
|
||||
BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) \
|
||||
get_type; \
|
||||
typedef \
|
||||
class_member_proxy< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \
|
||||
, I \
|
||||
> \
|
||||
proxy; \
|
||||
typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) lvalue; \
|
||||
\
|
||||
static get_type \
|
||||
call(BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) const& obj) \
|
||||
{ \
|
||||
return BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 2, ATTRIBUTE); \
|
||||
}; \
|
||||
typedef \
|
||||
BOOST_PP_IF( \
|
||||
BOOST_PP_SEQ_HEAD(TEMPLATE_PARAMS_SEQ), \
|
||||
BOOST_FUSION_ADAPT_CLASS_GET_IDENTITY_TEMPLATE_IMPL, \
|
||||
BOOST_FUSION_ADAPT_CLASS_GET_IDENTITY_NON_TEMPLATE_IMPL)( \
|
||||
TEMPLATE_PARAMS_SEQ) \
|
||||
type; \
|
||||
\
|
||||
static proxy \
|
||||
call(BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj) \
|
||||
template<typename Seq> \
|
||||
struct apply \
|
||||
{ \
|
||||
return proxy(obj); \
|
||||
typedef \
|
||||
class_member_proxy< \
|
||||
BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) \
|
||||
, I \
|
||||
> \
|
||||
proxy; \
|
||||
\
|
||||
typedef typename \
|
||||
mpl::if_< \
|
||||
is_const<Seq> \
|
||||
, BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) \
|
||||
, proxy \
|
||||
>::type \
|
||||
type; \
|
||||
\
|
||||
static proxy \
|
||||
call(BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)& obj) \
|
||||
{ \
|
||||
return proxy(obj); \
|
||||
} \
|
||||
\
|
||||
static BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE) \
|
||||
call(BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) const& obj) \
|
||||
{ \
|
||||
return BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 2, ATTRIBUTE); \
|
||||
} \
|
||||
}; \
|
||||
};
|
||||
|
||||
namespace boost { namespace fusion { namespace extension
|
||||
{
|
||||
template <typename T, int N>
|
||||
struct class_member_proxy;
|
||||
}}}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user