MCPcopy Create free account
hub / github.com/apache/thrift / CompositeGenerator

Class CompositeGenerator

compiler/cpp/tests/catch/catch.hpp:2521–2588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2519
2520template<typename T>
2521class CompositeGenerator {
2522public:
2523 CompositeGenerator() : m_totalSize( 0 ) {}
2524
2525 // *** Move semantics, similar to auto_ptr ***
2526 CompositeGenerator( CompositeGenerator& other )
2527 : m_fileInfo( other.m_fileInfo ),
2528 m_totalSize( 0 )
2529 {
2530 move( other );
2531 }
2532
2533 CompositeGenerator& setFileInfo( const char* fileInfo ) {
2534 m_fileInfo = fileInfo;
2535 return *this;
2536 }
2537
2538 ~CompositeGenerator() {
2539 deleteAll( m_composed );
2540 }
2541
2542 operator T () const {
2543 size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
2544
2545 typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
2546 typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
2547 for( size_t index = 0; it != itEnd; ++it )
2548 {
2549 const IGenerator<T>* generator = *it;
2550 if( overallIndex >= index && overallIndex < index + generator->size() )
2551 {
2552 return generator->getValue( overallIndex-index );
2553 }
2554 index += generator->size();
2555 }
2556 CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
2557 return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so
2558 }
2559
2560 void add( const IGenerator<T>* generator ) {
2561 m_totalSize += generator->size();
2562 m_composed.push_back( generator );
2563 }
2564
2565 CompositeGenerator& then( CompositeGenerator& other ) {
2566 move( other );
2567 return *this;
2568 }
2569
2570 CompositeGenerator& then( T value ) {
2571 ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
2572 valuesGen->add( value );
2573 add( valuesGen );
2574 return *this;
2575 }
2576
2577private:
2578

Callers

nothing calls this directly

Calls 6

getGeneratorIndexMethod · 0.80
getValueMethod · 0.65
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected