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/core/ref.hpp>
21 #include <boost/test/detail/suppress_warnings.hpp>
23 //____________________________________________________________________________//
28 namespace monomorphic {
30 // ************************************************************************** //
31 // ************** generated_by ************** //
32 // ************************************************************************** //
34 /*!@brief Generators interface
36 * This class implements the dataset concept over a generator. Examples of generators are:
40 * The generator concept is the following:
41 * - the type of the generated samples is given by field @c sample
42 * - the member function @c capacity should return the size of the collection being generated (potentially infinite)
43 * - the member function @c next should change the state of the generator to the next generated value
44 * - the member function @c reset should put the state of the object in the same state as right after its instanciation
46 template<typename Generator>
49 typedef typename Generator::sample sample;
55 explicit iterator( Generator& gen )
58 if(m_gen->capacity() > 0) {
64 // forward iterator interface
65 sample const& operator*() const { return m_curr_sample; }
66 void operator++() { m_curr_sample = m_gen->next(); }
74 typedef Generator generator_type;
77 explicit generated_by( Generator&& G )
78 : m_generator( std::forward<Generator>(G) )
82 generated_by( generated_by&& rhs )
83 : m_generator( std::forward<Generator>(rhs.m_generator) )
86 //! Size of the underlying dataset
87 data::size_t size() const { return m_generator.capacity(); }
89 //! Iterator on the beginning of the dataset
90 iterator begin() const { return iterator( boost::ref(const_cast<Generator&>(m_generator)) ); }
94 Generator m_generator;
97 //____________________________________________________________________________//
99 //! A generated dataset is a dataset.
100 template<typename Generator>
101 struct is_dataset<generated_by<Generator>> : mpl::true_ {};
103 } // namespace monomorphic
105 } // namespace unit_test
108 #include <boost/test/detail/enable_warnings.hpp>
110 #endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER