/* * Copyright (c) 2014 Eran Pe'er. * * This program is made available under the terms of the MIT License. * * Created on Mar 10, 2014 */ #pragma once #include "fakeit/StubbingImpl.hpp" #include "fakeit/StubbingProgress.hpp" #include "fakeit/FakeitContext.hpp" #include "mockutils/smart_ptr.hpp" #include "mockutils/Destructible.hpp" namespace fakeit { class WhenFunctor { struct StubbingChange { friend class WhenFunctor; virtual ~StubbingChange() THROWS { if (std::uncaught_exception()) { return; } _xaction.commit(); } StubbingChange(StubbingChange &other) : _xaction(other._xaction) { } private: StubbingChange(Xaction &xaction) : _xaction(xaction) { } Xaction &_xaction; }; public: template struct MethodProgress : public MethodStubbingProgress { friend class WhenFunctor; virtual ~MethodProgress() override = default; MethodProgress(MethodProgress &other) : _progress(other._progress), _context(other._context) { } MethodProgress(StubbingContext &xaction) : _progress(new StubbingChange(xaction)), _context(xaction) { } protected: virtual MethodStubbingProgress &DoImpl(Action *action) override { _context.appendAction(action); return *this; } private: smart_ptr _progress; StubbingContext &_context; }; WhenFunctor() { } template MethodProgress operator()(const StubbingContext &stubbingContext) { StubbingContext &rootWithoutConst = const_cast &>(stubbingContext); MethodProgress progress(rootWithoutConst); return progress; } }; }