annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/auto/auto.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 Hartmut Kaiser
Chris@16 2 //
Chris@16 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5
Chris@16 6 #if !defined(BOOST_SPIRIT_KARMA_AUTO_NOV_29_2009_0339PM)
Chris@16 7 #define BOOST_SPIRIT_KARMA_AUTO_NOV_29_2009_0339PM
Chris@16 8
Chris@16 9 #if defined(_MSC_VER)
Chris@16 10 #pragma once
Chris@16 11 #endif
Chris@16 12
Chris@16 13 #include <boost/spirit/home/support/common_terminals.hpp>
Chris@16 14 #include <boost/spirit/home/support/info.hpp>
Chris@16 15 #include <boost/spirit/home/support/container.hpp>
Chris@16 16 #include <boost/spirit/home/support/assert_msg.hpp>
Chris@16 17 #include <boost/spirit/home/support/detail/hold_any.hpp>
Chris@16 18 #include <boost/spirit/home/karma/domain.hpp>
Chris@16 19 #include <boost/spirit/home/karma/meta_compiler.hpp>
Chris@16 20 #include <boost/spirit/home/karma/delimit_out.hpp>
Chris@16 21 #include <boost/spirit/home/karma/generator.hpp>
Chris@16 22 #include <boost/spirit/home/karma/auto/create_generator.hpp>
Chris@16 23 #include <boost/mpl/bool.hpp>
Chris@16 24
Chris@16 25 ///////////////////////////////////////////////////////////////////////////////
Chris@16 26 namespace boost { namespace spirit
Chris@16 27 {
Chris@16 28 ///////////////////////////////////////////////////////////////////////////
Chris@16 29 // Enablers
Chris@16 30 ///////////////////////////////////////////////////////////////////////////
Chris@16 31 template <>
Chris@16 32 struct use_terminal<karma::domain, tag::auto_> // enables auto_
Chris@16 33 : mpl::true_ {};
Chris@16 34
Chris@16 35 template <typename A0>
Chris@16 36 struct use_terminal<karma::domain // enables auto_(...)
Chris@16 37 , terminal_ex<tag::auto_, fusion::vector1<A0> >
Chris@16 38 > : mpl::true_ {};
Chris@16 39
Chris@16 40 template <> // enables auto_(f)
Chris@16 41 struct use_lazy_terminal<
Chris@16 42 karma::domain, tag::auto_, 1 /*arity*/
Chris@16 43 > : mpl::true_ {};
Chris@16 44
Chris@16 45 }}
Chris@16 46
Chris@16 47 ///////////////////////////////////////////////////////////////////////////////
Chris@16 48 namespace boost { namespace spirit { namespace karma
Chris@16 49 {
Chris@16 50 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
Chris@16 51 using spirit::auto_;
Chris@16 52 #endif
Chris@16 53 using spirit::auto_type;
Chris@16 54
Chris@16 55 ///////////////////////////////////////////////////////////////////////////
Chris@16 56 template <typename Modifiers>
Chris@16 57 struct auto_generator
Chris@16 58 : generator<auto_generator<Modifiers> >
Chris@16 59 {
Chris@16 60 typedef mpl::int_<generator_properties::all_properties> properties;
Chris@16 61
Chris@16 62 template <typename Context, typename Unused>
Chris@16 63 struct attribute
Chris@16 64 {
Chris@16 65 typedef spirit::basic_hold_any<char> type;
Chris@16 66 };
Chris@16 67
Chris@16 68 auto_generator(Modifiers const& modifiers)
Chris@16 69 : modifiers_(modifiers) {}
Chris@16 70
Chris@16 71 // auto_generator has an attached attribute
Chris@16 72 template <
Chris@16 73 typename OutputIterator, typename Context, typename Delimiter
Chris@16 74 , typename Attribute>
Chris@16 75 bool generate(OutputIterator& sink, Context& context
Chris@16 76 , Delimiter const& d, Attribute const& attr) const
Chris@16 77 {
Chris@16 78 return compile<karma::domain>(create_generator<Attribute>(), modifiers_)
Chris@16 79 .generate(sink, context, d, attr);
Chris@16 80 }
Chris@16 81
Chris@16 82 // this auto_generator has no attribute attached, it needs to have been
Chris@16 83 // initialized from a value/variable
Chris@16 84 template <typename OutputIterator, typename Context
Chris@16 85 , typename Delimiter>
Chris@16 86 static bool
Chris@16 87 generate(OutputIterator&, Context&, Delimiter const&, unused_type)
Chris@16 88 {
Chris@16 89 // It is not possible (doesn't make sense) to use auto_ generators
Chris@16 90 // without providing any attribute, as the generator doesn't 'know'
Chris@16 91 // what to output. The following assertion fires if this situation
Chris@16 92 // is detected in your code.
Chris@16 93 BOOST_SPIRIT_ASSERT_FAIL(OutputIterator, auto_not_usable_without_attribute, ());
Chris@16 94 return false;
Chris@16 95 }
Chris@16 96
Chris@16 97 template <typename Context>
Chris@16 98 info what(Context& /*context*/) const
Chris@16 99 {
Chris@16 100 return info("auto_");
Chris@16 101 }
Chris@16 102
Chris@16 103 Modifiers modifiers_;
Chris@16 104 };
Chris@16 105
Chris@16 106 ///////////////////////////////////////////////////////////////////////////
Chris@16 107 template <typename T, typename Modifiers>
Chris@16 108 struct lit_auto_generator
Chris@16 109 : generator<lit_auto_generator<T, Modifiers> >
Chris@16 110 {
Chris@16 111 typedef mpl::int_<generator_properties::all_properties> properties;
Chris@16 112
Chris@16 113 template <typename Context, typename Unused>
Chris@16 114 struct attribute
Chris@16 115 {
Chris@16 116 typedef unused_type type;
Chris@16 117 };
Chris@16 118
Chris@16 119 lit_auto_generator(typename add_reference<T>::type t, Modifiers const& modifiers)
Chris@16 120 : t_(t)
Chris@16 121 , generator_(compile<karma::domain>(create_generator<T>(), modifiers))
Chris@16 122 {}
Chris@16 123
Chris@16 124 // auto_generator has an attached attribute
Chris@16 125 template <
Chris@16 126 typename OutputIterator, typename Context, typename Delimiter
Chris@16 127 , typename Attribute>
Chris@16 128 bool generate(OutputIterator& sink, Context& context
Chris@16 129 , Delimiter const& d, Attribute const&) const
Chris@16 130 {
Chris@16 131 return generator_.generate(sink, context, d, t_);
Chris@16 132 }
Chris@16 133
Chris@16 134 template <typename Context>
Chris@16 135 info what(Context& /*context*/) const
Chris@16 136 {
Chris@16 137 return info("auto_");
Chris@16 138 }
Chris@16 139
Chris@16 140 typedef typename spirit::result_of::create_generator<T>::type
Chris@16 141 generator_type;
Chris@16 142
Chris@16 143 typedef typename spirit::result_of::compile<
Chris@16 144 karma::domain, generator_type, Modifiers>::type generator_impl_type;
Chris@16 145
Chris@16 146 T t_;
Chris@16 147 generator_impl_type generator_;
Chris@16 148
Chris@16 149 private:
Chris@16 150 // silence MSVC warning C4512: assignment operator could not be generated
Chris@16 151 lit_auto_generator& operator= (lit_auto_generator const&);
Chris@16 152 };
Chris@16 153
Chris@16 154 ///////////////////////////////////////////////////////////////////////////
Chris@16 155 // Generator generators: make_xxx function (objects)
Chris@16 156 ///////////////////////////////////////////////////////////////////////////
Chris@16 157
Chris@16 158 // auto_
Chris@16 159 template <typename Modifiers>
Chris@16 160 struct make_primitive<tag::auto_, Modifiers>
Chris@16 161 {
Chris@16 162 typedef auto_generator<Modifiers> result_type;
Chris@16 163
Chris@16 164 result_type operator()(unused_type, Modifiers const& modifiers) const
Chris@16 165 {
Chris@16 166 return result_type(modifiers);
Chris@16 167 }
Chris@16 168 };
Chris@16 169
Chris@16 170 // auto_(...)
Chris@16 171 template <typename Modifiers, typename A0>
Chris@16 172 struct make_primitive<
Chris@16 173 terminal_ex<tag::auto_, fusion::vector1<A0> >, Modifiers>
Chris@16 174 {
Chris@16 175 typedef typename add_const<A0>::type const_attribute;
Chris@16 176
Chris@16 177 typedef lit_auto_generator<const_attribute, Modifiers> result_type;
Chris@16 178
Chris@16 179 template <typename Terminal>
Chris@16 180 result_type operator()(Terminal const& term, Modifiers const& modifiers) const
Chris@16 181 {
Chris@16 182 return result_type(fusion::at_c<0>(term.args), modifiers);
Chris@16 183 }
Chris@16 184 };
Chris@16 185
Chris@16 186 }}}
Chris@16 187
Chris@16 188 #endif