PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/spirit/home/classic/actor/swap_actor.hpp

http://hadesmem.googlecode.com/
C++ Header | 85 lines | 47 code | 12 blank | 26 comment | 0 complexity | edd33005a28f62a5be6384fa110d0a33 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2003 Jonathan de Halleux (dehalleux@pelikhan.com)
 3    http://spirit.sourceforge.net/
 4
 5  Distributed under the Boost Software License, Version 1.0. (See accompanying
 6  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 7=============================================================================*/
 8#ifndef BOOST_SPIRIT_ACTOR_SWAP_ACTOR_HPP
 9#define BOOST_SPIRIT_ACTOR_SWAP_ACTOR_HPP
10
11#include <boost/spirit/home/classic/namespace.hpp>
12#include <boost/spirit/home/classic/actor/ref_value_actor.hpp>
13
14namespace boost { namespace spirit {
15
16BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
17
18    ///////////////////////////////////////////////////////////////////////////
19    //  Summary:
20    //  A semantic action policy that swaps values.
21    //  (This doc uses convention available in actors.hpp)
22    //
23    //  Actions (what it does):
24    //      ref.swap( value_ref );
25    //
26    //  Policy name:
27    //      swap_action
28    //
29    //  Policy holder, corresponding helper method:
30    //      ref_value_actor, swap_a( ref );
31    //      ref_const_ref_actor, swap_a( ref, value_ref );
32    //
33    //  () operators: both
34    //
35    //  See also ref_value_actor and ref_const_ref_actor for more details.
36    ///////////////////////////////////////////////////////////////////////////
37    template<
38        typename T
39    >
40    class swap_actor
41    {
42    private:
43        T& ref;
44        T& swap_ref;
45
46    public:
47        swap_actor(
48            T& ref_,
49            T& swap_ref_)
50            : ref(ref_), swap_ref(swap_ref_)
51        {};
52
53        template<typename T2>
54        void operator()(T2 const& /*val*/) const
55        {
56            ref.swap(swap_ref);
57        }
58
59
60        template<typename IteratorT>
61        void operator()(
62            IteratorT const& /*first*/,
63            IteratorT const& /*last*/
64            ) const
65        {
66            ref.swap(swap_ref);
67        }
68    };
69
70    template<
71        typename T
72    >
73    inline swap_actor<T> swap_a(
74        T& ref_,
75        T& swap_ref_
76    )
77    {
78        return swap_actor<T>(ref_,swap_ref_);
79    }
80
81BOOST_SPIRIT_CLASSIC_NAMESPACE_END
82
83}}
84
85#endif