1 | /* boost random/detail/uniform_int_float.hpp header file |
---|
2 | * |
---|
3 | * Copyright Jens Maurer 2000-2001 |
---|
4 | * Distributed under the Boost Software License, Version 1.0. (See |
---|
5 | * accompanying file LICENSE_1_0.txt or copy at |
---|
6 | * http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | * |
---|
8 | * See http://www.boost.org for most recent version including documentation. |
---|
9 | * |
---|
10 | * $Id: pass_through_engine.hpp,v 1.5 2004/07/27 03:43:32 dgregor Exp $ |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | #ifndef BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP |
---|
15 | #define BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP |
---|
16 | |
---|
17 | #include <boost/config.hpp> |
---|
18 | #include <boost/random/detail/ptr_helper.hpp> |
---|
19 | |
---|
20 | |
---|
21 | namespace boost { |
---|
22 | namespace random { |
---|
23 | namespace detail { |
---|
24 | |
---|
25 | template<class UniformRandomNumberGenerator> |
---|
26 | class pass_through_engine |
---|
27 | { |
---|
28 | private: |
---|
29 | typedef ptr_helper<UniformRandomNumberGenerator> helper_type; |
---|
30 | |
---|
31 | public: |
---|
32 | typedef typename helper_type::value_type base_type; |
---|
33 | typedef typename base_type::result_type result_type; |
---|
34 | |
---|
35 | explicit pass_through_engine(UniformRandomNumberGenerator rng) |
---|
36 | // make argument an rvalue to avoid matching Generator& constructor |
---|
37 | : _rng(static_cast<typename helper_type::rvalue_type>(rng)) |
---|
38 | { } |
---|
39 | |
---|
40 | result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().min)(); } |
---|
41 | result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().max)(); } |
---|
42 | base_type& base() { return helper_type::ref(_rng); } |
---|
43 | const base_type& base() const { return helper_type::ref(_rng); } |
---|
44 | |
---|
45 | result_type operator()() { return base()(); } |
---|
46 | |
---|
47 | private: |
---|
48 | UniformRandomNumberGenerator _rng; |
---|
49 | }; |
---|
50 | |
---|
51 | #ifndef BOOST_NO_STD_LOCALE |
---|
52 | |
---|
53 | template<class UniformRandomNumberGenerator, class CharT, class Traits> |
---|
54 | std::basic_ostream<CharT,Traits>& |
---|
55 | operator<<( |
---|
56 | std::basic_ostream<CharT,Traits>& os |
---|
57 | , const pass_through_engine<UniformRandomNumberGenerator>& ud |
---|
58 | ) |
---|
59 | { |
---|
60 | return os << ud.base(); |
---|
61 | } |
---|
62 | |
---|
63 | template<class UniformRandomNumberGenerator, class CharT, class Traits> |
---|
64 | std::basic_istream<CharT,Traits>& |
---|
65 | operator>>( |
---|
66 | std::basic_istream<CharT,Traits>& is |
---|
67 | , const pass_through_engine<UniformRandomNumberGenerator>& ud |
---|
68 | ) |
---|
69 | { |
---|
70 | return is >> ud.base(); |
---|
71 | } |
---|
72 | |
---|
73 | #else // no new streams |
---|
74 | |
---|
75 | template<class UniformRandomNumberGenerator> |
---|
76 | inline std::ostream& |
---|
77 | operator<<(std::ostream& os, |
---|
78 | const pass_through_engine<UniformRandomNumberGenerator>& ud) |
---|
79 | { |
---|
80 | return os << ud.base(); |
---|
81 | } |
---|
82 | |
---|
83 | template<class UniformRandomNumberGenerator> |
---|
84 | inline std::istream& |
---|
85 | operator>>(std::istream& is, |
---|
86 | const pass_through_engine<UniformRandomNumberGenerator>& ud) |
---|
87 | { |
---|
88 | return is >> ud.base(); |
---|
89 | } |
---|
90 | |
---|
91 | #endif |
---|
92 | |
---|
93 | } // namespace detail |
---|
94 | } // namespace random |
---|
95 | } // namespace boost |
---|
96 | |
---|
97 | #endif // BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP |
---|
98 | |
---|