1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// Defines generic interface for monomorphic dataset based on generator
10 // ***************************************************************************
12 #ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
13 #define BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/monomorphic/fwd.hpp>
19 #include <boost/test/detail/suppress_warnings.hpp>
21 //____________________________________________________________________________//
26 namespace monomorphic {
28 // ************************************************************************** //
29 // ************** generated_by ************** //
30 // ************************************************************************** //
32 /*!@brief Generators interface
34 * This class implements the dataset concept over a generator. Examples of generators are:
38 * The generator concept is the following:
39 * - the type of the generated samples is given by field @c sample
40 * - the member function @c capacity should return the size of the collection being generated (potentially infinite)
41 * - the member function @c next should change the state of the generator to the next generated value
42 * - the member function @c reset should put the state of the object in the same state as right after its instanciation
44 template<typename Generator>
47 typedef typename Generator::sample sample;
53 explicit iterator( Generator& gen )
56 if(m_gen->capacity() > 0) {
62 // forward iterator interface
63 sample const& operator*() const { return m_curr_sample; }
64 void operator++() { m_curr_sample = m_gen->next(); }
72 typedef Generator generator_type;
75 explicit generated_by( Generator&& G )
76 : m_generator( std::forward<Generator>(G) )
80 generated_by( generated_by&& rhs )
81 : m_generator( std::forward<Generator>(rhs.m_generator) )
84 //! Size of the underlying dataset
85 data::size_t size() const { return m_generator.capacity(); }
87 //! Iterator on the beginning of the dataset
88 iterator begin() const { return iterator( boost::ref(const_cast<Generator&>(m_generator)) ); }
92 Generator m_generator;
95 //____________________________________________________________________________//
97 //! A generated dataset is a dataset.
98 template<typename Generator>
99 struct is_dataset<generated_by<Generator>> : mpl::true_ {};
101 } // namespace monomorphic
103 } // namespace unit_test
106 #include <boost/test/detail/enable_warnings.hpp>
108 #endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER