source: NonGTP/Boost/boost/spirit/actor/push_front_actor.hpp @ 857

Revision 857, 2.7 KB checked in by igarcia, 18 years ago (diff)
Line 
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_FRONT_ACTOR_HPP
10#define BOOST_SPIRIT_ACTOR_PUSH_FRONT_ACTOR_HPP
11
12#include <boost/spirit/actor/ref_value_actor.hpp>
13#include <boost/spirit/actor/ref_const_ref_actor.hpp>
14
15namespace boost { namespace spirit {
16
17    ///////////////////////////////////////////////////////////////////////////
18    //  Summary:
19    //
20    //  A semantic action policy that appends a value to the front 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_front( value );
26    //      ref.push_front( T::value_type(first,last) );
27    //      ref.push_front( value_ref );
28    //
29    //  Policy name:
30    //      push_front_action
31    //
32    //  Policy holder, corresponding helper method:
33    //      ref_value_actor, push_front_a( ref );
34    //      ref_const_ref_actor, push_front_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_front_action
41    {
42        template<
43            typename T,
44            typename ValueT
45        >
46        void act(T& ref_, ValueT const& value_) const
47        {
48            ref_.push_front( 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_front( value );
64        }
65    };
66
67    template<typename T>
68    inline ref_value_actor<T,push_front_action> push_front_a(T& ref_)
69    {
70        return ref_value_actor<T,push_front_action>(ref_);
71    }
72
73    template<
74        typename T,
75        typename ValueT
76    >
77    inline ref_const_ref_actor<T,ValueT,push_front_action> push_front_a(
78        T& ref_,
79        ValueT const& value_
80    )
81    {
82        return ref_const_ref_actor<T,ValueT,push_front_action>(ref_,value_);
83    }
84
85}}
86
87#endif
Note: See TracBrowser for help on using the repository browser.