Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:53

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 // 
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #if !defined(BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM)
0007 #define BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/support/attributes.hpp>
0014 #include <boost/spirit/home/support/container.hpp>
0015 #include <boost/spirit/home/support/numeric_traits.hpp>
0016 #include <boost/fusion/include/adapt_adt.hpp>
0017 #include <boost/utility/enable_if.hpp>
0018 
0019 ///////////////////////////////////////////////////////////////////////////////
0020 // customization points allowing to use adapted classes with spirit
0021 namespace boost { namespace spirit { namespace traits
0022 {
0023     ///////////////////////////////////////////////////////////////////////////
0024     template <typename T, int N, bool Const, typename Domain>
0025     struct not_is_variant<
0026             fusion::extension::adt_attribute_proxy<T, N, Const>, Domain>
0027       : not_is_variant<
0028             typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
0029           , Domain>
0030     {};
0031 
0032     template <typename T, int N, bool Const, typename Domain>
0033     struct not_is_optional<
0034             fusion::extension::adt_attribute_proxy<T, N, Const>, Domain>
0035       : not_is_optional<
0036             typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
0037           , Domain>
0038     {};
0039 
0040     ///////////////////////////////////////////////////////////////////////////
0041     template <typename T, int N, bool Const>
0042     struct is_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
0043       : is_container<
0044             typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
0045         >
0046     {};
0047 
0048     template <typename T, int N, bool Const>
0049     struct container_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
0050       : container_value<
0051             typename remove_reference<
0052                 typename fusion::extension::adt_attribute_proxy<
0053                     T, N, Const
0054                 >::type
0055             >::type
0056         >
0057     {};
0058 
0059     template <typename T, int N, bool Const>
0060     struct container_value<
0061             fusion::extension::adt_attribute_proxy<T, N, Const> const>
0062       : container_value<
0063             typename add_const<
0064                 typename remove_reference<
0065                     typename fusion::extension::adt_attribute_proxy<
0066                         T, N, Const
0067                     >::type
0068                 >::type 
0069             >::type 
0070         >
0071     {};
0072 
0073     template <typename T, int N, typename Val>
0074     struct push_back_container<
0075         fusion::extension::adt_attribute_proxy<T, N, false>
0076       , Val
0077       , typename enable_if<is_reference<
0078             typename fusion::extension::adt_attribute_proxy<T, N, false>::type
0079         > >::type>
0080     {
0081         static bool call(
0082             fusion::extension::adt_attribute_proxy<T, N, false>& p
0083           , Val const& val)
0084         {
0085             typedef typename 
0086                 fusion::extension::adt_attribute_proxy<T, N, false>::type
0087             type;
0088             return push_back(type(p), val);
0089         }
0090     };
0091 
0092     template <typename T, int N, bool Const>
0093     struct container_iterator<
0094             fusion::extension::adt_attribute_proxy<T, N, Const> >
0095       : container_iterator<
0096             typename remove_reference<
0097                 typename fusion::extension::adt_attribute_proxy<
0098                     T, N, Const
0099                 >::type
0100             >::type
0101         >
0102     {};
0103 
0104     template <typename T, int N, bool Const>
0105     struct container_iterator<
0106             fusion::extension::adt_attribute_proxy<T, N, Const> const>
0107       : container_iterator<
0108             typename add_const<
0109                 typename remove_reference<
0110                     typename fusion::extension::adt_attribute_proxy<
0111                         T, N, Const
0112                     >::type
0113                 >::type 
0114             >::type 
0115         >
0116     {};
0117 
0118     template <typename T, int N, bool Const>
0119     struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
0120     {
0121         typedef typename remove_reference<
0122             typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
0123         >::type container_type;
0124 
0125         static typename container_iterator<container_type>::type 
0126         call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
0127         {
0128             return c.get().begin();
0129         }
0130     };
0131 
0132     template <typename T, int N, bool Const>
0133     struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
0134     {
0135         typedef typename add_const<
0136             typename remove_reference<
0137                 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type 
0138             >::type
0139         >::type container_type;
0140 
0141         static typename container_iterator<container_type>::type 
0142         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
0143         {
0144             return c.get().begin();
0145         }
0146     };
0147 
0148     template <typename T, int N, bool Const>
0149     struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
0150     {
0151         typedef typename remove_reference<
0152             typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
0153         >::type container_type;
0154 
0155         static typename container_iterator<container_type>::type 
0156         call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
0157         {
0158             return c.get().end();
0159         }
0160     };
0161 
0162     template <typename T, int N, bool Const>
0163     struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
0164     {
0165         typedef typename add_const<
0166             typename remove_reference<
0167                 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type 
0168             >::type
0169         >::type container_type;
0170 
0171         static typename container_iterator<container_type>::type 
0172         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
0173         {
0174             return c.get().end();
0175         }
0176     };
0177 
0178     ///////////////////////////////////////////////////////////////////////////
0179     template <typename T, int N, typename Val>
0180     struct assign_to_attribute_from_value<
0181         fusion::extension::adt_attribute_proxy<T, N, false>
0182       , Val>
0183     {
0184         static void 
0185         call(Val const& val
0186           , fusion::extension::adt_attribute_proxy<T, N, false>& attr)
0187         {
0188             attr = val;
0189         }
0190     };
0191 
0192     template <typename T, int N, bool Const, typename Exposed>
0193     struct extract_from_attribute<
0194         fusion::extension::adt_attribute_proxy<T, N, Const>, Exposed>
0195     {
0196         typedef
0197             typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
0198         get_return_type;
0199         typedef typename remove_const<
0200             typename remove_reference<
0201                 get_return_type
0202             >::type
0203         >::type embedded_type;
0204         typedef 
0205             typename spirit::result_of::extract_from<Exposed, embedded_type>::type
0206         extracted_type;
0207 
0208         // If adt_attribute_proxy returned a value we must pass the attribute
0209         // by value, otherwise we will end up with a reference to a temporary
0210         // that will expire out of scope of the function call.
0211         typedef typename mpl::if_c<is_reference<get_return_type>::value
0212           , extracted_type
0213           , typename remove_reference<extracted_type>::type
0214         >::type type;
0215 
0216         template <typename Context>
0217         static type 
0218         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val, Context& ctx)
0219         {
0220             return extract_from<Exposed>(val.get(), ctx);
0221         }
0222     };
0223 
0224     ///////////////////////////////////////////////////////////////////////////
0225     template <typename T, int N, bool Const>
0226     struct attribute_type<fusion::extension::adt_attribute_proxy<T, N, Const> >
0227       : fusion::extension::adt_attribute_proxy<T, N, Const>
0228     {};
0229 
0230     ///////////////////////////////////////////////////////////////////////////
0231     template <typename T, int N, bool Const>
0232     struct optional_attribute<
0233         fusion::extension::adt_attribute_proxy<T, N, Const> >
0234     {
0235         typedef typename result_of::optional_value<
0236             typename remove_reference<
0237                 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type 
0238             >::type
0239         >::type type;
0240 
0241         static type 
0242         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
0243         {
0244             return optional_value(val.get());
0245         }
0246 
0247         static bool 
0248         is_valid(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
0249         {
0250             return has_optional_value(val.get());
0251         }
0252     };
0253 
0254     ///////////////////////////////////////////////////////////////////////////
0255     template <typename T, int N, typename Attribute, typename Domain>
0256     struct transform_attribute<
0257         fusion::extension::adt_attribute_proxy<T, N, false>
0258       , Attribute
0259       , Domain
0260       , typename disable_if<is_reference<
0261             typename fusion::extension::adt_attribute_proxy<T, N, false>::type
0262         > >::type>
0263     {
0264         typedef Attribute type;
0265 
0266         static Attribute 
0267         pre(fusion::extension::adt_attribute_proxy<T, N, false>& val)
0268         { 
0269             return val; 
0270         }
0271         static void 
0272         post(
0273             fusion::extension::adt_attribute_proxy<T, N, false>& val
0274           , Attribute const& attr) 
0275         {
0276             val = attr;
0277         }
0278         static void 
0279         fail(fusion::extension::adt_attribute_proxy<T, N, false>&)
0280         {
0281         }
0282     };
0283 
0284     template <
0285         typename T, int N, bool Const, typename Attribute, typename Domain>
0286     struct transform_attribute<
0287         fusion::extension::adt_attribute_proxy<T, N, Const>
0288       , Attribute
0289       , Domain
0290       , typename enable_if<is_reference<
0291             typename fusion::extension::adt_attribute_proxy<
0292                 T, N, Const
0293             >::type
0294         > >::type>
0295     {
0296         typedef Attribute& type;
0297 
0298         static Attribute& 
0299         pre(fusion::extension::adt_attribute_proxy<T, N, Const>& val)
0300         { 
0301             return val; 
0302         }
0303         static void 
0304         post(
0305             fusion::extension::adt_attribute_proxy<T, N, Const>&
0306           , Attribute const&)
0307         {
0308         }
0309         static void 
0310         fail(fusion::extension::adt_attribute_proxy<T, N, Const>&)
0311         {
0312         }
0313     };
0314 
0315     template <typename T, int N, bool Const>
0316     struct clear_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
0317     {
0318         static void call(
0319             fusion::extension::adt_attribute_proxy<T, N, Const>& val)
0320         {
0321             typedef typename 
0322                 fusion::extension::adt_attribute_proxy<T, N, Const>::type
0323             type;
0324             clear(type(val));
0325         }
0326     };
0327 
0328     template <typename T, int N, bool Const>
0329     struct attribute_size<fusion::extension::adt_attribute_proxy<T, N, Const> >
0330     {
0331         typedef typename remove_const<
0332             typename remove_reference<
0333                 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type 
0334             >::type
0335         >::type embedded_type;
0336 
0337         typedef typename attribute_size<embedded_type>::type type;
0338 
0339         static type 
0340         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
0341         {
0342             return attribute_size<embedded_type>::call(val.get());
0343         }
0344     };
0345 
0346     ///////////////////////////////////////////////////////////////////////////
0347     // customization point specializations for numeric generators
0348     template <typename T, int N, bool Const>
0349     struct absolute_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
0350     {
0351         typedef typename 
0352             fusion::extension::adt_attribute_proxy<T, N, Const>::type
0353         type;
0354 
0355         static type 
0356         call (fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
0357         {
0358             return get_absolute_value(val.get());
0359         }
0360     };
0361 
0362     template <typename T, int N, bool Const>
0363     struct is_negative<fusion::extension::adt_attribute_proxy<T, N, Const> >
0364     {
0365         static bool 
0366         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val) 
0367         { 
0368             return test_negative(val.get()); 
0369         }
0370     };
0371 
0372     template <typename T, int N, bool Const>
0373     struct is_zero<fusion::extension::adt_attribute_proxy<T, N, Const> >
0374     {
0375         static bool 
0376         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val) 
0377         { 
0378             return test_zero(val.get()); 
0379         }
0380     };
0381 
0382     template <typename T, int N, bool Const>
0383     struct is_nan<fusion::extension::adt_attribute_proxy<T, N, Const> >
0384     {
0385         static bool 
0386         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val) 
0387         { 
0388             return test_nan(val.get()); 
0389         }
0390     };
0391 
0392     template <typename T, int N, bool Const>
0393     struct is_infinite<fusion::extension::adt_attribute_proxy<T, N, Const> >
0394     {
0395         static bool 
0396         call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val) 
0397         { 
0398             return test_infinite(val.get()); 
0399         }
0400     };
0401 }}}
0402 
0403 ///////////////////////////////////////////////////////////////////////////////
0404 namespace boost { namespace spirit { namespace result_of
0405 {
0406     template <typename T, int N, bool Const>
0407     struct optional_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
0408       : result_of::optional_value<
0409             typename remove_const<
0410                 typename remove_reference<
0411                     typename fusion::extension::adt_attribute_proxy<T, N, Const>::type 
0412                 >::type
0413             >::type>
0414     {};
0415 }}}
0416 
0417 #endif