File indexing completed on 2025-01-18 09:53:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP
0012 #define BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP
0013
0014 #include <boost/config.hpp>
0015 #include <boost/cstdint.hpp>
0016 #include <boost/limits.hpp>
0017 #include <boost/static_assert.hpp>
0018 #include <boost/move/core.hpp>
0019 #include <boost/move/utility_core.hpp>
0020 #include <boost/type_traits/is_integral.hpp>
0021 #include <boost/type_traits/is_unsigned.hpp>
0022 #include <boost/uuid/entropy_error.hpp>
0023 #include <climits>
0024 #include <iterator>
0025
0026
0027
0028
0029 #include <boost/uuid/detail/random_provider_detect_platform.hpp>
0030 #include <boost/uuid/detail/random_provider_include_platform.hpp>
0031
0032
0033 namespace boost {
0034 namespace uuids {
0035 namespace detail {
0036
0037
0038
0039
0040
0041
0042
0043 class random_provider :
0044 public detail::random_provider_base
0045 {
0046 BOOST_MOVABLE_BUT_NOT_COPYABLE(random_provider)
0047
0048 public:
0049 BOOST_DEFAULTED_FUNCTION(random_provider(), {})
0050
0051 random_provider(BOOST_RV_REF(random_provider) that) BOOST_NOEXCEPT :
0052 detail::random_provider_base(boost::move(static_cast< detail::random_provider_base& >(that)))
0053 {
0054 }
0055
0056 random_provider& operator= (BOOST_RV_REF(random_provider) that) BOOST_NOEXCEPT
0057 {
0058 static_cast< detail::random_provider_base& >(*this) = boost::move(static_cast< detail::random_provider_base& >(that));
0059 return *this;
0060 }
0061
0062
0063
0064
0065 template<class Iter>
0066 void generate(Iter first, Iter last)
0067 {
0068 typedef typename std::iterator_traits<Iter>::value_type value_type;
0069 BOOST_STATIC_ASSERT(is_integral<value_type>::value);
0070 BOOST_STATIC_ASSERT(is_unsigned<value_type>::value);
0071 BOOST_STATIC_ASSERT(sizeof(value_type) * CHAR_BIT >= 32);
0072
0073 for (; first != last; ++first)
0074 {
0075 get_random_bytes(&*first, sizeof(*first));
0076 *first &= (std::numeric_limits<boost::uint32_t>::max)();
0077 }
0078 }
0079
0080
0081 const char * name() const
0082 {
0083 return BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(BOOST_UUID_RANDOM_PROVIDER_NAME);
0084 }
0085 };
0086
0087 }
0088 }
0089 }
0090
0091 #endif