Refactored Impls

This commit is contained in:
Phil Nash
2012-08-07 08:18:48 +01:00
parent 58a26da31e
commit 0477465f8d
7 changed files with 61 additions and 39 deletions

View File

@@ -8,6 +8,8 @@
#ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
#include "catch_interfaces_generators.h"
#include "catch_common.h"
#include <vector>
@@ -16,7 +18,7 @@
namespace Catch {
struct GeneratorInfo {
struct GeneratorInfo : IGeneratorInfo {
GeneratorInfo( std::size_t size )
: m_size( size ),
@@ -41,17 +43,17 @@ namespace Catch {
///////////////////////////////////////////////////////////////////////////
class GeneratorsForTest {
class GeneratorsForTest : public IGeneratorsForTest {
public:
~GeneratorsForTest() {
deleteAll( m_generatorsInOrder );
}
GeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
std::map<std::string, GeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
if( it == m_generatorsByName.end() ) {
GeneratorInfo* info = new GeneratorInfo( size );
IGeneratorInfo* info = new GeneratorInfo( size );
m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
m_generatorsInOrder.push_back( info );
return *info;
@@ -60,8 +62,8 @@ namespace Catch {
}
bool moveNext() {
std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
for(; it != itEnd; ++it ) {
if( (*it)->moveNext() )
return true;
@@ -70,15 +72,15 @@ namespace Catch {
}
private:
std::map<std::string, GeneratorInfo*> m_generatorsByName;
std::vector<GeneratorInfo*> m_generatorsInOrder;
std::map<std::string, IGeneratorInfo*> m_generatorsByName;
std::vector<IGeneratorInfo*> m_generatorsInOrder;
};
IGeneratorsForTest* createGeneratorsForTest()
{
return new GeneratorsForTest();
}
} // end namespace Catch
#define INTERNAL_CATCH_LINESTR2( line ) #line
#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
#endif // TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED