]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/include/boost/test/data/monomorphic/generate.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / test / include / boost / test / data / monomorphic / generate.hpp
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)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 /// @file
9 /// Defines generic interface for monomorphic dataset based on generator
10 // ***************************************************************************
11
12 #ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
13 #define BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
14
15 // Boost.Test
16 #include <boost/test/data/config.hpp>
17 #include <boost/test/data/monomorphic/fwd.hpp>
18
19 #include <boost/test/detail/suppress_warnings.hpp>
20
21 //____________________________________________________________________________//
22
23 namespace boost {
24 namespace unit_test {
25 namespace data {
26 namespace monomorphic {
27
28 // ************************************************************************** //
29 // ************** generated_by ************** //
30 // ************************************************************************** //
31
32 /*!@brief Generators interface
33 *
34 * This class implements the dataset concept over a generator. Examples of generators are:
35 * - xrange_t
36 * - random_t
37 *
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
43 */
44 template<typename Generator>
45 class generated_by {
46 public:
47 typedef typename Generator::sample sample;
48
49 enum { arity = 1 };
50
51 struct iterator {
52 // Constructor
53 explicit iterator( Generator& gen )
54 : m_gen( &gen )
55 {
56 if(m_gen->capacity() > 0) {
57 m_gen->reset();
58 ++*this;
59 }
60 }
61
62 // forward iterator interface
63 sample const& operator*() const { return m_curr_sample; }
64 void operator++() { m_curr_sample = m_gen->next(); }
65
66 private:
67 // Data members
68 Generator* m_gen;
69 sample m_curr_sample;
70 };
71
72 typedef Generator generator_type;
73
74 // Constructor
75 explicit generated_by( Generator&& G )
76 : m_generator( std::forward<Generator>(G) )
77 {}
78
79 // Move constructor
80 generated_by( generated_by&& rhs )
81 : m_generator( std::forward<Generator>(rhs.m_generator) )
82 {}
83
84 //! Size of the underlying dataset
85 data::size_t size() const { return m_generator.capacity(); }
86
87 //! Iterator on the beginning of the dataset
88 iterator begin() const { return iterator( boost::ref(const_cast<Generator&>(m_generator)) ); }
89
90 private:
91 // Data members
92 Generator m_generator;
93 };
94
95 //____________________________________________________________________________//
96
97 //! A generated dataset is a dataset.
98 template<typename Generator>
99 struct is_dataset<generated_by<Generator>> : mpl::true_ {};
100
101 } // namespace monomorphic
102 } // namespace data
103 } // namespace unit_test
104 } // namespace boost
105
106 #include <boost/test/detail/enable_warnings.hpp>
107
108 #endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
109