Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@516 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-07-22 07:15:34 +00:00
parent 10df4772ef
commit 1698e0f2b3
7 changed files with 86 additions and 42 deletions

39
turtle/detail/functor.hpp Normal file
View file

@ -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

View file

@ -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 <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/mpl/at.hpp>
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

View file

@ -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 <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/at.hpp>
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) )

View file

@ -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();
}

View file

@ -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();
}