1 // Copyright 2011 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #include "engine/action.hpp"
30
31 #include "engine/context.hpp"
32 #include "utils/format/macros.hpp"
33
34 namespace fs = utils::fs;
35
36
37 /// Internal implementation of an action.
38 struct engine::action::impl {
39 /// The runtime context of the action.
40 context _context;
41
42 /// Constructor.
43 ///
44 /// \param context_ The runtime context.
implengine::action::impl45 impl(const context& context_) :
46 _context(context_)
47 {
48 }
49
50 /// Equality comparator.
51 ///
52 /// \param other The object to compare to.
53 ///
54 /// \return True if the two objects are equal; false otherwise.
55 bool
operator ==engine::action::impl56 operator==(const impl& other) const
57 {
58 return _context == other._context;
59 }
60 };
61
62
63 /// Constructs a new action.
64 ///
65 /// \param context_ The runtime context in which the action runs.
action(const context & context_)66 engine::action::action(const context& context_) :
67 _pimpl(new impl(context_))
68 {
69 }
70
71
72 /// Destructor.
~action(void)73 engine::action::~action(void)
74 {
75 }
76
77
78 /// Returns the context attached to this action.
79 ///
80 /// \return A reference to the context.
81 const engine::context&
runtime_context(void) const82 engine::action::runtime_context(void) const
83 {
84 return _pimpl->_context;
85 }
86
87
88 /// Equality comparator.
89 ///
90 /// \param other The other object to compare this one to.
91 ///
92 /// \return True if this object and other are equal; false otherwise.
93 bool
operator ==(const action & other) const94 engine::action::operator==(const action& other) const
95 {
96 return *_pimpl == *other._pimpl;
97 }
98
99
100 /// Inequality comparator.
101 ///
102 /// \param other The other object to compare this one to.
103 ///
104 /// \return True if this object and other are different; false otherwise.
105 bool
operator !=(const action & other) const106 engine::action::operator!=(const action& other) const
107 {
108 return !(*this == other);
109 }
110
111
112 /// Injects the object into a stream.
113 ///
114 /// \param output The stream into which to inject the object.
115 /// \param object The object to format.
116 ///
117 /// \return The output stream.
118 std::ostream&
operator <<(std::ostream & output,const action & object)119 engine::operator<<(std::ostream& output, const action& object)
120 {
121 output << F("action{context=%s}") % object.runtime_context();
122 return output;
123 }
124