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