Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@479 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-07-22 06:52:39 +00:00
parent 4a128a0221
commit cf264cd31e
9 changed files with 75 additions and 98 deletions

View file

@ -27,11 +27,11 @@
<ClInclude Include="..\..\turtle\constraint.hpp" />
<ClInclude Include="..\..\turtle\constraints.hpp" />
<ClInclude Include="..\..\turtle\default_error.hpp" />
<ClInclude Include="..\..\turtle\detail\args.hpp" />
<ClInclude Include="..\..\turtle\detail\child.hpp" />
<ClInclude Include="..\..\turtle\detail\context.hpp" />
<ClInclude Include="..\..\turtle\detail\group.hpp" />
<ClInclude Include="..\..\turtle\detail\lambda.hpp" />
<ClInclude Include="..\..\turtle\detail\parameters.hpp" />
<ClInclude Include="..\..\turtle\detail\parent.hpp" />
<ClInclude Include="..\..\turtle\detail\root.hpp" />
<ClInclude Include="..\..\turtle\detail\signature.hpp" />

View file

@ -70,9 +70,6 @@
<ClInclude Include="..\..\turtle\detail\lambda.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\detail\args.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\detail\child.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
@ -97,5 +94,8 @@
<ClInclude Include="..\..\turtle\detail\yes_no_type.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\detail\parameters.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -22,7 +22,7 @@
<ClInclude Include="..\..\test\mock_error.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\test\detail\test_args.cpp" />
<ClCompile Include="..\..\test\detail\test_parameters.cpp" />
<ClCompile Include="..\..\test\detail\test_signature.cpp" />
<ClCompile Include="..\..\test\detail\test_type_name.cpp" />
<ClCompile Include="..\..\test\test_constraints.cpp" />

View file

@ -51,10 +51,10 @@
<ClCompile Include="..\..\test\detail\test_signature.cpp">
<Filter>Source Files\detail</Filter>
</ClCompile>
<ClCompile Include="..\..\test\detail\test_args.cpp">
<ClCompile Include="..\..\test\detail\test_type_name.cpp">
<Filter>Source Files\detail</Filter>
</ClCompile>
<ClCompile Include="..\..\test\detail\test_type_name.cpp">
<ClCompile Include="..\..\test\detail\test_parameters.cpp">
<Filter>Source Files\detail</Filter>
</ClCompile>
</ItemGroup>

View file

@ -1,20 +0,0 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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)
#include <turtle/detail/args.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::arg< void( float ), 1, 1 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::arg< void( float, int ), 1, 2 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< int, mock::detail::arg< void( float, int ), 2, 2 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float ), 1, 2 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float ), 2, 2 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float, int ), 1, 1 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float, int ), 1, 3 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float, int ), 2, 3 >::type > ));

View file

@ -0,0 +1,15 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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)
#include <turtle/detail/parameters.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::parameters< void( float ), 1 >::at< 0 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::parameters< void( float, int ), 2 >::at< 0 >::type > ));
BOOST_MPL_ASSERT(( boost::is_same< int, mock::detail::parameters< void( float, int ), 2 >::at< 1 >::type > ));

View file

@ -1,69 +0,0 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2010
//
// 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_ARGS_HPP_INCLUDED
#define MOCK_ARGS_HPP_INCLUDED
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/mpl/at.hpp>
namespace mock
{
namespace detail
{
struct invalid_type
{
private:
invalid_type();
};
template< typename S, int n, bool B >
struct arg_imp
{
typedef invalid_type type;
};
template< typename S, int n >
struct arg_imp< S, n, true >
{
typedef BOOST_DEDUCED_TYPENAME
boost::mpl::at_c<
BOOST_DEDUCED_TYPENAME
boost::function_types::parameter_types< S >,
n - 1
>::type type;
};
template< typename S, int n, int N >
struct arg :
arg_imp< S, n, boost::function_types::function_arity< S >::value == N >
{
BOOST_MPL_ASSERT_RELATION( n, >, 0 );
BOOST_MPL_ASSERT_RELATION( n, <=, N );
};
}
} // mock
#define MOCK_ARG(N, n, S, tpn) \
BOOST_PP_COMMA_IF(n) tpn \
mock::detail::arg< S, BOOST_PP_INC(n), N >::type p##n
#define MOCK_ARG_PROXY(z, n, d) \
MOCK_ARG( \
BOOST_PP_ARRAY_ELEM(0, d), \
n, \
BOOST_PP_ARRAY_ELEM(1, d), \
BOOST_PP_ARRAY_ELEM(2, d) )
#define MOCK_ARGS(n, S, tpn) \
BOOST_PP_REPEAT(n, MOCK_ARG_PROXY, (3, (n, S, tpn)))
#define MOCK_DECL(M, n, S, c, tpn) \
tpn boost::function_types::result_type< S >::type M( \
MOCK_ARGS(n, S, tpn) ) c
#endif // MOCK_ARGS_HPP_INCLUDED

View file

@ -0,0 +1,40 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2010
//
// 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_PARAMETERS_HPP_INCLUDED
#define MOCK_PARAMETERS_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 Arity >
struct parameters
{
BOOST_MPL_ASSERT_RELATION( Arity, ==,
boost::function_types::function_arity< Signature >::value );
template< int n >
struct at
{
typedef BOOST_DEDUCED_TYPENAME
boost::mpl::at_c<
BOOST_DEDUCED_TYPENAME
boost::function_types::parameter_types< Signature >,
n
>::type type;
};
};
}
} // mock
#endif // MOCK_PARAMETERS_HPP_INCLUDED

View file

@ -14,7 +14,7 @@
#include "object.hpp"
#include "function.hpp"
#include "detail/type_name.hpp"
#include "detail/args.hpp"
#include "detail/parameters.hpp"
#include "detail/signature.hpp"
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp>
@ -66,6 +66,17 @@ namespace detail
return t##_mock_; \
}
#define MOCK_PARAM(z, n, d) \
BOOST_PP_COMMA_IF(n) d::at< n >::type p##n
#define MOCK_PARAMS(n, S, tpn) \
BOOST_PP_REPEAT(n, MOCK_PARAM, \
tpn mock::detail::parameters< S BOOST_PP_COMMA() n >)
#define MOCK_DECL(M, n, S, c, tpn) \
tpn boost::function_types::result_type< S >::type M( \
MOCK_PARAMS(n, S, tpn) ) c
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
MOCK_DECL(M, n, S, c, tpn) \
{ \
@ -119,7 +130,7 @@ namespace detail
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \
MOCK_FUNCTION_HELPER(void A, t, static) \
T( MOCK_ARGS(n, void A, tpn) ) \
T( MOCK_PARAMS(n, void A, tpn) ) \
{ \
MOCK_HELPER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \
}