Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@136 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2010-03-02 22:44:23 +00:00
parent 3109a228f0
commit 8a34752a83
6 changed files with 35 additions and 33 deletions

View file

@ -212,10 +212,6 @@
RelativePath="..\..\src\libraries\turtle\object.hpp"
>
</File>
<File
RelativePath="..\..\src\libraries\turtle\orderable.hpp"
>
</File>
<File
RelativePath="..\..\src\libraries\turtle\placeholder.hpp"
>
@ -228,6 +224,10 @@
RelativePath="..\..\src\libraries\turtle\sequence.hpp"
>
</File>
<File
RelativePath="..\..\src\libraries\turtle\sequenceable.hpp"
>
</File>
<File
RelativePath="..\..\src\libraries\turtle\type_name.hpp"
>

View file

@ -52,6 +52,7 @@
ProgramDataBaseFileName="$(IntDir)/$(ProjectName).pdb"
WarningLevel="4"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
@ -135,6 +136,7 @@
ProgramDataBaseFileName="$(IntDir)/$(ProjectName).pdb"
WarningLevel="4"
SuppressStartupBanner="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool

View file

@ -28,7 +28,7 @@ namespace mock
{
namespace detail
{
class expectation_base : private orderable
class expectation_base : private sequenceable
{
public:
expectation_base()

View file

@ -35,6 +35,7 @@ namespace detail
virtual bool is_valid() const = 0;
// Verify invocation
// returns false if the verification fails
virtual bool verify() const = 0;
friend inline std::ostream& operator<<( std::ostream& s, const invocation& i )

View file

@ -9,7 +9,7 @@
#ifndef MOCK_SEQUENCE_HPP_INCLUDED
#define MOCK_SEQUENCE_HPP_INCLUDED
#include "orderable.hpp"
#include "sequenceable.hpp"
#include <vector>
#include <algorithm>
@ -20,50 +20,49 @@ namespace mock
public:
~sequence()
{
for( elements_it it = elements_.begin();
it != elements_.end(); ++it )
for( orderables_it it = orderables_.begin();
it != orderables_.end(); ++it )
(*it)->remove( *this );
for( elements_it it = called_.begin();
for( orderables_it it = called_.begin();
it != called_.end(); ++it )
(*it)->remove( *this );
}
void add( detail::orderable& e )
void add( detail::sequenceable& o )
{
elements_.push_back( &e );
orderables_.push_back( &o );
}
void remove( detail::orderable& e )
void remove( detail::sequenceable& o )
{
elements_.erase( std::remove( elements_.begin(),
elements_.end(), &e ), elements_.end() );
orderables_.erase( std::remove( orderables_.begin(),
orderables_.end(), &o ), orderables_.end() );
called_.erase( std::remove( called_.begin(),
called_.end(), &e ), called_.end() );
called_.end(), &o ), called_.end() );
}
bool is_valid( const detail::orderable& e ) const
bool is_valid( const detail::sequenceable& o ) const
{
return std::find( called_.begin(), called_.end(), &e )
return std::find( called_.begin(), called_.end(), &o )
== called_.end();
}
void call( const detail::orderable& e )
void call( const detail::sequenceable& o )
{
elements_it it =
std::find( elements_.begin(), elements_.end(), &e );
if( it != elements_.end() )
orderables_it it =
std::find( orderables_.begin(), orderables_.end(), &o );
if( it != orderables_.end() )
{
std::copy( elements_.begin(), it,
std::copy( orderables_.begin(), it,
std::back_inserter( called_ ) );
elements_.erase( elements_.begin(), it );
orderables_.erase( orderables_.begin(), it );
}
}
private:
typedef std::vector< detail::orderable* > elements_type;
typedef elements_type::iterator elements_it;
typedef std::vector< detail::sequenceable* > orderables_type;
typedef orderables_type::iterator orderables_it;
elements_type elements_;
elements_type called_;
orderables_type orderables_, called_;
};
}

View file

@ -6,8 +6,8 @@
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MOCK_ORDERABLE_HPP_INCLUDED
#define MOCK_ORDERABLE_HPP_INCLUDED
#ifndef MOCK_SEQUENCEABLE_HPP_INCLUDED
#define MOCK_SEQUENCEABLE_HPP_INCLUDED
namespace mock
{
@ -15,11 +15,11 @@ namespace mock
namespace detail
{
class orderable
class sequenceable
{
public:
orderable() {}
virtual ~orderable() {}
sequenceable() {}
virtual ~sequenceable() {}
virtual void remove( sequence& s ) = 0;
};
@ -27,4 +27,4 @@ namespace detail
}
#endif // #ifndef MOCK_ORDERABLE_HPP_INCLUDED
#endif // #ifndef MOCK_SEQUENCEABLE_HPP_INCLUDED