PageRenderTime 37ms CodeModel.GetById 18ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

/src/contrib/boost/spirit/home/support/adapt_class_attributes.hpp

http://pythonocc.googlecode.com/
C++ Header | 128 lines | 101 code | 15 blank | 12 comment | 0 complexity | f966cc47886b1a55dfda05e4f8c6f2cb MD5 | raw file
  1//  Copyright (c) 2001-2010 Hartmut Kaiser
  2// 
  3//  Distributed under the Boost Software License, Version 1.0. (See accompanying
  4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5
  6#if !defined(BOOST_SPIRIT_ADAPT_CLASS_ATTRIBUTES_JAN_27_2010_1219PM)
  7#define BOOST_SPIRIT_ADAPT_CLASS_ATTRIBUTES_JAN_27_2010_1219PM
  8
  9#if defined(_MSC_VER)
 10#pragma once
 11#endif
 12
 13#include <boost/spirit/home/support/attributes.hpp>
 14#include <boost/spirit/home/support/container.hpp>
 15#include <boost/fusion/include/adapt_class.hpp>
 16#include <boost/utility/enable_if.hpp>
 17
 18///////////////////////////////////////////////////////////////////////////////
 19// forward declaration only
 20namespace boost { namespace fusion { namespace extension 
 21{ 
 22    template <typename T, int N> struct class_member_proxy;
 23}}}
 24
 25///////////////////////////////////////////////////////////////////////////////
 26// customization points allowing to use adapted classes with spirit
 27namespace boost { namespace spirit { namespace traits
 28{
 29    ///////////////////////////////////////////////////////////////////////////
 30    template <typename T, int N>
 31    struct is_container<fusion::extension::class_member_proxy<T, N> >
 32      : is_container<typename fusion::extension::class_member_proxy<T, N>::type>
 33    {};
 34
 35    template <typename T, int N>
 36    struct container_value<fusion::extension::class_member_proxy<T, N> >
 37      : container_value<typename fusion::extension::class_member_proxy<T, N>::type>
 38    {};
 39
 40    template <typename T, int N, typename Val>
 41    struct push_back_container<fusion::extension::class_member_proxy<T, N>, Val
 42      , typename enable_if<
 43            is_reference<typename fusion::extension::class_member_proxy<T, N>::type> 
 44        >::type>
 45    {
 46        static bool call(fusion::extension::class_member_proxy<T, N>& p, Val const& val)
 47        {
 48            typedef typename fusion::extension::class_member_proxy<T, N>::type type;
 49            return push_back((type)p, val);
 50        }
 51    };
 52
 53    template <typename T, int N>
 54    struct container_iterator<fusion::extension::class_member_proxy<T, N> >
 55      : container_iterator<typename fusion::extension::class_member_proxy<T, N>::type>
 56    {};
 57
 58    ///////////////////////////////////////////////////////////////////////////
 59    template <typename T, int N, typename Val>
 60    struct assign_to_attribute_from_value<
 61        fusion::extension::class_member_proxy<T, N>, Val>
 62    {
 63        static void 
 64        call(Val const& val, fusion::extension::class_member_proxy<T, N>& attr)
 65        {
 66            attr = val;
 67        }
 68    };
 69
 70    ///////////////////////////////////////////////////////////////////////////
 71    template <typename T, int N>
 72    struct attribute_type<fusion::extension::class_member_proxy<T, N> > 
 73      : fusion::extension::class_member_proxy<T, N> 
 74    {};
 75
 76    ///////////////////////////////////////////////////////////////////////////
 77    template <typename T, int N, typename Attribute>
 78    struct transform_attribute<
 79        fusion::extension::class_member_proxy<T, N>, Attribute
 80      , typename disable_if<
 81            is_reference<typename fusion::extension::class_member_proxy<T, N>::lvalue> 
 82        >::type>
 83    {
 84        typedef Attribute type;
 85
 86        static Attribute 
 87        pre(fusion::extension::class_member_proxy<T, N>& val) 
 88        { 
 89            return val; 
 90        }
 91        static void 
 92        post(fusion::extension::class_member_proxy<T, N>& val
 93          , Attribute const& attr) 
 94        {
 95            val = attr;
 96        }
 97        static void 
 98        fail(fusion::extension::class_member_proxy<T, N>&) 
 99        {
100        }
101    };
102
103    template <typename T, int N, typename Attribute>
104    struct transform_attribute<
105        fusion::extension::class_member_proxy<T, N>, Attribute
106      , typename enable_if<
107            is_reference<typename fusion::extension::class_member_proxy<T, N>::lvalue> 
108        >::type>
109    {
110        typedef Attribute& type;
111
112        static Attribute& 
113        pre(fusion::extension::class_member_proxy<T, N>& val) 
114        { 
115            return val; 
116        }
117        static void 
118        post(fusion::extension::class_member_proxy<T, N>&, Attribute const&) 
119        {
120        }
121        static void 
122        fail(fusion::extension::class_member_proxy<T, N>&) 
123        {
124        }
125    };
126}}}
127
128#endif