Line data Source code
1 : /*============================================================================= 2 : Copyright (c) 2003 Jonathan de Halleux (dehalleux@pelikhan.com) 3 : http://spirit.sourceforge.net/ 4 : 5 : Distributed under the Boost Software License, Version 1.0. (See accompanying 6 : file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 : =============================================================================*/ 8 : #ifndef BOOST_SPIRIT_ACTOR_ASSIGN_ACTOR_HPP 9 : #define BOOST_SPIRIT_ACTOR_ASSIGN_ACTOR_HPP 10 : 11 : #include <boost/spirit/home/classic/namespace.hpp> 12 : #include <boost/spirit/home/classic/actor/ref_value_actor.hpp> 13 : #include <boost/spirit/home/classic/actor/ref_const_ref_actor.hpp> 14 : 15 : namespace boost { namespace spirit { 16 : 17 : BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN 18 : 19 : /////////////////////////////////////////////////////////////////////////// 20 : // Summary: 21 : // A semantic action policy that applies the assignement operator. 22 : // (This doc uses convention available in actors.hpp) 23 : // 24 : // Actions (what it does): 25 : // ref = value; 26 : // ref = T(first,last); 27 : // ref = value_ref; 28 : // 29 : // Policy name: 30 : // assign_action 31 : // 32 : // Policy holder, corresponding helper method: 33 : // ref_value_actor, assign_a( ref ); 34 : // ref_const_ref_actor, assign_a( ref, value_ref ); 35 : // 36 : // () operators: both 37 : // 38 : // See also ref_value_actor and ref_const_ref_actor for more details. 39 : /////////////////////////////////////////////////////////////////////////// 40 : struct assign_action 41 : { 42 : template< 43 : typename T, 44 : typename ValueT 45 : > 46 0 : void act(T& ref_, ValueT const& value_) const 47 : { 48 0 : ref_ = value_; 49 : } 50 : template< 51 : typename T, 52 : typename IteratorT 53 : > 54 : void act( 55 : T& ref_, 56 : IteratorT const& first_, 57 : IteratorT const& last_ 58 : ) const 59 : { 60 : typedef T value_type; 61 : #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS 62 : value_type value(first_,last_); 63 : #else 64 : value_type value; 65 : std::copy(first_, last_, std::inserter(value, value.end())); 66 : #endif 67 : ref_ = value; 68 : } 69 : }; 70 : 71 : // Deprecated. Please use assign_a 72 : template<typename T> 73 : inline ref_value_actor<T,assign_action> assign(T& ref_) 74 : { 75 : return ref_value_actor<T,assign_action>(ref_); 76 : } 77 : 78 : template<typename T> 79 0 : inline ref_value_actor<T,assign_action> assign_a(T& ref_) 80 : { 81 0 : return ref_value_actor<T,assign_action>(ref_); 82 : } 83 : 84 : template< 85 : typename T, 86 : typename ValueT 87 : > 88 : inline ref_const_ref_actor<T,ValueT,assign_action> assign_a( 89 : T& ref_, 90 : ValueT const& value_ 91 : ) 92 : { 93 : return ref_const_ref_actor<T,ValueT,assign_action>(ref_,value_); 94 : } 95 : 96 : BOOST_SPIRIT_CLASSIC_NAMESPACE_END 97 : 98 : }} 99 : 100 : #endif