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

Revision 857, 2.8 KB checked in by igarcia, 19 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_ASSIGN_ACTOR_HPP
10#define BOOST_SPIRIT_ACTOR_ASSIGN_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    //  A semantic action policy that applies the assignement operator.
20    //  (This doc uses convention available in actors.hpp)
21    //
22    //  Actions (what it does):
23    //      ref = value;
24    //      ref = T(first,last);
25    //      ref = value_ref;
26    //
27    //  Policy name:
28    //      assign_action
29    //
30    //  Policy holder, corresponding helper method:
31    //      ref_value_actor, assign_a( ref );
32    //      ref_const_ref_actor, assign_a( ref, value_ref );
33    //
34    //  () operators: both
35    //
36    //  See also ref_value_actor and ref_const_ref_actor for more details.
37    ///////////////////////////////////////////////////////////////////////////
38    struct assign_action
39    {
40        template<
41            typename T,
42            typename ValueT
43        >
44        void act(T& ref_, ValueT const& value_) const
45        {
46            ref_ = value_;
47        }
48        template<
49            typename T,
50            typename IteratorT
51        >
52        void act(
53            T& ref_,
54            IteratorT const& first_,
55            IteratorT const& last_
56            ) const
57        {
58            typedef T value_type;
59#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
60            value_type value(first_,last_);
61#else
62            value_type value;
63            std::copy(first_, last_, std::inserter(value, value.end()));
64#endif
65            ref_ = value;
66        }
67    };
68
69    // Deprecated. Please use assign_a
70    template<typename T>
71    inline ref_value_actor<T,assign_action> assign(T& ref_)
72    {
73        return ref_value_actor<T,assign_action>(ref_);
74    }
75
76    template<typename T>
77    inline ref_value_actor<T,assign_action> assign_a(T& ref_)
78    {
79        return ref_value_actor<T,assign_action>(ref_);
80    }
81
82    template<
83        typename T,
84        typename ValueT
85    >
86    inline ref_const_ref_actor<T,ValueT,assign_action> assign_a(
87        T& ref_,
88        ValueT const& value_
89    )
90    {
91        return ref_const_ref_actor<T,ValueT,assign_action>(ref_,value_);
92    }
93
94}}
95
96#endif
Note: See TracBrowser for help on using the repository browser.