Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:52:55

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003     Copyright (c) 2001-2011 Hartmut Kaiser
0004     Copyright (c) 2017 wanghan02
0005     Copyright (c) 2024 Nana Sakisaka
0006 
0007     Distributed under the Boost Software License, Version 1.0. (See accompanying
0008     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 #if !defined(BOOST_SPIRIT_X3_OPTIONAL_MARCH_23_2007_1117PM)
0011 #define BOOST_SPIRIT_X3_OPTIONAL_MARCH_23_2007_1117PM
0012 
0013 #include <boost/spirit/home/x3/core/proxy.hpp>
0014 #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
0015 #include <boost/spirit/home/x3/support/expectation.hpp>
0016 #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
0017 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
0018 #include <boost/spirit/home/x3/support/traits/optional_traits.hpp>
0019 #include <boost/spirit/home/x3/support/traits/attribute_category.hpp>
0020 
0021 namespace boost { namespace spirit { namespace x3
0022 {
0023     template <typename Subject>
0024     struct optional : proxy<Subject, optional<Subject>>
0025     {
0026         typedef proxy<Subject, optional<Subject>> base_type;
0027         static bool const is_pass_through_unary = false;
0028         static bool const handles_container = true;
0029 
0030         constexpr optional(Subject const& subject)
0031           : base_type(subject) {}
0032 
0033         using base_type::parse_subject;
0034 
0035         // Attribute is a container
0036         template <typename Iterator, typename Context
0037           , typename RContext, typename Attribute>
0038         bool parse_subject(Iterator& first, Iterator const& last
0039           , Context const& context, RContext& rcontext, Attribute& attr
0040           , traits::container_attribute) const
0041         {
0042             detail::parse_into_container(
0043                 this->subject, first, last, context, rcontext, attr);
0044             return !has_expectation_failure(context);
0045         }
0046 
0047         // Attribute is an optional
0048         template <typename Iterator, typename Context
0049           , typename RContext, typename Attribute>
0050         bool parse_subject(Iterator& first, Iterator const& last
0051           , Context const& context, RContext& rcontext, Attribute& attr
0052           , traits::optional_attribute) const
0053         {
0054             typedef typename
0055                 x3::traits::optional_value<Attribute>::type
0056             value_type;
0057 
0058             // create a local value
0059             value_type val{};
0060 
0061             if (this->subject.parse(first, last, context, rcontext, val))
0062             {
0063                 // assign the parsed value into our attribute
0064                 x3::traits::move_to(val, attr);
0065 
0066             } else {
0067                 return !has_expectation_failure(context);
0068             }
0069             return true;
0070         }
0071     };
0072 
0073     template <typename Subject>
0074     constexpr optional<typename extension::as_parser<Subject>::value_type>
0075     operator-(Subject const& subject)
0076     {
0077         return { as_parser(subject) };
0078     }
0079 }}}
0080 
0081 namespace boost { namespace spirit { namespace x3 { namespace traits
0082 {
0083     template <typename Subject, typename Context>
0084     struct attribute_of<x3::optional<Subject>, Context>
0085         : build_optional<
0086             typename attribute_of<Subject, Context>::type> {};
0087 }}}}
0088 
0089 #endif