annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/operator/optional.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (c) 2001-2011 Joel de Guzman
Chris@16 2 // Copyright (c) 2001-2011 Hartmut Kaiser
Chris@16 3 //
Chris@16 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 #if !defined(SPIRIT_KARMA_OPTIONAL_MARCH_31_2007_0852AM)
Chris@16 8 #define SPIRIT_KARMA_OPTIONAL_MARCH_31_2007_0852AM
Chris@16 9
Chris@16 10 #if defined(_MSC_VER)
Chris@16 11 #pragma once
Chris@16 12 #endif
Chris@16 13
Chris@16 14 #include <boost/spirit/home/karma/domain.hpp>
Chris@16 15 #include <boost/spirit/home/karma/generator.hpp>
Chris@16 16 #include <boost/spirit/home/karma/meta_compiler.hpp>
Chris@16 17 #include <boost/spirit/home/support/info.hpp>
Chris@16 18 #include <boost/spirit/home/support/unused.hpp>
Chris@16 19 #include <boost/spirit/home/karma/detail/attributes.hpp>
Chris@16 20 #include <boost/spirit/home/support/container.hpp>
Chris@16 21 #include <boost/spirit/home/support/has_semantic_action.hpp>
Chris@16 22 #include <boost/spirit/home/support/handles_container.hpp>
Chris@16 23 #include <boost/mpl/assert.hpp>
Chris@16 24 #include <boost/optional.hpp>
Chris@16 25 #include <boost/type_traits/is_convertible.hpp>
Chris@16 26
Chris@16 27 namespace boost { namespace spirit
Chris@16 28 {
Chris@16 29 ///////////////////////////////////////////////////////////////////////////
Chris@16 30 // Enablers
Chris@16 31 ///////////////////////////////////////////////////////////////////////////
Chris@16 32 template <>
Chris@16 33 struct use_operator<karma::domain, proto::tag::negate> // enables -g
Chris@16 34 : mpl::true_ {};
Chris@16 35
Chris@16 36 }}
Chris@16 37
Chris@16 38 ///////////////////////////////////////////////////////////////////////////////
Chris@16 39 namespace boost { namespace spirit { namespace karma
Chris@16 40 {
Chris@16 41 ///////////////////////////////////////////////////////////////////////////
Chris@16 42 template <typename Subject>
Chris@16 43 struct optional : unary_generator<optional<Subject> >
Chris@16 44 {
Chris@16 45 typedef Subject subject_type;
Chris@16 46 typedef typename subject_type::properties properties;
Chris@16 47
Chris@16 48 // Build a boost::optional from the subject's attribute. Note
Chris@16 49 // that boost::optional may return unused_type if the
Chris@16 50 // subject's attribute is an unused_type.
Chris@16 51 template <typename Context, typename Iterator = unused_type>
Chris@16 52 struct attribute
Chris@16 53 : traits::build_optional<
Chris@16 54 typename traits::attribute_of<Subject, Context, Iterator>::type
Chris@16 55 >
Chris@16 56 {};
Chris@16 57
Chris@16 58 optional(Subject const& subject)
Chris@16 59 : subject(subject) {}
Chris@16 60
Chris@16 61 template <
Chris@16 62 typename OutputIterator, typename Context, typename Delimiter
Chris@16 63 , typename Attribute>
Chris@16 64 bool generate(OutputIterator& sink, Context& ctx
Chris@16 65 , Delimiter const& d, Attribute const& attr) const
Chris@16 66 {
Chris@16 67 if (traits::has_optional_value(attr))
Chris@16 68 subject.generate(sink, ctx, d, traits::optional_value(attr));
Chris@16 69 return sink_is_good(sink);
Chris@16 70 }
Chris@16 71
Chris@16 72 template <typename Context>
Chris@16 73 info what(Context& context) const
Chris@16 74 {
Chris@16 75 return info("optional", subject.what(context));
Chris@16 76 }
Chris@16 77
Chris@16 78 Subject subject;
Chris@16 79 };
Chris@16 80
Chris@16 81 ///////////////////////////////////////////////////////////////////////////
Chris@16 82 // Generator generators: make_xxx function (objects)
Chris@16 83 ///////////////////////////////////////////////////////////////////////////
Chris@16 84 template <typename Elements, typename Modifiers>
Chris@16 85 struct make_composite<proto::tag::negate, Elements, Modifiers>
Chris@16 86 : make_unary_composite<Elements, optional> {};
Chris@16 87
Chris@16 88 }}}
Chris@16 89
Chris@16 90 namespace boost { namespace spirit { namespace traits
Chris@16 91 {
Chris@16 92 ///////////////////////////////////////////////////////////////////////////
Chris@16 93 template <typename Subject>
Chris@16 94 struct has_semantic_action<karma::optional<Subject> >
Chris@16 95 : unary_has_semantic_action<Subject> {};
Chris@16 96
Chris@16 97 ///////////////////////////////////////////////////////////////////////////
Chris@16 98 template <typename Subject, typename Attribute, typename Context
Chris@16 99 , typename Iterator>
Chris@16 100 struct handles_container<karma::optional<Subject>, Attribute, Context
Chris@16 101 , Iterator>
Chris@16 102 : mpl::true_ {};
Chris@16 103 }}}
Chris@16 104
Chris@16 105 #endif