/* * Action.hpp * Copyright (c) 2014 Eran Pe'er. * * This program is made available under the terms of the MIT License. * * Created on Jun 5, 2014 */ #pragma once #include #include #include #include "mockutils/DefaultValue.hpp" #include "mockutils/Destructible.hpp" #include "fakeit/FakeitExceptions.hpp" namespace fakeit { template struct Action : public Destructible { virtual ~Action() = default; virtual R invoke(arglist &... args) = 0; virtual bool isDone() = 0; }; template struct Repeat : public Action { virtual ~Repeat() = default; Repeat(std::function f) : f(f), times(1) { } Repeat(std::function f, long times) : f(f), times(times) { } virtual R invoke(arglist &... args) override { times--; return f(args...); } virtual bool isDone() override { return times == 0; } private: std::function f; long times; }; template struct RepeatForever : public Action { virtual ~RepeatForever() = default; RepeatForever(std::function f) : f(f) { } virtual R invoke(arglist &... args) override { return f(args...); } virtual bool isDone() override { return false; } private: std::function f; }; template struct ReturnDefaultValue : public Action { virtual ~ReturnDefaultValue() = default; virtual R invoke(arglist &...) override { return DefaultValue::value(); } virtual bool isDone() override { return false; } }; template struct ReturnDelegateValue : public Action { ReturnDelegateValue(std::function delegate) : _delegate(delegate) { } virtual ~ReturnDelegateValue() = default; virtual R invoke(arglist &... args) override { return _delegate(args...); } virtual bool isDone() override { return false; } private: std::function _delegate; }; }