]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 single element monomorphic dataset | |
10 | // *************************************************************************** | |
11 | ||
12 | #ifndef BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER | |
13 | #define BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER | |
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 | // ************** singleton ************** // | |
30 | // ************************************************************************** // | |
31 | ||
32 | /// Models a single element data set | |
33 | template<typename T> | |
34 | class singleton { | |
92f5a8d4 | 35 | private: |
7c673cae FG |
36 | typedef typename boost::decay<T>::type sample; |
37 | ||
92f5a8d4 TL |
38 | public: |
39 | ||
7c673cae FG |
40 | enum { arity = 1 }; |
41 | ||
42 | struct iterator { | |
43 | // Constructor | |
44 | explicit iterator( singleton<T> const* owner ) | |
45 | : m_owner( owner ) | |
46 | {} | |
47 | ||
48 | // forward iterator interface | |
49 | sample const& operator*() const { return m_owner->value(); } | |
50 | void operator++() {} | |
51 | ||
52 | private: | |
53 | singleton<T> const* m_owner; | |
54 | }; | |
55 | ||
56 | //! Constructor | |
57 | explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {} | |
58 | ||
59 | //! Move constructor | |
60 | singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {} | |
61 | ||
62 | //! Value access method | |
63 | T const& value() const { return m_value; } | |
64 | ||
65 | //! dataset interface | |
66 | data::size_t size() const { return 1; } | |
67 | iterator begin() const { return iterator( this ); } | |
68 | ||
69 | private: | |
70 | // Data members | |
71 | T m_value; | |
72 | }; | |
73 | ||
74 | //____________________________________________________________________________// | |
75 | ||
76 | // a singleton is a dataset | |
77 | template<typename T> | |
78 | struct is_dataset<singleton<T>> : mpl::true_ {}; | |
79 | ||
80 | //____________________________________________________________________________// | |
81 | ||
82 | } // namespace monomorphic | |
83 | ||
84 | /// @overload boost::unit_test::data::make() | |
85 | template<typename T> | |
b32b8144 | 86 | inline typename std::enable_if<!is_container_forward_iterable<T>::value && |
7c673cae FG |
87 | !monomorphic::is_dataset<T>::value && |
88 | !boost::is_array<typename boost::remove_reference<T>::type>::value, | |
89 | monomorphic::singleton<T> | |
90 | >::type | |
91 | make( T&& v ) | |
92 | { | |
93 | return monomorphic::singleton<T>( std::forward<T>( v ) ); | |
94 | } | |
95 | ||
96 | //____________________________________________________________________________// | |
97 | ||
98 | /// @overload boost::unit_test::data::make | |
99 | inline monomorphic::singleton<char*> | |
100 | make( char* str ) | |
101 | { | |
102 | return monomorphic::singleton<char*>( std::move(str) ); | |
103 | } | |
104 | ||
105 | //____________________________________________________________________________// | |
106 | ||
107 | /// @overload boost::unit_test::data::make | |
108 | inline monomorphic::singleton<char const*> | |
109 | make( char const* str ) | |
110 | { | |
111 | return monomorphic::singleton<char const*>( std::move(str) ); | |
112 | } | |
113 | ||
114 | } // namespace data | |
115 | } // namespace unit_test | |
116 | } // namespace boost | |
117 | ||
118 | #include <boost/test/detail/enable_warnings.hpp> | |
119 | ||
120 | #endif // BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER | |
121 |