Removed dependency to Boost.Phoenix

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@761 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2014-12-13 20:41:15 +00:00
parent 2a88b87682
commit 08a74ccfe3
5 changed files with 25 additions and 50 deletions

View file

@ -123,7 +123,6 @@ The mock object library uses several boost libraries and will adjust some of the
* Boost.Function with BOOST_FUNCTION_MAX_ARGS required at MOCK_MAX_ARGS or higher * Boost.Function with BOOST_FUNCTION_MAX_ARGS required at MOCK_MAX_ARGS or higher
* Boost.FunctionTypes with BOOST_FT_MAX_ARITY required at MOCK_MAX_ARGS + 1 or higher * Boost.FunctionTypes with BOOST_FT_MAX_ARITY required at MOCK_MAX_ARGS + 1 or higher
* Boost.Phoenix (when increasing MOCK_MAX_ARGS over 9 otherwise Boost.Bind is used) with PHOENIX_LIMIT required at MOCK_MAX_ARGS or higher
A compilation error will happen if one of those constants is already defined too low. A compilation error will happen if one of those constants is already defined too low.

View file

@ -22,8 +22,6 @@
#ifndef MOCK_MAX_ARGS #ifndef MOCK_MAX_ARGS
# define MOCK_MAX_ARGS 9 # define MOCK_MAX_ARGS 9
#elif BOOST_PP_LESS(9, MOCK_MAX_ARGS)
# define MOCK_USE_BOOST_PHOENIX
#endif #endif
#ifndef MOCK_MAX_SEQUENCES #ifndef MOCK_MAX_SEQUENCES
@ -42,20 +40,6 @@
# error BOOST_FT_MAX_ARITY must be set to MOCK_MAX_ARGS + 1 or higher # error BOOST_FT_MAX_ARITY must be set to MOCK_MAX_ARGS + 1 or higher
#endif #endif
#ifdef MOCK_USE_BOOST_PHOENIX
# define BOOST_PHOENIX_USE_V2_OVER_V3 // V3 doesn't work due to various bugs including https://svn.boost.org/trac/boost/ticket/8504
# ifndef BOOST_RESULT_OF_NUM_ARGS
# define BOOST_RESULT_OF_NUM_ARGS MOCK_MAX_ARGS
# elif BOOST_PP_LESS(BOOST_RESULT_OF_NUM_ARGS, MOCK_MAX_ARGS)
# error BOOST_RESULT_OF_NUM_ARGS must be set to MOCK_MAX_ARGS or higher
# endif
# ifndef PHOENIX_LIMIT
# define PHOENIX_LIMIT MOCK_MAX_ARGS
# elif BOOST_PP_LESS(PHOENIX_LIMIT, MOCK_MAX_ARGS)
# error PHOENIX_LIMIT must be set to MOCK_MAX_ARGS or higher
# endif
#endif
#if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_NULLPTR) #if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_NULLPTR)
# ifndef MOCK_NO_NULLPTR # ifndef MOCK_NO_NULLPTR
# define MOCK_NULLPTR # define MOCK_NULLPTR

View file

