sl@0: /* boost random/discard_block.hpp header file sl@0: * sl@0: * Copyright Jens Maurer 2002 sl@0: * Distributed under the Boost Software License, Version 1.0. (See sl@0: * accompanying file LICENSE_1_0.txt or copy at sl@0: * http://www.boost.org/LICENSE_1_0.txt) sl@0: * sl@0: * See http://www.boost.org for most recent version including documentation. sl@0: * sl@0: * $Id: discard_block.hpp,v 1.12 2005/05/21 15:57:00 dgregor Exp $ sl@0: * sl@0: * Revision history sl@0: * 2001-03-02 created sl@0: */ sl@0: sl@0: #ifndef BOOST_RANDOM_DISCARD_BLOCK_HPP sl@0: #define BOOST_RANDOM_DISCARD_BLOCK_HPP sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: namespace boost { sl@0: namespace random { sl@0: sl@0: template sl@0: class discard_block sl@0: { sl@0: public: sl@0: typedef UniformRandomNumberGenerator base_type; sl@0: typedef typename base_type::result_type result_type; sl@0: sl@0: BOOST_STATIC_CONSTANT(bool, has_fixed_range = false); sl@0: BOOST_STATIC_CONSTANT(unsigned int, total_block = p); sl@0: BOOST_STATIC_CONSTANT(unsigned int, returned_block = r); sl@0: sl@0: #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS sl@0: BOOST_STATIC_ASSERT(total_block >= returned_block); sl@0: #endif sl@0: sl@0: discard_block() : _rng(), _n(0) { } sl@0: explicit discard_block(const base_type & rng) : _rng(rng), _n(0) { } sl@0: template discard_block(It& first, It last) sl@0: : _rng(first, last), _n(0) { } sl@0: void seed() { _rng.seed(); _n = 0; } sl@0: template void seed(T s) { _rng.seed(s); _n = 0; } sl@0: template void seed(It& first, It last) sl@0: { _n = 0; _rng.seed(first, last); } sl@0: sl@0: const base_type& base() const { return _rng; } sl@0: sl@0: result_type operator()() sl@0: { sl@0: if(_n >= returned_block) { sl@0: // discard values of random number generator sl@0: for( ; _n < total_block; ++_n) sl@0: _rng(); sl@0: _n = 0; sl@0: } sl@0: ++_n; sl@0: return _rng(); sl@0: } sl@0: sl@0: result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); } sl@0: result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); } sl@0: static bool validation(result_type x) { return true; } // dummy sl@0: sl@0: #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE sl@0: sl@0: #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS sl@0: template sl@0: friend std::basic_ostream& sl@0: operator<<(std::basic_ostream& os, const discard_block& s) sl@0: { sl@0: os << s._rng << " " << s._n << " "; sl@0: return os; sl@0: } sl@0: sl@0: template sl@0: friend std::basic_istream& sl@0: operator>>(std::basic_istream& is, discard_block& s) sl@0: { sl@0: is >> s._rng >> std::ws >> s._n >> std::ws; sl@0: return is; sl@0: } sl@0: #endif sl@0: sl@0: friend bool operator==(const discard_block& x, const discard_block& y) sl@0: { return x._rng == y._rng && x._n == y._n; } sl@0: friend bool operator!=(const discard_block& x, const discard_block& y) sl@0: { return !(x == y); } sl@0: #else sl@0: // Use a member function; Streamable concept not supported. sl@0: bool operator==(const discard_block& rhs) const sl@0: { return _rng == rhs._rng && _n == rhs._n; } sl@0: bool operator!=(const discard_block& rhs) const sl@0: { return !(*this == rhs); } sl@0: #endif sl@0: sl@0: private: sl@0: base_type _rng; sl@0: unsigned int _n; sl@0: }; sl@0: sl@0: #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION sl@0: // A definition is required even for integral static constants sl@0: template sl@0: const bool discard_block::has_fixed_range; sl@0: template sl@0: const unsigned int discard_block::total_block; sl@0: template sl@0: const unsigned int discard_block::returned_block; sl@0: #endif sl@0: sl@0: } // namespace random sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_RANDOM_DISCARD_BLOCK_HPP