Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:36

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003     Copyright (c) 2001-2011 Hartmut Kaiser
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 =============================================================================*/
0008 #ifndef BOOST_SPIRIT_X3_NONTERMINAL_DETAIL_TRANSFORM_ATTRIBUTE_HPP
0009 #define BOOST_SPIRIT_X3_NONTERMINAL_DETAIL_TRANSFORM_ATTRIBUTE_HPP
0010 
0011 #include <boost/spirit/home/x3/support/traits/transform_attribute.hpp>
0012 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
0013 #include <type_traits>
0014 #include <utility>
0015 
0016 ///////////////////////////////////////////////////////////////////////////////
0017 namespace boost { namespace spirit { namespace x3
0018 {
0019     struct parser_id;
0020 
0021     template <typename Exposed, typename Transformed>
0022     struct default_transform_attribute
0023     {
0024         typedef Transformed type;
0025 
0026         static Transformed pre(Exposed&) { return Transformed(); }
0027 
0028         static void post(Exposed& val, Transformed&& attribute)
0029         {
0030             traits::move_to(std::forward<Transformed>(attribute), val);
0031         }
0032     };
0033 
0034     // handle case where no transformation is required as the types are the same
0035     template <typename Attribute>
0036     struct default_transform_attribute<Attribute, Attribute>
0037     {
0038         typedef Attribute& type;
0039         static Attribute& pre(Attribute& val) { return val; }
0040         static void post(Attribute&, Attribute const&) {}
0041     };
0042 
0043     // main specialization for x3
0044     template <typename Exposed, typename Transformed, typename Enable = void>
0045     struct transform_attribute
0046       : default_transform_attribute<Exposed, Transformed> {};
0047 
0048     // unused_type needs some special handling as well
0049     template <>
0050     struct transform_attribute<unused_type, unused_type>
0051     {
0052         typedef unused_type type;
0053         static unused_type pre(unused_type) { return unused; }
0054         static void post(unused_type, unused_type) {}
0055     };
0056 
0057     template <>
0058     struct transform_attribute<unused_type const, unused_type>
0059       : transform_attribute<unused_type, unused_type> {};
0060 
0061     template <typename Attribute>
0062     struct transform_attribute<unused_type, Attribute>
0063       : transform_attribute<unused_type, unused_type> {};
0064 
0065     template <typename Attribute>
0066     struct transform_attribute<unused_type const, Attribute>
0067       : transform_attribute<unused_type, unused_type> {};
0068 
0069     template <typename Attribute>
0070     struct transform_attribute<Attribute, unused_type>
0071       : transform_attribute<unused_type, unused_type> {};
0072 
0073     template <typename Attribute>
0074     struct transform_attribute<Attribute const, unused_type>
0075       : transform_attribute<unused_type, unused_type> {};
0076 }}}
0077 
0078 ///////////////////////////////////////////////////////////////////////////////
0079 namespace boost { namespace spirit { namespace x3 { namespace traits
0080 {
0081     template <typename Exposed, typename Transformed>
0082     struct transform_attribute<Exposed, Transformed, x3::parser_id>
0083       : x3::transform_attribute<Exposed, Transformed>
0084     {
0085         static_assert(!std::is_reference<Exposed>::value,
0086             "Exposed cannot be a reference type");
0087         static_assert(!std::is_reference<Transformed>::value,
0088             "Transformed cannot be a reference type");
0089     };
0090 }}}}
0091 
0092 #endif