Back to home page

EIC code displayed by LXR

 
 

    


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

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 #if !defined(BOOST_SPIRIT_X3_OPTIONAL_MARCH_23_2007_1117PM)
0009 #define BOOST_SPIRIT_X3_OPTIONAL_MARCH_23_2007_1117PM
0010 
0011 #include <boost/spirit/home/x3/core/proxy.hpp>
0012 #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
0013 #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
0014 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
0015 #include <boost/spirit/home/x3/support/traits/optional_traits.hpp>
0016 #include <boost/spirit/home/x3/support/traits/attribute_category.hpp>
0017 
0018 namespace boost { namespace spirit { namespace x3
0019 {
0020     template <typename Subject>
0021     struct optional : proxy<Subject, optional<Subject>>
0022     {
0023         typedef proxy<Subject, optional<Subject>> base_type;
0024         static bool const is_pass_through_unary = false;
0025         static bool const handles_container = true;
0026 
0027         constexpr optional(Subject const& subject)
0028           : base_type(subject) {}
0029 
0030         using base_type::parse_subject;
0031 
0032         // Attribute is a container
0033         template <typename Iterator, typename Context
0034           , typename RContext, typename Attribute>
0035         bool parse_subject(Iterator& first, Iterator const& last
0036           , Context const& context, RContext& rcontext, Attribute& attr
0037           , traits::container_attribute) const
0038         {
0039             detail::parse_into_container(
0040                 this->subject, first, last, context, rcontext, attr);
0041             return true;
0042         }
0043 
0044         // Attribute is an optional
0045         template <typename Iterator, typename Context
0046           , typename RContext, typename Attribute>
0047         bool parse_subject(Iterator& first, Iterator const& last
0048           , Context const& context, RContext& rcontext, Attribute& attr
0049           , traits::optional_attribute) const
0050         {
0051             typedef typename
0052                 x3::traits::optional_value<Attribute>::type
0053             value_type;
0054 
0055             // create a local value
0056             value_type val{};
0057 
0058             if (this->subject.parse(first, last, context, rcontext, val))
0059             {
0060                 // assign the parsed value into our attribute
0061                 x3::traits::move_to(val, attr);
0062             }
0063             return true;
0064         }
0065     };
0066 
0067     template <typename Subject>
0068     constexpr optional<typename extension::as_parser<Subject>::value_type>
0069     operator-(Subject const& subject)
0070     {
0071         return { as_parser(subject) };
0072     }
0073 }}}
0074 
0075 namespace boost { namespace spirit { namespace x3 { namespace traits
0076 {
0077     template <typename Subject, typename Context>
0078     struct attribute_of<x3::optional<Subject>, Context>
0079         : build_optional<
0080             typename attribute_of<Subject, Context>::type> {};
0081 }}}}
0082 
0083 #endif