]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/random/variate_generator.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
691af20136998ef17cad9488223eb47c6e9f92e9
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / random / variate_generator.hpp
1 /* boost random/variate_generator.hpp header file\r
2  *\r
3  * Copyright Jens Maurer 2002\r
4  * Distributed under the Boost Software License, Version 1.0. (See\r
5  * accompanying file LICENSE_1_0.txt or copy at\r
6  * http://www.boost.org/LICENSE_1_0.txt)\r
7  *\r
8  * See http://www.boost.org for most recent version including documentation.\r
9  *\r
10  * $Id: variate_generator.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $\r
11  *\r
12  */\r
13 \r
14 #ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP\r
15 #define BOOST_RANDOM_RANDOM_GENERATOR_HPP\r
16 \r
17 #include <boost/config.hpp>\r
18 \r
19 // implementation details\r
20 #include <boost/detail/workaround.hpp>\r
21 #include <boost/random/uniform_01.hpp>\r
22 #include <boost/random/detail/pass_through_engine.hpp>\r
23 #include <boost/random/detail/uniform_int_float.hpp>\r
24 #include <boost/random/detail/ptr_helper.hpp>\r
25 \r
26 // Borland C++ 5.6.0 has problems using its numeric_limits traits as\r
27 // template parameters\r
28 #if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)\r
29 #include <boost/type_traits/is_integral.hpp>\r
30 #endif\r
31 \r
32 #include <boost/random/detail/disable_warnings.hpp>\r
33 \r
34 namespace boost {\r
35 \r
36 namespace random {\r
37 namespace detail {\r
38 \r
39 template<bool have_int, bool want_int>\r
40 struct engine_helper;\r
41 \r
42 // for consistency, always have two levels of decorations\r
43 template<>\r
44 struct engine_helper<true, true>\r
45 {\r
46   template<class Engine, class DistInputType>\r
47   struct impl\r
48   {\r
49     typedef pass_through_engine<Engine> type;\r
50   };\r
51 };\r
52 \r
53 template<>\r
54 struct engine_helper<false, false>\r
55 {\r
56   template<class Engine, class DistInputType>\r
57   struct impl\r
58   {\r
59     typedef uniform_01<Engine, DistInputType> type;\r
60   };\r
61 };\r
62 \r
63 template<>\r
64 struct engine_helper<true, false>\r
65 {\r
66   template<class Engine, class DistInputType>\r
67   struct impl\r
68   {\r
69     typedef uniform_01<Engine, DistInputType> type;\r
70   };\r
71 };\r
72 \r
73 template<>\r
74 struct engine_helper<false, true>\r
75 {\r
76   template<class Engine, class DistInputType>\r
77   struct impl\r
78   {\r
79     typedef uniform_int_float<Engine, unsigned long> type;\r
80   };\r
81 };\r
82 \r
83 } // namespace detail\r
84 } // namespace random\r
85 \r
86 \r
87 template<class Engine, class Distribution>\r
88 class variate_generator\r
89 {\r
90 private:\r
91   typedef random::detail::pass_through_engine<Engine> decorated_engine;\r
92 \r
93 public:\r
94   typedef typename decorated_engine::base_type engine_value_type;\r
95   typedef Engine engine_type;\r
96   typedef Distribution distribution_type;\r
97   typedef typename Distribution::result_type result_type;\r
98 \r
99   variate_generator(Engine e, Distribution d)\r
100     : _eng(decorated_engine(e)), _dist(d) { }\r
101 \r
102   result_type operator()() { return _dist(_eng); }\r
103   template<class T>\r
104   result_type operator()(T value) { return _dist(_eng, value); }\r
105 \r
106   engine_value_type& engine() { return _eng.base().base(); }\r
107   const engine_value_type& engine() const { return _eng.base().base(); }\r
108 \r
109   distribution_type& distribution() { return _dist; }\r
110   const distribution_type& distribution() const { return _dist; }\r
111 \r
112   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }\r
113   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }\r
114 \r
115 private:\r
116 #if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)\r
117   typedef typename random::detail::engine_helper<\r
118     boost::is_integral<typename decorated_engine::result_type>::value,\r
119     boost::is_integral<typename Distribution::input_type>::value\r
120     >::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;\r
121 #else\r
122   enum {\r
123     have_int = std::numeric_limits<typename decorated_engine::result_type>::is_integer,\r
124     want_int = std::numeric_limits<typename Distribution::input_type>::is_integer\r
125   };\r
126   typedef typename random::detail::engine_helper<have_int, want_int>::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;\r
127 #endif\r
128 \r
129   internal_engine_type _eng;\r
130   distribution_type _dist;\r
131 };\r
132 \r
133 } // namespace boost\r
134 \r
135 #include <boost/random/detail/disable_warnings.hpp>\r
136 \r
137 #endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP\r