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

Revision 857, 2.1 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_SWAP_ACTOR_HPP
10#define BOOST_SPIRIT_ACTOR_SWAP_ACTOR_HPP
11
12#include <boost/spirit/actor/ref_value_actor.hpp>
13
14namespace boost { namespace spirit {
15
16    ///////////////////////////////////////////////////////////////////////////
17    //  Summary:
18    //  A semantic action policy that swaps values.
19    //  (This doc uses convention available in actors.hpp)
20    //
21    //  Actions (what it does):
22    //      ref.swap( value_ref );
23    //
24    //  Policy name:
25    //      swap_action
26    //
27    //  Policy holder, corresponding helper method:
28    //      ref_value_actor, swap_a( ref );
29    //      ref_const_ref_actor, swap_a( ref, value_ref );
30    //
31    //  () operators: both
32    //
33    //  See also ref_value_actor and ref_const_ref_actor for more details.
34    ///////////////////////////////////////////////////////////////////////////
35    template<
36        typename T
37    >
38    class swap_actor
39    {
40    private:
41        T& ref;
42        T& swap_ref;
43
44    public:
45        swap_actor(
46            T& ref_,
47            T& swap_ref_)
48            : ref(ref_), swap_ref(swap_ref_)
49        {};
50
51        template<typename T2>
52        void operator()(T2 const& /*val*/) const
53        {
54            ref.swap(swap_ref);
55        }
56
57
58        template<typename IteratorT>
59        void operator()(
60            IteratorT const& /*first*/,
61            IteratorT const& /*last*/
62            ) const
63        {
64            ref.swap(swap_ref);
65        }
66    };
67
68    template<
69        typename T
70    >
71    inline swap_actor<T> swap_a(
72        T& ref_,
73        T& swap_ref_
74    )
75    {
76        return swap_actor<T>(ref_,swap_ref_);
77    }
78
79}}
80
81#endif
Note: See TracBrowser for help on using the repository browser.