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_INSERT_KEY_ACTOR_HPP
9 #define BOOST_SPIRIT_ACTOR_INSERT_KEY_ACTOR_HPP
10 
11 #include <boost/spirit/home/classic/namespace.hpp>
12 #include <boost/spirit/home/classic/actor/ref_const_ref_value_actor.hpp>
13 
14 namespace boost { namespace spirit {
15 
16 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
17 
18     ///////////////////////////////////////////////////////////////////////////
19     //  Summary:
20     //  A semantic action policy that insert data into an associative
21     //  container using a const reference to data.
22     //  (This doc uses convention available in actors.hpp)
23     //
24     //  Actions (what it does):
25     //      ref.insert( T::value_type(value,value_ref) );
26     //      ref.insert( T::value_type(T::key_type(first,last), value_ref));;
27     //
28     //  Policy name:
29     //      insert_key_action
30     //
31     //  Policy holder, corresponding helper method:
32     //      ref_const_ref_value_actor, insert_key_a( ref, value_ref );
33     //
34     //  () operators: both
35     //
36     //  See also ref_const_ref_value_actor for more details.
37     ///////////////////////////////////////////////////////////////////////////
38     struct insert_key_action
39     {
40         template<
41             typename T,
42             typename ValueT,
43             typename ReferentT
44         >
actboost::spirit::insert_key_action45         void act(
46             T& ref_,
47             ValueT const& value_,
48             ReferentT const& key_
49             ) const
50         {
51             typedef typename T::value_type value_type;
52             value_type key_value(key_, value_);
53             ref_.insert( key_value );
54         }
55 
56         template<
57             typename T,
58             typename ValueT,
59             typename IteratorT
60         >
actboost::spirit::insert_key_action61         void act(
62             T& ref_,
63             ValueT const& value_,
64             IteratorT const& first_,
65             IteratorT const& last_
66             ) const
67         {
68             typedef typename T::key_type key_type;
69             typedef typename T::value_type value_type;
70 
71             key_type key(first_,last_);
72             value_type key_value(key, value_);
73             ref_.insert( key_value );
74         }
75     };
76 
77     template<
78         typename T,
79         typename ValueT
80         >
insert_key_a(T & ref_,ValueT const & value_)81     inline ref_const_ref_value_actor<T,ValueT,insert_key_action> insert_key_a(
82         T& ref_,
83         ValueT const& value_
84         )
85     {
86         return ref_const_ref_value_actor<
87             T,
88             ValueT,
89             insert_key_action
90             >(ref_,value_);
91     }
92 
93 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
94 
95 }}
96 
97 #endif
98