Extracted generator impl code out of Hub

This commit is contained in:
Phil Nash 2011-01-28 10:18:23 +00:00
parent fe67902de1
commit bf4a4312b4
3 changed files with 113 additions and 78 deletions

View File

@ -42,6 +42,7 @@
4A3BFFF0128DD23C005609E3 /* catch_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_config.hpp; path = ../internal/catch_config.hpp; sourceTree = SOURCE_ROOT; };
4A6D514B12C8A547008F0415 /* catch_debugger.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_debugger.hpp; path = ../internal/catch_debugger.hpp; sourceTree = SOURCE_ROOT; };
4A8A68FF12F1F75100ACED26 /* catch_generators.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_generators.hpp; path = ../internal/catch_generators.hpp; sourceTree = SOURCE_ROOT; };
4A8A698812F2CDA100ACED26 /* catch_generators_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_generators_impl.hpp; path = ../internal/catch_generators_impl.hpp; sourceTree = SOURCE_ROOT; };
4A992A6512B2156C002B7B66 /* catch_xmlwriter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_xmlwriter.hpp; path = ../internal/catch_xmlwriter.hpp; sourceTree = SOURCE_ROOT; };
4A992A6612B21582002B7B66 /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_junit.hpp; path = ../catch_reporter_junit.hpp; sourceTree = SOURCE_ROOT; };
4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
@ -144,6 +145,7 @@
4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */,
4A33BCE512CE7F500052A211 /* catch_hub.h */,
4A33BF0D12CEAC0C0052A211 /* catch_hub_impl.hpp */,
4A8A698812F2CDA100ACED26 /* catch_generators_impl.hpp */,
);
name = Hub;
sourceTree = "<group>";

View File

@ -0,0 +1,110 @@
/*
* catch_generators_impl.hpp
* Catch
*
* Created by Phil on 28/01/2011.
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
*
* 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 TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
#include "catch_common.h"
#include <vector>
#include <string>
#include <map>
namespace Catch
{
struct GeneratorInfo
{
GeneratorInfo
(
std::size_t size
)
: m_size( size ),
m_currentIndex( 0 )
{
}
bool moveNext
()
{
if( ++m_currentIndex == m_size )
{
m_currentIndex = 0;
return false;
}
return true;
}
std::size_t getCurrentIndex
()
const
{
return m_currentIndex;
}
std::size_t m_size;
std::size_t m_currentIndex;
};
class GeneratorsForTest
{
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 );
if( it == m_generatorsByName.end() )
{
GeneratorInfo* info = new GeneratorInfo( size );
m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
m_generatorsInOrder.push_back( info );
return *info;
}
return *it->second;
}
bool moveNext
()
{
std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
for(; it != itEnd; ++it )
{
if( (*it)->moveNext() )
return true;
}
return false;
}
private:
std::map<std::string, GeneratorInfo*> m_generatorsByName;
std::vector<GeneratorInfo*> m_generatorsInOrder;
};
} // 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

View File

@ -13,6 +13,7 @@
#include "catch_reporter_registry.hpp"
#include "catch_test_case_registry_impl.hpp"
#include "catch_runner_impl.hpp"
#include "catch_generators_impl.hpp"
#include "catch_stream.hpp"
namespace Catch
@ -85,84 +86,6 @@ namespace Catch
throw std::domain_error( "Unknown stream: " + streamName );
}
struct GeneratorInfo
{
GeneratorInfo
(
std::size_t size
)
: m_size( size ),
m_currentIndex( 0 )
{
}
bool moveNext
()
{
if( ++m_currentIndex == m_size )
{
m_currentIndex = 0;
return false;
}
return true;
}
std::size_t getCurrentIndex
()
const
{
return m_currentIndex;
}
std::size_t m_size;
std::size_t m_currentIndex;
};
class GeneratorsForTest
{
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 );
if( it == m_generatorsByName.end() )
{
GeneratorInfo* info = new GeneratorInfo( size );
m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
m_generatorsInOrder.push_back( info );
return *info;
}
return *it->second;
}
bool moveNext
()
{
std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
for(; it != itEnd; ++it )
{
if( (*it)->moveNext() )
return true;
}
return false;
}
private:
std::map<std::string, GeneratorInfo*> m_generatorsByName;
std::vector<GeneratorInfo*> m_generatorsInOrder;
};
///////////////////////////////////////////////////////////////////////////
GeneratorsForTest* Hub::findGeneratorsForCurrentTest
()