[857] | 1 | /*=============================================================================
|
---|
| 2 | Copyright (c) 2003 Jonathan de Halleux (dehalleux@pelikhan.com)
|
---|
| 3 | http://spirit.sourceforge.net/
|
---|
| 4 |
|
---|
| 5 | Use, modification and distribution is subject to the Boost Software
|
---|
| 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
| 7 | http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 8 | =============================================================================*/
|
---|
| 9 | #ifndef BOOST_SPIRIT_ACTOR_INSERT_KEY_ACTOR_HPP
|
---|
| 10 | #define BOOST_SPIRIT_ACTOR_INSERT_KEY_ACTOR_HPP
|
---|
| 11 |
|
---|
| 12 | #include <boost/spirit/actor/ref_const_ref_value_actor.hpp>
|
---|
| 13 |
|
---|
| 14 | namespace boost { namespace spirit {
|
---|
| 15 |
|
---|
| 16 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 17 | // Summary:
|
---|
| 18 | // A semantic action policy that insert data into an associative
|
---|
| 19 | // container using a const reference to data.
|
---|
| 20 | // (This doc uses convention available in actors.hpp)
|
---|
| 21 | //
|
---|
| 22 | // Actions (what it does):
|
---|
| 23 | // ref.insert( T::value_type(value,value_ref) );
|
---|
| 24 | // ref.insert( T::value_type(T::key_type(first,last), value_ref));;
|
---|
| 25 | //
|
---|
| 26 | // Policy name:
|
---|
| 27 | // insert_key_action
|
---|
| 28 | //
|
---|
| 29 | // Policy holder, corresponding helper method:
|
---|
| 30 | // ref_const_ref_value_actor, insert_key_a( ref, value_ref );
|
---|
| 31 | //
|
---|
| 32 | // () operators: both
|
---|
| 33 | //
|
---|
| 34 | // See also ref_const_ref_value_actor for more details.
|
---|
| 35 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 36 | struct insert_key_action
|
---|
| 37 | {
|
---|
| 38 | template<
|
---|
| 39 | typename T,
|
---|
| 40 | typename ValueT,
|
---|
| 41 | typename ReferentT
|
---|
| 42 | >
|
---|
| 43 | void act(
|
---|
| 44 | T& ref_,
|
---|
| 45 | ValueT const& value_,
|
---|
| 46 | ReferentT const& key_
|
---|
| 47 | ) const
|
---|
| 48 | {
|
---|
| 49 | typedef typename T::value_type value_type;
|
---|
| 50 | value_type key_value(key_, value_);
|
---|
| 51 | ref_.insert( key_value );
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | template<
|
---|
| 55 | typename T,
|
---|
| 56 | typename ValueT,
|
---|
| 57 | typename IteratorT
|
---|
| 58 | >
|
---|
| 59 | void act(
|
---|
| 60 | T& ref_,
|
---|
| 61 | ValueT const& value_,
|
---|
| 62 | IteratorT const& first_,
|
---|
| 63 | IteratorT const& last_
|
---|
| 64 | ) const
|
---|
| 65 | {
|
---|
| 66 | typedef typename T::key_type key_type;
|
---|
| 67 | typedef typename T::value_type value_type;
|
---|
| 68 |
|
---|
| 69 | key_type key(first_,last_);
|
---|
| 70 | value_type key_value(key, value_);
|
---|
| 71 | ref_.insert( key_value );
|
---|
| 72 | }
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | template<
|
---|
| 76 | typename T,
|
---|
| 77 | typename ValueT
|
---|
| 78 | >
|
---|
| 79 | inline ref_const_ref_value_actor<T,ValueT,insert_key_action> insert_key_a(
|
---|
| 80 | T& ref_,
|
---|
| 81 | ValueT const& value_
|
---|
| 82 | )
|
---|
| 83 | {
|
---|
| 84 | return ref_const_ref_value_actor<
|
---|
| 85 | T,
|
---|
| 86 | ValueT,
|
---|
| 87 | insert_key_action
|
---|
| 88 | >(ref_,value_);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | }}
|
---|
| 92 |
|
---|
| 93 | #endif
|
---|