mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Refactoring
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@138 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
1a7fb3dd65
commit
a366578b9e
8 changed files with 136 additions and 114 deletions
|
|
@ -169,7 +169,7 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\libraries\turtle\constraint.hpp"
|
RelativePath="..\..\src\libraries\turtle\constraints.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
|
@ -212,6 +212,10 @@
|
||||||
RelativePath="..\..\src\libraries\turtle\object.hpp"
|
RelativePath="..\..\src\libraries\turtle\object.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\src\libraries\turtle\operators.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\libraries\turtle\placeholder.hpp"
|
RelativePath="..\..\src\libraries\turtle\placeholder.hpp"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@
|
||||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx;h;hpp;hxx;hm;inl;inc;xsd"
|
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx;h;hpp;hxx;hm;inl;inc;xsd"
|
||||||
>
|
>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\tests\turtle_test\constraint_test.cpp"
|
RelativePath="..\..\src\tests\turtle_test\constraints_test.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
#define MOCK_CHECK_HPP_INCLUDED
|
#define MOCK_CHECK_HPP_INCLUDED
|
||||||
|
|
||||||
#include "placeholder.hpp"
|
#include "placeholder.hpp"
|
||||||
#include "constraint.hpp"
|
|
||||||
#include "is_functor.hpp"
|
#include "is_functor.hpp"
|
||||||
|
#include "constraints.hpp"
|
||||||
#include "format.hpp"
|
#include "format.hpp"
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include <boost/utility/enable_if.hpp>
|
||||||
|
|
|
||||||
|
|
@ -6,38 +6,14 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef MOCK_CONSTRAINT_HPP_INCLUDED
|
#ifndef MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||||
#define MOCK_CONSTRAINT_HPP_INCLUDED
|
#define MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||||
|
|
||||||
#include "placeholder.hpp"
|
|
||||||
#include "functional.hpp"
|
#include "functional.hpp"
|
||||||
#include "format.hpp"
|
#include "operators.hpp"
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
template< typename Functor, typename Description >
|
|
||||||
const detail::placeholder< Functor > constraint( const Functor& f,
|
|
||||||
const Description& desc )
|
|
||||||
{
|
|
||||||
std::stringstream s;
|
|
||||||
s << std::boolalpha << desc;
|
|
||||||
return detail::placeholder< Functor >( f, s.str() );
|
|
||||||
}
|
|
||||||
template< typename Functor >
|
|
||||||
const detail::placeholder< Functor > constraint( const Functor& f )
|
|
||||||
{
|
|
||||||
return detail::placeholder< Functor >( f, "?" );
|
|
||||||
}
|
|
||||||
template< typename Functor, typename T >
|
|
||||||
const detail::placeholder< Functor > constraint( const Functor& f,
|
|
||||||
const std::string& name,
|
|
||||||
const T& t )
|
|
||||||
{
|
|
||||||
return detail::placeholder< Functor >( f,
|
|
||||||
name + "( " + format( t ) + " )" );
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template<>
|
template<>
|
||||||
|
|
@ -135,4 +111,4 @@ namespace detail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifndef MOCK_CONSTRAINT_HPP_INCLUDED
|
#endif // #ifndef MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
#include "action.hpp"
|
#include "action.hpp"
|
||||||
#include "sequence.hpp"
|
#include "sequence.hpp"
|
||||||
#include "check.hpp"
|
#include "check.hpp"
|
||||||
#include "constraint.hpp"
|
#include "constraints.hpp"
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
|
|
|
||||||
100
src/libraries/turtle/operators.hpp
Normal file
100
src/libraries/turtle/operators.hpp
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
//
|
||||||
|
// 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_OPERATORS_HPP_INCLUDED
|
||||||
|
#define MOCK_OPERATORS_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "placeholder.hpp"
|
||||||
|
|
||||||
|
namespace mock
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template< typename Functor1, typename Functor2 >
|
||||||
|
class and_
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
and_( const Functor1& f1, const Functor2& f2 )
|
||||||
|
: f1_( f1 )
|
||||||
|
, f2_( f2 )
|
||||||
|
{}
|
||||||
|
template< typename Actual >
|
||||||
|
bool operator()( const Actual& actual ) const
|
||||||
|
{
|
||||||
|
return f1_( actual ) && f2_( actual );
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Functor1 f1_;
|
||||||
|
Functor2 f2_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template< typename Functor1, typename Functor2 >
|
||||||
|
class or_
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
or_( const Functor1& f1, const Functor2& f2 )
|
||||||
|
: f1_( f1 )
|
||||||
|
, f2_( f2 )
|
||||||
|
{}
|
||||||
|
template< typename Actual >
|
||||||
|
bool operator()( const Actual& actual ) const
|
||||||
|
{
|
||||||
|
return f1_( actual ) || f2_( actual );
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Functor1 f1_;
|
||||||
|
Functor2 f2_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template< typename Functor >
|
||||||
|
class not_
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit not_( const Functor& f )
|
||||||
|
: f_( f )
|
||||||
|
{}
|
||||||
|
template< typename Actual >
|
||||||
|
bool operator()( const Actual& actual ) const
|
||||||
|
{
|
||||||
|
return ! f_( actual );
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Functor f_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template< typename Functor1, typename Functor2 >
|
||||||
|
const placeholder< or_< Functor1, Functor2 > >
|
||||||
|
operator||( const placeholder< Functor1 >& lhs,
|
||||||
|
const placeholder< Functor2 >& rhs )
|
||||||
|
{
|
||||||
|
return constraint(
|
||||||
|
or_< Functor1, Functor2 >( lhs.f_, rhs.f_ ),
|
||||||
|
"(" + lhs.desc_ + " || " + rhs.desc_ + ")" );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename Functor1, typename Functor2 >
|
||||||
|
const placeholder< and_< Functor1, Functor2 > >
|
||||||
|
operator&&( const placeholder< Functor1 >& lhs,
|
||||||
|
const placeholder< Functor2 >& rhs )
|
||||||
|
{
|
||||||
|
return constraint(
|
||||||
|
and_< Functor1, Functor2 >( lhs.f_, rhs.f_ ),
|
||||||
|
"(" + lhs.desc_ + " && " + rhs.desc_ + ")" );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename Functor >
|
||||||
|
const placeholder< not_< Functor > >
|
||||||
|
operator!( const placeholder< Functor >& ph )
|
||||||
|
{
|
||||||
|
return constraint(
|
||||||
|
not_< Functor >( ph.f_ ), "! " + ph.desc_ );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifndef MOCK_OPERATORS_HPP_INCLUDED
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#ifndef MOCK_PLACEHOLDER_HPP_INCLUDED
|
#ifndef MOCK_PLACEHOLDER_HPP_INCLUDED
|
||||||
#define MOCK_PLACEHOLDER_HPP_INCLUDED
|
#define MOCK_PLACEHOLDER_HPP_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include "format.hpp"
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
|
|
@ -25,86 +25,28 @@ namespace detail
|
||||||
Functor f_;
|
Functor f_;
|
||||||
std::string desc_;
|
std::string desc_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename Functor1, typename Functor2 >
|
|
||||||
class and_
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
and_( const Functor1& f1, const Functor2& f2 )
|
|
||||||
: f1_( f1 )
|
|
||||||
, f2_( f2 )
|
|
||||||
{}
|
|
||||||
template< typename Actual >
|
|
||||||
bool operator()( const Actual& actual ) const
|
|
||||||
{
|
|
||||||
return f1_( actual ) && f2_( actual );
|
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
Functor1 f1_;
|
|
||||||
Functor2 f2_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template< typename Functor1, typename Functor2 >
|
template< typename Functor, typename Description >
|
||||||
class or_
|
const detail::placeholder< Functor > constraint( const Functor& f,
|
||||||
|
const Description& desc )
|
||||||
{
|
{
|
||||||
public:
|
std::stringstream s;
|
||||||
or_( const Functor1& f1, const Functor2& f2 )
|
s << std::boolalpha << desc;
|
||||||
: f1_( f1 )
|
return detail::placeholder< Functor >( f, s.str() );
|
||||||
, f2_( f2 )
|
|
||||||
{}
|
|
||||||
template< typename Actual >
|
|
||||||
bool operator()( const Actual& actual ) const
|
|
||||||
{
|
|
||||||
return f1_( actual ) || f2_( actual );
|
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
Functor1 f1_;
|
|
||||||
Functor2 f2_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template< typename Functor >
|
template< typename Functor >
|
||||||
class not_
|
const detail::placeholder< Functor > constraint( const Functor& f )
|
||||||
{
|
{
|
||||||
public:
|
return detail::placeholder< Functor >( f, "?" );
|
||||||
explicit not_( const Functor& f )
|
|
||||||
: f_( f )
|
|
||||||
{}
|
|
||||||
template< typename Actual >
|
|
||||||
bool operator()( const Actual& actual ) const
|
|
||||||
{
|
|
||||||
return ! f_( actual );
|
|
||||||
}
|
}
|
||||||
private:
|
template< typename Functor, typename T >
|
||||||
Functor f_;
|
const detail::placeholder< Functor > constraint( const Functor& f,
|
||||||
};
|
const std::string& name,
|
||||||
|
const T& t )
|
||||||
template< typename F1, typename F2 >
|
|
||||||
const placeholder< or_< F1, F2 > >
|
|
||||||
operator||( const placeholder< F1 >& lhs,
|
|
||||||
const placeholder< F2 >& rhs )
|
|
||||||
{
|
{
|
||||||
return placeholder< or_< F1, F2 > >(
|
return detail::placeholder< Functor >( f,
|
||||||
or_< F1, F2 >( lhs.f_, rhs.f_ ),
|
name + "( " + format( t ) + " )" );
|
||||||
"(" + lhs.desc_ + " || " + rhs.desc_ + ")" );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename F1, typename F2 >
|
|
||||||
const placeholder< and_< F1, F2 > >
|
|
||||||
operator&&( const placeholder< F1 >& lhs,
|
|
||||||
const placeholder< F2 >& rhs )
|
|
||||||
{
|
|
||||||
return placeholder< and_< F1, F2 > >(
|
|
||||||
and_< F1, F2 >( lhs.f_, rhs.f_ ),
|
|
||||||
"(" + lhs.desc_ + " && " + rhs.desc_ + ")" );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename F >
|
|
||||||
const placeholder< not_< F > >
|
|
||||||
operator!( const placeholder< F >& ph )
|
|
||||||
{
|
|
||||||
return placeholder< not_< F > >(
|
|
||||||
not_< F >( ph.f_ ), "! " + ph.desc_ );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <turtle/constraint.hpp>
|
#include <turtle/constraints.hpp>
|
||||||
|
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#define BOOST_LIB_NAME boost_unit_test_framework
|
#define BOOST_LIB_NAME boost_unit_test_framework
|
||||||
Loading…
Add table
Add a link
Reference in a new issue