/** * @file spirit_actors.h * * @brief Additional actors for the wrap parser * * @date Dec 8, 2011 * @author Alex Cunningham */ #pragma once #include #include namespace boost { namespace spirit { BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////// // Summary: // A semantic action policy that calls pop_back method. // (This doc uses convention available in actors.hpp) // Note that this action performs a "safe" pop, that checks the size // before popping to avoid segfaults // // Actions (what it does): // ref.pop_back(); // // Policy name: // pop_action // // Policy holder, corresponding helper method: // ref_actor, clear_a( ref ); // // () operators: both. // // See also ref_actor for more details. /////////////////////////////////////////////////////////////////////////// struct pop_action { template< typename T> void act(T& ref_) const { if (!ref_.empty()) ref_.pop_back(); } }; /////////////////////////////////////////////////////////////////////////// // helper method that creates a and_assign_actor. /////////////////////////////////////////////////////////////////////////// template inline ref_actor pop_a(T& ref_) { return ref_actor(ref_); } /////////////////////////////////////////////////////////////////////////// // Summary: // // A semantic action policy that appends a set of values to the back of a // container. // (This doc uses convention available in actors.hpp) // // Actions (what it does and what ref, value_ref must support): // ref.push_back( values ); // ref.push_back( T::value_type(first,last) ); // ref.push_back( value_ref ); // // Policy name: // append_action // // Policy holder, corresponding helper method: // ref_value_actor, append_a( ref ); // ref_const_ref_actor, append_a( ref, value_ref ); // // () operators: both // // See also ref_value_actor and ref_const_ref_actor for more details. /////////////////////////////////////////////////////////////////////////// struct append_action { template< typename T, typename ValueT > void act(T& ref_, ValueT const& value_) const { ref_.insert(ref_.begin(), value_.begin(), value_.end()); } template void act( T& ref_, IteratorT const& first_, IteratorT const& last_ ) const { ref_.insert(ref_.end(), first_, last_); } }; template inline ref_value_actor append_a(T& ref_) { return ref_value_actor(ref_); } template inline ref_const_ref_actor append_a( T& ref_, ValueT const& value_ ) { return ref_const_ref_actor(ref_,value_); } BOOST_SPIRIT_CLASSIC_NAMESPACE_END } }