2011-01-28 05:18:23 -05:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2012-08-07 03:18:48 -04:00
|
|
|
#include "catch_interfaces_generators.h"
|
|
|
|
|
2011-01-28 05:18:23 -05:00
|
|
|
#include "catch_common.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
2012-05-16 03:02:20 -04:00
|
|
|
namespace Catch {
|
|
|
|
|
2012-08-07 03:18:48 -04:00
|
|
|
struct GeneratorInfo : IGeneratorInfo {
|
2012-05-16 03:02:20 -04:00
|
|
|
|
|
|
|
GeneratorInfo( std::size_t size )
|
2011-01-28 05:18:23 -05:00
|
|
|
: m_size( size ),
|
|
|
|
m_currentIndex( 0 )
|
2012-05-16 03:02:20 -04:00
|
|
|
{}
|
2011-01-28 05:18:23 -05:00
|
|
|
|
2012-05-16 03:02:20 -04:00
|
|
|
bool moveNext() {
|
|
|
|
if( ++m_currentIndex == m_size ) {
|
2011-01-28 05:18:23 -05:00
|
|
|
m_currentIndex = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-16 03:02:20 -04:00
|
|
|
std::size_t getCurrentIndex() const {
|
2011-01-28 05:18:23 -05:00
|
|
|
return m_currentIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t m_size;
|
|
|
|
std::size_t m_currentIndex;
|
|
|
|
};
|
|
|
|
|
2011-01-28 13:56:26 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-07 03:18:48 -04:00
|
|
|
class GeneratorsForTest : public IGeneratorsForTest {
|
2011-01-28 05:18:23 -05:00
|
|
|
|
|
|
|
public:
|
2012-05-16 03:02:20 -04:00
|
|
|
~GeneratorsForTest() {
|
2011-01-28 05:18:23 -05:00
|
|
|
deleteAll( m_generatorsInOrder );
|
|
|
|
}
|
|
|
|
|
2012-08-07 03:18:48 -04:00
|
|
|
IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
|
|
|
|
std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
|
2012-05-16 03:02:20 -04:00
|
|
|
if( it == m_generatorsByName.end() ) {
|
2012-08-07 03:18:48 -04:00
|
|
|
IGeneratorInfo* info = new GeneratorInfo( size );
|
2011-01-28 05:18:23 -05:00
|
|
|
m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
|
|
|
|
m_generatorsInOrder.push_back( info );
|
|
|
|
return *info;
|
|
|
|
}
|
|
|
|
return *it->second;
|
|
|
|
}
|
|
|
|
|
2012-05-16 03:02:20 -04:00
|
|
|
bool moveNext() {
|
2012-08-07 03:18:48 -04:00
|
|
|
std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
|
|
|
|
std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
|
2012-05-16 03:02:20 -04:00
|
|
|
for(; it != itEnd; ++it ) {
|
2011-01-28 05:18:23 -05:00
|
|
|
if( (*it)->moveNext() )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-07 03:18:48 -04:00
|
|
|
std::map<std::string, IGeneratorInfo*> m_generatorsByName;
|
|
|
|
std::vector<IGeneratorInfo*> m_generatorsInOrder;
|
2011-01-28 05:18:23 -05:00
|
|
|
};
|
|
|
|
|
2012-08-07 03:18:48 -04:00
|
|
|
IGeneratorsForTest* createGeneratorsForTest()
|
|
|
|
{
|
|
|
|
return new GeneratorsForTest();
|
|
|
|
}
|
2011-01-28 05:18:23 -05:00
|
|
|
|
2012-08-07 03:18:48 -04:00
|
|
|
} // end namespace Catch
|
2011-01-28 05:18:23 -05:00
|
|
|
|
2012-09-17 01:42:29 -04:00
|
|
|
#endif // TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|