Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:40

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 #if !defined(BOOST_SPIRIT_KARMA_REFERENCE_APR_17_2009_1057PM)
0008 #define BOOST_SPIRIT_KARMA_REFERENCE_APR_17_2009_1057PM
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/spirit/home/karma/meta_compiler.hpp>
0015 #include <boost/spirit/home/karma/generator.hpp>
0016 #include <boost/spirit/home/support/info.hpp>
0017 #include <boost/spirit/home/support/handles_container.hpp>
0018 #include <boost/type_traits/remove_const.hpp>
0019 #include <boost/ref.hpp>
0020 
0021 namespace boost { namespace spirit { namespace karma
0022 {
0023     ///////////////////////////////////////////////////////////////////////////
0024     // reference is a generator that references another generator (its Subject)
0025     ///////////////////////////////////////////////////////////////////////////
0026     template <typename Subject>
0027     struct reference : generator<reference<Subject> >
0028     {
0029         typedef mpl::int_<generator_properties::all_properties> properties;
0030 
0031         typedef Subject subject_type;
0032 
0033         reference(Subject& subject)
0034           : ref(subject) {}
0035 
0036         template <typename Context, typename Unused>
0037         struct attribute : Subject::template attribute<Context, Unused> {};
0038 
0039         // Default overload, used whenever the attribute is not unused and not
0040         // used from an aliased rule.
0041         template <typename OutputIterator, typename Context
0042           , typename Delimiter, typename Attribute>
0043         bool generate(OutputIterator& sink, Context& context
0044           , Delimiter const& delim, Attribute const& attr) const
0045         {
0046             return ref.get().generate(sink, context, delim, attr);
0047         }
0048 
0049         // This overload gets called from an aliased rule only, we take the 
0050         // attribute from the context provided from the wrapper rule.
0051         template <typename OutputIterator, typename Context
0052           , typename Delimiter>
0053         bool generate(OutputIterator& sink, Context& context
0054           , Delimiter const& delim, unused_type) const
0055         {
0056             return ref.get().generate(sink, context, delim, context.attributes);
0057         }
0058 
0059         // This overload is used whenever no attribute is given and it is used
0060         // not from an aliased rule.
0061         template <typename OutputIterator, typename Delimiter>
0062         bool generate(OutputIterator& sink, unused_type
0063           , Delimiter const& delim, unused_type) const
0064         {
0065             return ref.get().generate(sink, unused, delim, unused);
0066         }
0067 
0068         template <typename Context>
0069         info what(Context& context) const
0070         {
0071             // the reference is transparent (does not add any info)
0072             return ref.get().what(context);
0073         }
0074 
0075         boost::reference_wrapper<Subject> ref;
0076     };
0077 }}}
0078 
0079 namespace boost { namespace spirit { namespace traits
0080 {
0081     ///////////////////////////////////////////////////////////////////////////
0082     template <typename Subject, typename Attribute, typename Context
0083       , typename Iterator>
0084     struct handles_container<karma::reference<Subject>, Attribute
0085       , Context, Iterator>
0086       : handles_container<typename remove_const<Subject>::type, Attribute
0087         , Context, Iterator> 
0088     {};
0089 }}}
0090 
0091 #endif