File indexing completed on 2024-09-22 04:53:10

0001 /*
0002  * SPDX-FileCopyrightText: 2008 Trevor Pounds
0003  * SPDX-License-Identifier: MIT
0004  */
0005 
0006 #ifndef __MOCKITOPP_ACTION_HPP__
0007 #define __MOCKITOPP_ACTION_HPP__
0008 
0009 namespace mockitopp
0010 {
0011    namespace detail
0012    {
0013       template <typename R>
0014       struct action
0015       {
0016          virtual R invoke() = 0;
0017 
0018          virtual ~action() {}
0019       };
0020 
0021       template <typename R>
0022       struct returnable_action : public action<R>
0023       {
0024          R _returnable;
0025 
0026          returnable_action(const R& returnable)
0027             : _returnable(returnable)
0028             {}
0029 
0030          R invoke() override { return _returnable; }
0031       };
0032 
0033       template <>
0034       struct returnable_action<void> : public action<void>
0035       {
0036          void invoke() override {}
0037       };
0038 
0039       template <typename R, typename T>
0040       struct throwable_action : public action<R>
0041       {
0042          T _throwable;
0043 
0044          throwable_action(const T& throwable)
0045             : _throwable(throwable)
0046             {}
0047 
0048          R invoke() override { throw _throwable; }
0049       };
0050    } // namespace detail
0051 } // namespace mockitopp
0052 
0053 #endif //__MOCKITOPP_ACTION_HPP__