Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:09:16

0001 //  Copyright (c) 2001-2011 Joel de Guzman
0002 //  Copyright (c) 2001-2011 Hartmut Kaiser
0003 //
0004 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_SPIRIT_KARMA_OPERATOR_OPTIONAL_HPP
0008 #define BOOST_SPIRIT_KARMA_OPERATOR_OPTIONAL_HPP
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/spirit/home/karma/domain.hpp>
0015 #include <boost/spirit/home/karma/generator.hpp>
0016 #include <boost/spirit/home/karma/meta_compiler.hpp>
0017 #include <boost/spirit/home/support/info.hpp>
0018 #include <boost/spirit/home/support/unused.hpp>
0019 #include <boost/spirit/home/karma/detail/attributes.hpp>
0020 #include <boost/spirit/home/support/container.hpp>
0021 #include <boost/spirit/home/support/has_semantic_action.hpp>
0022 #include <boost/spirit/home/support/handles_container.hpp>
0023 #include <boost/mpl/assert.hpp>
0024 #include <boost/optional.hpp>
0025 #include <boost/proto/operators.hpp>
0026 #include <boost/proto/tags.hpp>
0027 #include <boost/type_traits/is_convertible.hpp>
0028 
0029 namespace boost { namespace spirit
0030 {
0031     ///////////////////////////////////////////////////////////////////////////
0032     // Enablers
0033     ///////////////////////////////////////////////////////////////////////////
0034     template <>
0035     struct use_operator<karma::domain, proto::tag::negate> // enables -g
0036       : mpl::true_ {};
0037 
0038 }}
0039 
0040 ///////////////////////////////////////////////////////////////////////////////
0041 namespace boost { namespace spirit { namespace karma
0042 {
0043     ///////////////////////////////////////////////////////////////////////////
0044     template <typename Subject>
0045     struct optional : unary_generator<optional<Subject> >
0046     {
0047         typedef Subject subject_type;
0048         typedef typename subject_type::properties properties;
0049 
0050         // Build a boost::optional from the subject's attribute. Note
0051         // that boost::optional may return unused_type if the
0052         // subject's attribute is an unused_type.
0053         template <typename Context, typename Iterator = unused_type>
0054         struct attribute
0055           : traits::build_optional<
0056                 typename traits::attribute_of<Subject, Context, Iterator>::type
0057             >
0058         {};
0059 
0060         optional(Subject const& subject)
0061           : subject(subject) {}
0062 
0063         template <
0064             typename OutputIterator, typename Context, typename Delimiter
0065           , typename Attribute>
0066         bool generate(OutputIterator& sink, Context& ctx
0067           , Delimiter const& d, Attribute const& attr) const
0068         {
0069             if (traits::has_optional_value(attr)) 
0070                 subject.generate(sink, ctx, d, traits::optional_value(attr));
0071             return sink_is_good(sink);
0072         }
0073 
0074         template <typename Context>
0075         info what(Context& context) const
0076         {
0077             return info("optional", subject.what(context));
0078         }
0079 
0080         Subject subject;
0081     };
0082 
0083     ///////////////////////////////////////////////////////////////////////////
0084     // Generator generators: make_xxx function (objects)
0085     ///////////////////////////////////////////////////////////////////////////
0086     template <typename Elements, typename Modifiers>
0087     struct make_composite<proto::tag::negate, Elements, Modifiers>
0088       : make_unary_composite<Elements, optional> {};
0089 
0090 }}}
0091 
0092 namespace boost { namespace spirit { namespace traits
0093 {
0094     ///////////////////////////////////////////////////////////////////////////
0095     template <typename Subject>
0096     struct has_semantic_action<karma::optional<Subject> >
0097       : unary_has_semantic_action<Subject> {};
0098 
0099     ///////////////////////////////////////////////////////////////////////////
0100     template <typename Subject, typename Attribute, typename Context
0101       , typename Iterator>
0102     struct handles_container<karma::optional<Subject>, Attribute, Context
0103           , Iterator>
0104       : mpl::true_ {};
0105 }}}
0106 
0107 #endif