Chris@16: // Copyright (c) 2001-2011 Joel de Guzman Chris@16: // Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #if !defined(BOOST_SPIRIT_KARMA_REFERENCE_APR_17_2009_1057PM) Chris@16: #define BOOST_SPIRIT_KARMA_REFERENCE_APR_17_2009_1057PM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit { namespace karma Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // reference is a generator that references another generator (its Subject) Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct reference : generator > Chris@16: { Chris@16: typedef mpl::int_ properties; Chris@16: Chris@16: typedef Subject subject_type; Chris@16: Chris@16: reference(Subject& subject) Chris@16: : ref(subject) {} Chris@16: Chris@16: template Chris@16: struct attribute : Subject::template attribute {}; Chris@16: Chris@16: // Default overload, used whenever the attribute is not unused and not Chris@16: // used from an aliased rule. Chris@16: template Chris@16: bool generate(OutputIterator& sink, Context& context Chris@16: , Delimiter const& delim, Attribute const& attr) const Chris@16: { Chris@16: return ref.get().generate(sink, context, delim, attr); Chris@16: } Chris@16: Chris@16: // This overload gets called from an aliased rule only, we take the Chris@16: // attribute from the context provided from the wrapper rule. Chris@16: template Chris@16: bool generate(OutputIterator& sink, Context& context Chris@16: , Delimiter const& delim, unused_type) const Chris@16: { Chris@16: return ref.get().generate(sink, context, delim, context.attributes); Chris@16: } Chris@16: Chris@16: // This overload is used whenever no attribute is given and it is used Chris@16: // not from an aliased rule. Chris@16: template Chris@16: bool generate(OutputIterator& sink, unused_type Chris@16: , Delimiter const& delim, unused_type) const Chris@16: { Chris@16: return ref.get().generate(sink, unused, delim, unused); Chris@16: } Chris@16: Chris@16: template Chris@16: info what(Context& context) const Chris@16: { Chris@16: // the reference is transparent (does not add any info) Chris@16: return ref.get().what(context); Chris@16: } Chris@16: Chris@16: boost::reference_wrapper ref; Chris@16: }; Chris@16: }}} Chris@16: Chris@16: namespace boost { namespace spirit { namespace traits Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct handles_container, Attribute Chris@16: , Context, Iterator> Chris@16: : handles_container::type, Attribute Chris@16: , Context, Iterator> Chris@16: {}; Chris@16: }}} Chris@16: Chris@16: #endif