/*============================================================================= Copyright (c) 2009 Daniel James Copyright (c) 2002 2004 2006 Joel de Guzman Copyright (c) 2004 Eric Niebler http://spirit.sourceforge.net/ Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #if !defined(BOOST_SPIRIT_QUICKBOOK_AS_STRING_HPP) #define BOOST_SPIRIT_QUICKBOOK_AS_STRING_HPP #include #include #include #include namespace quickbook { namespace spirit = boost::spirit; namespace ph = boost::phoenix; // member_assign - action to assign the attribute to a member of the // rule's attributte. template struct member_assign_type { member_assign_type(Member Struct::*mem_ptr) : mem_ptr_(mem_ptr) {} template void operator()(Member& attrib, Context& context, bool& pass) const { (ph::bind(mem_ptr_, spirit::_val) = attrib)(attrib, context, pass); } template void operator()(Attrib& attrib, Context& context, bool& pass) const { (ph::bind(mem_ptr_, spirit::_val) = attrib)(attrib, context, pass); } Member Struct::*mem_ptr_; }; template struct member_assign_type { member_assign_type(std::string Struct::*mem_ptr) : mem_ptr_(mem_ptr) {} template void operator()(std::string& attrib, Context& context, bool& pass) const { (ph::bind(mem_ptr_, spirit::_val) = attrib)(attrib, context, pass); } template void operator()(Attrib& attrib, Context& context, bool& pass) const { (ph::bind(mem_ptr_, spirit::_val) = std::string(attrib.begin(), attrib.end()))(attrib, context, pass); } std::string Struct::*mem_ptr_; }; template member_assign_type member_assign(Member Struct::*mem_ptr) { return member_assign_type(mem_ptr); } // member_push - action to push the attribute to a member of the // rule's attributte. template struct member_push_type { member_push_type(Member Struct::*mem_ptr) : mem_ptr_(mem_ptr) {} template void operator()(Member& attrib, Context& context, bool& pass) const { ph::bind(mem_ptr_, spirit::_val)(attrib, context, pass) .push_back(attrib); } template void operator()(Attrib& attrib, Context& context, bool& pass) const { ph::bind(mem_ptr_, spirit::_val)(attrib, context, pass) .push_back(typename Member::value_type(attrib)); } Member Struct::*mem_ptr_; }; template struct member_push_type > { member_push_type(std::vector Struct::*mem_ptr) : mem_ptr_(mem_ptr) {} template void operator()(std::string& attrib, Context& context, bool& pass) const { ph::bind(mem_ptr_, spirit::_val)(attrib, context, pass) .push_back(attrib); } template void operator()(Attrib& attrib, Context& context, bool& pass) const { ph::bind(mem_ptr_, spirit::_val)(attrib, context, pass) .push_back(std::string(attrib.begin(), attrib.end())); } std::vector Struct::*mem_ptr_; }; template member_push_type member_push(Member Struct::*mem_ptr) { return member_push_type(mem_ptr); } } #endif