@ -28,13 +28,18 @@ namespace detail
{ {
private: private:
typedef boost::function< Signature > functor_type; typedef boost::function< Signature > functor_type;
typedef lambda< Result, Signature > lambda_type; typedef boost::function< Result() > action_type;
typedef lambda< Result > lambda_type;
public: public:
const functor_type& functor() const const functor_type& functor() const
{ {
return f_; return f_;
} }
const action_type& actionn() const
{
return a_;
}
void calls( const functor_type& f ) void calls( const functor_type& f )
{ {
@ -46,28 +51,27 @@ namespace detail
template< typename Exception > template< typename Exception >
void throws( Exception e ) void throws( Exception e )
{ {
f_ = lambda_type::make_throw( e ); a_ = lambda_type::make_throw( e );
} }
protected: protected:
void set( const functor_type& f ) void set( const action_type& a )
{ {
f_ = f; a_ = a;
} }
template< typename Y > template< typename Y >
void set( const boost::reference_wrapper< Y >& r ) void set( const boost::reference_wrapper< Y >& r )
{ {
f_ = lambda_type::make_ref( r ); a_ = lambda_type::make_ref( r );
} }
functor_type f_; functor_type f_;
action_type a_;
}; };
template< typename Result, typename Signature > template< typename Result, typename Signature >
class action : public action_base< Result, Signature > class action : public action_base< Result, Signature >
{ {
typedef lambda< Result, Signature > lambda_type;
public: public:
template< typename Value > template< typename Value >
void returns( const Value& v ) void returns( const Value& v )
@ -138,7 +142,7 @@ namespace detail
class action< Result*, Signature > class action< Result*, Signature >
: public action_base< Result*, Signature > : public action_base< Result*, Signature >
{ {
typedef lambda< Result*, Signature > lambda_type; typedef lambda< Result* > lambda_type;
public: public:
void returns( Result* r ) void returns( Result* r )
@ -155,7 +159,7 @@ namespace detail
template< typename Signature > template< typename Signature >
class action< void, Signature > : public action_base< void, Signature > class action< void, Signature > : public action_base< void, Signature >
{ {
typedef lambda< void, Signature > lambda_type; typedef lambda< void > lambda_type;
public: public:
action() action()

View file

@ -207,7 +207,7 @@ namespace detail
MOCK_FUNCTION_CONTEXT, it->file(), it->line() ); MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
return error_type::abort(); return error_type::abort();
} }
if( ! it->functor() ) if( ! it->functor() && ! it->actionn() )
{ {
error_type::fail( "missing action", error_type::fail( "missing action",
MOCK_FUNCTION_CONTEXT, it->file(), it->line() ); MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
@ -216,8 +216,10 @@ namespace detail
valid_ = true; valid_ = true;
error_type::call( error_type::call(
MOCK_FUNCTION_CONTEXT, it->file(), it->line() ); MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
return it->functor()( if( it->functor() )
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ); return it->functor()(
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) );
return it->actionn()();
} }
error_type::fail( "unexpected call", MOCK_FUNCTION_CONTEXT ); error_type::fail( "unexpected call", MOCK_FUNCTION_CONTEXT );
return error_type::abort(); return error_type::abort();

View file

@ -10,15 +10,7 @@
#define MOCK_LAMBDA_HPP_INCLUDED #define MOCK_LAMBDA_HPP_INCLUDED
#include "../config.hpp" #include "../config.hpp"
#ifdef MOCK_USE_BOOST_PHOENIX
# ifdef BOOST_PHOENIX_USE_V2_OVER_V3
#include <boost/spirit/home/phoenix/bind.hpp>
# else
#include <boost/phoenix/bind.hpp>
# endif
#else
#include <boost/bind.hpp> #include <boost/bind.hpp>
#endif
#include <boost/move/move.hpp> #include <boost/move/move.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
@ -26,40 +18,34 @@ namespace mock
{ {
namespace detail namespace detail
{ {
#ifdef MOCK_USE_BOOST_PHOENIX template< typename Result >
using boost::phoenix::bind;
#else
using boost::bind;
#endif
template< typename Result, typename Signature >
struct lambda struct lambda
{ {
typedef boost::function< Signature > functor_type; typedef boost::function< Result() > functor_type;
template< typename T > template< typename T >
static functor_type make_val( T t ) static functor_type make_val( T t )
{ {
return detail::bind( &do_val< T >, t ); return boost::bind( &do_val< T >, t );
} }
template< typename T > template< typename T >
static functor_type make_ref( const boost::reference_wrapper< T >& t ) static functor_type make_ref( const boost::reference_wrapper< T >& t )
{ {
return detail::bind( &do_ref< T >, t.get_pointer() ); return boost::bind( &do_ref< T >, t.get_pointer() );
} }
template< typename T > template< typename T >
static functor_type make_move( T& t ) static functor_type make_move( T& t )
{ {
return detail::bind( &do_move< T >, &t ); return boost::bind( &do_move< T >, &t );
} }
template< typename T > template< typename T >
static functor_type make_throw( T t ) static functor_type make_throw( T t )
{ {
return detail::bind( &do_throw< T >, t ); return boost::bind( &do_throw< T >, t );
} }
static functor_type make_nothing() static functor_type make_nothing()
{ {
return detail::bind( &do_nothing ); return boost::bind( &do_nothing );
} }
private: private: