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_PUSH_BACK_ACTOR_HPP
|
---|
10 | #define BOOST_SPIRIT_ACTOR_PUSH_BACK_ACTOR_HPP
|
---|
11 |
|
---|
12 | #include <boost/spirit/actor/ref_value_actor.hpp>
|
---|
13 | #include <boost/spirit/actor/ref_const_ref_actor.hpp>
|
---|
14 |
|
---|
15 | namespace boost { namespace spirit {
|
---|
16 |
|
---|
17 | ///////////////////////////////////////////////////////////////////////////
|
---|
18 | // Summary:
|
---|
19 | //
|
---|
20 | // A semantic action policy that appends a value to the back of a
|
---|
21 | // container.
|
---|
22 | // (This doc uses convention available in actors.hpp)
|
---|
23 | //
|
---|
24 | // Actions (what it does and what ref, value_ref must support):
|
---|
25 | // ref.push_back( value );
|
---|
26 | // ref.push_back( T::value_type(first,last) );
|
---|
27 | // ref.push_back( value_ref );
|
---|
28 | //
|
---|
29 | // Policy name:
|
---|
30 | // push_back_action
|
---|
31 | //
|
---|
32 | // Policy holder, corresponding helper method:
|
---|
33 | // ref_value_actor, push_back_a( ref );
|
---|
34 | // ref_const_ref_actor, push_back_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 push_back_action
|
---|
41 | {
|
---|
42 | template<
|
---|
43 | typename T,
|
---|
44 | typename ValueT
|
---|
45 | >
|
---|
46 | void act(T& ref_, ValueT const& value_) const
|
---|
47 | {
|
---|
48 | ref_.push_back( 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 typename T::value_type value_type;
|
---|
61 | value_type value(first_,last_);
|
---|
62 |
|
---|
63 | ref_.push_back( value );
|
---|
64 | }
|
---|
65 | };
|
---|
66 |
|
---|
67 | // Deprecated interface. Use push_back_a
|
---|
68 | template<typename T>
|
---|
69 | inline ref_value_actor<T,push_back_action>
|
---|
70 | append(T& ref_)
|
---|
71 | {
|
---|
72 | return ref_value_actor<T,push_back_action>(ref_);
|
---|
73 | }
|
---|
74 |
|
---|
75 | template<typename T>
|
---|
76 | inline ref_value_actor<T,push_back_action>
|
---|
77 | push_back_a(T& ref_)
|
---|
78 | {
|
---|
79 | return ref_value_actor<T,push_back_action>(ref_);
|
---|
80 | }
|
---|
81 |
|
---|
82 | template<
|
---|
83 | typename T,
|
---|
84 | typename ValueT
|
---|
85 | >
|
---|
86 | inline ref_const_ref_actor<T,ValueT,push_back_action>
|
---|
87 | push_back_a(
|
---|
88 | T& ref_,
|
---|
89 | ValueT const& value_
|
---|
90 | )
|
---|
91 | {
|
---|
92 | return ref_const_ref_actor<T,ValueT,push_back_action>(ref_,value_);
|
---|
93 | }
|
---|
94 |
|
---|
95 | }}
|
---|
96 |
|
---|
97 | #endif
|
---|