Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
taxilian committed Nov 24, 2010
2 parents 5141e03 + c409760 commit 24d149a
Show file tree
Hide file tree
Showing 13 changed files with 1,465 additions and 1 deletion.
2 changes: 1 addition & 1 deletion boost/detail/utf8_codecvt_facet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace std {

BOOST_UTF8_BEGIN_NAMESPACE

struct utf8_codecvt_facet :
struct BOOST_UTF8_DECL utf8_codecvt_facet :
public std::codecvt<wchar_t, char, std::mbstate_t>
{
public:
Expand Down
39 changes: 39 additions & 0 deletions boost/test/included/test_exec_monitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// (C) Copyright Gennadiy Rozental 2001-2008.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: 49312 $
//
// Description : included (vs. linked) version of Test Execution Monitor
// ***************************************************************************

#ifndef BOOST_INCLUDED_TEST_EXEC_MONITOR_HPP_071894GER
#define BOOST_INCLUDED_TEST_EXEC_MONITOR_HPP_071894GER

#include <boost/test/impl/compiler_log_formatter.ipp>
#include <boost/test/impl/debug.ipp>
#include <boost/test/impl/execution_monitor.ipp>
#include <boost/test/impl/framework.ipp>
#include <boost/test/impl/plain_report_formatter.ipp>
#include <boost/test/impl/progress_monitor.ipp>
#include <boost/test/impl/results_collector.ipp>
#include <boost/test/impl/results_reporter.ipp>
#include <boost/test/impl/test_main.ipp>
#include <boost/test/impl/test_tools.ipp>
#include <boost/test/impl/unit_test_log.ipp>
#include <boost/test/impl/unit_test_main.ipp>
#include <boost/test/impl/unit_test_monitor.ipp>
#include <boost/test/impl/unit_test_parameters.ipp>
#include <boost/test/impl/unit_test_suite.ipp>
#include <boost/test/impl/xml_log_formatter.ipp>
#include <boost/test/impl/xml_report_formatter.ipp>

#define BOOST_TEST_INCLUDED
#include <boost/test/test_exec_monitor.hpp>

#endif // BOOST_INCLUDED_TEST_EXEC_MONITOR_HPP_071894GER
36 changes: 36 additions & 0 deletions boost/test/test_exec_monitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// (C) Copyright Gennadiy Rozental 2001-2008.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: 49312 $
//
// Description : Entry point for the end user into the Test Execution Monitor.
// ***************************************************************************

#ifndef BOOST_TEST_EXEC_MONITOR_HPP_071894GER
#define BOOST_TEST_EXEC_MONITOR_HPP_071894GER

// Boost.Test
#include <boost/test/test_tools.hpp>

//____________________________________________________________________________//

// ************************************************************************** //
// ************** Auto Linking ************** //
// ************************************************************************** //

// Automatically link to the correct build variant where possible.
#if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_TEST_NO_LIB) && \
!defined(BOOST_TEST_SOURCE) && !defined(BOOST_TEST_INCLUDED)

# define BOOST_LIB_NAME boost_test_exec_monitor
# include <boost/config/auto_link.hpp>

#endif // auto-linking disabled

#endif // BOOST_TEST_EXEC_MONITOR_HPP_071894GER
125 changes: 125 additions & 0 deletions boost/uuid/name_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Boost name_generator.hpp header file ----------------------------------------------//

// Copyright 2010 Andy Tompkins.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_UUID_NAME_GENERATOR_HPP
#define BOOST_UUID_NAME_GENERATOR_HPP

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/sha1.hpp>
#include <boost/assert.hpp>
#include <string>
#include <cstring> // for strlen, wcslen

#ifdef BOOST_NO_STDC_NAMESPACE
namespace std {
using ::strlen;
using ::wcslen;
} //namespace std
#endif //BOOST_NO_STDC_NAMESPACE

namespace boost {
namespace uuids {

// generate a name-based uuid
// TODO: add in common namesspace uuids
class name_generator {
public:
typedef uuid result_type;

explicit name_generator(uuid const& namespace_uuid)
: namespace_uuid(namespace_uuid)
{}

uuid operator()(const char* name) {
reset();
process_characters(name, std::strlen(name));
return sha_to_uuid();
}

uuid operator()(const wchar_t* name) {
reset();
process_characters(name, std::wcslen(name));
return sha_to_uuid();
}

template <typename ch, typename char_traits, typename alloc>
uuid operator()(std::basic_string<ch, char_traits, alloc> const& name) {
reset();
process_characters(name.c_str(), name.length());
return sha_to_uuid();
}

uuid operator()(void const* buffer, std::size_t byte_count) {
reset();
sha.process_bytes(buffer, byte_count);
return sha_to_uuid();
};

private:
// we convert all characters to uint32_t so that each
// character is 4 bytes reguardless of sizeof(char) or
// sizeof(wchar_t). We want the name string on any
// platform / compiler to generate the same uuid
// except for char
template <typename char_type>
void process_characters(char_type const*const characters, size_t count) {
BOOST_ASSERT(sizeof(uint32_t) >= sizeof(char_type));

for (size_t i=0; i<count; i++) {
uint32_t c = characters[i];
sha.process_byte( (c >> 0) && 0xFF );
sha.process_byte( (c >> 8) && 0xFF );
sha.process_byte( (c >> 16) && 0xFF );
sha.process_byte( (c >> 24) && 0xFF );
}
}

void process_characters(char const*const characters, size_t count) {
sha.process_bytes(characters, count);
}

void reset()
{
sha.reset();
sha.process_bytes(namespace_uuid.begin(), namespace_uuid.size());
}

uuid sha_to_uuid()
{
unsigned int digest[5];

sha.get_digest(digest);

uuid u;
for (int i=0; i<4; ++i) {
*(u.begin() + i*4+0) = ((digest[i] >> 24) & 0xFF);
*(u.begin() + i*4+1) = ((digest[i] >> 16) & 0xFF);
*(u.begin() + i*4+2) = ((digest[i] >> 8) & 0xFF);
*(u.begin() + i*4+3) = ((digest[i] >> 0) & 0xFF);
}

// set variant
// must be 0b10xxxxxx
*(u.begin()+8) &= 0xBF;
*(u.begin()+8) |= 0x80;

// set version
// must be 0b0101xxxx
*(u.begin()+6) &= 0x5F; //0b01011111
*(u.begin()+6) |= 0x50; //0b01010000

return u;
}

private:
uuid namespace_uuid;
detail::sha1 sha;
};

}} // namespace boost::uuids

#endif // BOOST_UUID_NAME_GENERATOR_HPP
34 changes: 34 additions & 0 deletions boost/uuid/nil_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Boost nil_generator.hpp header file ----------------------------------------------//

// Copyright 2010 Andy Tompkins.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_UUID_NIL_GENERATOR_HPP
#define BOOST_UUID_NIL_GENERATOR_HPP

#include <boost/uuid/uuid.hpp>

namespace boost {
namespace uuids {

// generate a nil uuid
struct nil_generator {
typedef uuid result_type;

uuid operator()() const {
// initialize to all zeros
uuid u = {{0}};
return u;
}
};

inline uuid nil_uuid() {
return nil_generator()();
}

}} // namespace boost::uuids

#endif // BOOST_UUID_NIL_GENERATOR_HPP

118 changes: 118 additions & 0 deletions boost/uuid/random_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Boost random_generator.hpp header file ----------------------------------------------//

// Copyright 2010 Andy Tompkins.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_UUID_RANDOM_GENERATOR_HPP
#define BOOST_UUID_RANDOM_GENERATOR_HPP

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/seed_rng.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/assert.hpp>
#include <boost/shared_ptr.hpp>
#include <limits>

namespace boost {
namespace uuids {

// generate a random-based uuid
template <typename UniformRandomNumberGenerator>
class basic_random_generator {
private:
typedef uniform_int<unsigned long> distribution_type;
typedef variate_generator<UniformRandomNumberGenerator*, distribution_type> generator_type;

struct null_deleter
{
void operator()(void const *) const {}
};

public:
typedef uuid result_type;

// default constructor creates the random number generator
basic_random_generator()
: pURNG(new UniformRandomNumberGenerator)
, generator
( pURNG.get()
, distribution_type
( (std::numeric_limits<unsigned long>::min)()
, (std::numeric_limits<unsigned long>::max)()
)
)
{
// seed the random number generator
detail::seed(*pURNG);
}

// keep a reference to a random number generator
// don't seed a given random number generator
explicit basic_random_generator(UniformRandomNumberGenerator& gen)
: pURNG(&gen, null_deleter())
, generator
( pURNG.get()
, distribution_type
( (std::numeric_limits<unsigned long>::min)()
, (std::numeric_limits<unsigned long>::max)()
)
)
{}

// keep a pointer to a random number generator
// don't seed a given random number generator
explicit basic_random_generator(UniformRandomNumberGenerator* pGen)
: pURNG(pGen, null_deleter())
, generator
( pURNG.get()
, distribution_type
( (std::numeric_limits<unsigned long>::min)()
, (std::numeric_limits<unsigned long>::max)()
)
)
{
BOOST_ASSERT(pURNG);
}

uuid operator()()
{
uuid u;

int i=0;
unsigned long random_value = generator();
for (uuid::iterator it=u.begin(); it!=u.end(); ++it, ++i) {
if (i==sizeof(unsigned long)) {
random_value = generator();
i = 0;
}

*it = ((random_value >> (i*8)) & 0xFF);
}

// set variant
// must be 0b10xxxxxx
*(u.begin()+8) &= 0xBF;
*(u.begin()+8) |= 0x80;

// set version
// must be 0b0100xxxx
*(u.begin()+6) &= 0x4F; //0b01001111
*(u.begin()+6) |= 0x40; //0b01000000

return u;
}

private:
shared_ptr<UniformRandomNumberGenerator> pURNG;
generator_type generator;
};

typedef basic_random_generator<mt19937> random_generator;

}} // namespace boost::uuids

#endif //BOOST_UUID_RANDOM_GENERATOR_HPP
Loading

0 comments on commit 24d149a

Please sign in to comment.