Class ChunkGenerator

Synopsis

#include <include/internal/catch_generators_generic.hpp>

template <typename T>
class ChunkGenerator final : public IGenerator<std::vector<T>>

Description

No description yet.

Mentioned in

Inheritance

Ancestors: IGenerator

Methods

ChunkGenerator
get
next

Source

Lines 190-224 in include/internal/catch_generators_generic.hpp.

template <typename T>
class ChunkGenerator final : public IGenerator<std::vector<T>> {
    std::vector<T> m_chunk;
    size_t m_chunk_size;
    GeneratorWrapper<T> m_generator;
    bool m_used_up = false;
public:
    ChunkGenerator(size_t size, GeneratorWrapper<T> generator) :
        m_chunk_size(size), m_generator(std::move(generator))
    {
        m_chunk.reserve(m_chunk_size);
        if (m_chunk_size != 0) {
            m_chunk.push_back(m_generator.get());
            for (size_t i = 1; i < m_chunk_size; ++i) {
                if (!m_generator.next()) {
                    Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk"));
                }
                m_chunk.push_back(m_generator.get());
            }
        }
    }
    std::vector<T> const& get() const override {
        return m_chunk;
    }
    bool next() override {
        m_chunk.clear();
        for (size_t idx = 0; idx < m_chunk_size; ++idx) {
            if (!m_generator.next()) {
                return false;
            }
            m_chunk.push_back(m_generator.get());
        }
        return true;
    }
};





Add Discussion as Guest

Log in