From 1698e0f2b36261cf39d5a982c1e18c16b5d6df7c Mon Sep 17 00:00:00 2001 From: mat007 Date: Sun, 22 Jul 2012 07:15:34 +0000 Subject: [PATCH] Refactoring git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@516 860be788-9bd5-4423-9f1e-828f051e677b --- build/vc100/turtle.vcxproj | 2 ++ build/vc100/turtle.vcxproj.filters | 6 +++++ turtle/detail/functor.hpp | 39 +++++++++++++++++++++++++++++ turtle/detail/parameter.hpp | 33 ++++++++++++++++++++++++ turtle/mock.hpp | 40 ++---------------------------- turtle/reset.hpp | 4 +-- turtle/verify.hpp | 4 +-- 7 files changed, 86 insertions(+), 42 deletions(-) create mode 100644 turtle/detail/functor.hpp create mode 100644 turtle/detail/parameter.hpp diff --git a/build/vc100/turtle.vcxproj b/build/vc100/turtle.vcxproj index 0a321cb..a9906d5 100644 --- a/build/vc100/turtle.vcxproj +++ b/build/vc100/turtle.vcxproj @@ -35,12 +35,14 @@ + + diff --git a/build/vc100/turtle.vcxproj.filters b/build/vc100/turtle.vcxproj.filters index d62fb0c..f0de3b3 100644 --- a/build/vc100/turtle.vcxproj.filters +++ b/build/vc100/turtle.vcxproj.filters @@ -124,5 +124,11 @@ Source Files + + Source Files\detail + + + Source Files\detail + \ No newline at end of file diff --git a/turtle/detail/functor.hpp b/turtle/detail/functor.hpp new file mode 100644 index 0000000..a33c768 --- /dev/null +++ b/turtle/detail/functor.hpp @@ -0,0 +1,39 @@ +// http://turtle.sourceforge.net +// +// Copyright Mathieu Champlon 2012 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef MOCK_FUNCTOR_HPP_INCLUDED +#define MOCK_FUNCTOR_HPP_INCLUDED + +#include "detail/function.hpp" + +namespace mock +{ +namespace detail +{ + template< typename Signature > + struct functor : function< Signature > + { + functor() + { + static functor* f = 0; + if( f ) + { + *this = *f; + f = 0; + } + else + f = this; + } + }; +} +} // mock + +#define MOCK_FUNCTOR(f, S) \ + mock::detail::functor< S > f, f##_mock + +#endif // MOCK_FUNCTOR_HPP_INCLUDED diff --git a/turtle/detail/parameter.hpp b/turtle/detail/parameter.hpp new file mode 100644 index 0000000..79350ea --- /dev/null +++ b/turtle/detail/parameter.hpp @@ -0,0 +1,33 @@ +// http://turtle.sourceforge.net +// +// Copyright Mathieu Champlon 2012 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef MOCK_PARAMETER_HPP_INCLUDED +#define MOCK_PARAMETER_HPP_INCLUDED + +#include +#include +#include + +namespace mock +{ +namespace detail +{ + template< typename Signature, int n > + struct parameter + { + typedef BOOST_DEDUCED_TYPENAME + boost::mpl::at_c< + BOOST_DEDUCED_TYPENAME + boost::function_types::parameter_types< Signature >, + n + >::type type; + }; +} +} // mock + +#endif // MOCK_PARAMETER_HPP_INCLUDED diff --git a/turtle/mock.hpp b/turtle/mock.hpp index 8706f71..6793b13 100644 --- a/turtle/mock.hpp +++ b/turtle/mock.hpp @@ -13,56 +13,20 @@ #include "object.hpp" #include "reset.hpp" #include "verify.hpp" +#include "detail/functor.hpp" #include "detail/function.hpp" #include "detail/type_name.hpp" #include "detail/signature.hpp" +#include "detail/parameter.hpp" #include "detail/cleanup.hpp" #include #include -#include -#include #include -#include - -namespace mock -{ -namespace detail -{ - template< typename Signature, int n > - struct parameter - { - typedef BOOST_DEDUCED_TYPENAME - boost::mpl::at_c< - BOOST_DEDUCED_TYPENAME - boost::function_types::parameter_types< Signature >, - n - >::type type; - }; - - template< typename S > - struct functor : mock::detail::function< S > - { - functor() - { - static functor* f = 0; - if( f ) - { - *this = *f; - f = 0; - } - else - f = this; - } - }; -} -} // mock #define MOCK_BASE_CLASS(T, I) \ struct T : I, mock::object, mock::detail::base< I > #define MOCK_CLASS(T) \ struct T : mock::object -#define MOCK_FUNCTOR(f, S) \ - mock::detail::functor< S > f, f##_mock #define MOCK_HELPER(t) \ t##_mock( mock::detail::root, BOOST_PP_STRINGIZE(t) ) diff --git a/turtle/reset.hpp b/turtle/reset.hpp index ddf9a7d..b232237 100644 --- a/turtle/reset.hpp +++ b/turtle/reset.hpp @@ -11,7 +11,7 @@ #include "object.hpp" #include "detail/root.hpp" -#include "detail/function.hpp" +#include "detail/functor.hpp" namespace mock { @@ -24,7 +24,7 @@ namespace mock o.impl_->reset(); } template< typename Signature > - void reset( detail::function< Signature >& f ) + void reset( detail::functor< Signature >& f ) { f.reset(); } diff --git a/turtle/verify.hpp b/turtle/verify.hpp index 060e9a8..c1f9e5f 100644 --- a/turtle/verify.hpp +++ b/turtle/verify.hpp @@ -11,7 +11,7 @@ #include "object.hpp" #include "detail/root.hpp" -#include "detail/function.hpp" +#include "detail/functor.hpp" namespace mock { @@ -24,7 +24,7 @@ namespace mock return o.impl_->verify(); } template< typename Signature > - bool verify( const detail::function< Signature >& f ) + bool verify( const detail::functor< Signature >& f ) { return f.verify(); }