Boost logo

Boost :

Subject: [boost] [uuid] Interface
From: Andy Tompkins (atompkins_at_[hidden])
Date: 2008-12-12 11:44:48

Here is what I see the interface looking like based on feedback
from the review so far. It would, of course, be split into
different header files.

namespace boost {
namespace uuids {

class uuid : boost::totally_ordered<uuid>
// no default constructor

  typedef ... value_type; // will only represent one octet
  typedef ... iterator;
  typedef ... const_iterator;
  typedef ... difference_type;
  typedef ... size_type;

  enum variant_type {
  enum version_type {
    version_1 = 1,
    version_2 = 2,
    version_3 = 3,
    version_4 = 4,
    version_5 = 5,
    version_time_based = version_1,
    version_dce_security = version_2,
    version_name_based_md5 = version_3,
    version_random_number_based = version_4
    version_name_based_sha1 = version_4

  // valid expression
  // generator() - result type must be convertible to a uuid
  template <typename Generator>
  explicit uuid(Generator & generator);
  // assert(std::distance(begin, end) >= 16);
  template <typename ByteInputIterator>
  uuid(ByteInputIterator begin, ByteInputIterator end);

  iterator begin();
  iterator end();

  const_iterator begin() const;
  const_iterator end() const;
  bool is_nil() const;
  operator unspecified_bool_type() const; // return !is_nil();
  static size_type size(); // always return 16

  bool operator==(uuid const& rhs) const;

  bool operator<(uuid const& rhs) const;

  variant_type variant() const;
  version_type version() const;

void swap(uuid & lhs, uuid & rhs);
std::size_t hash_value(uuid const& u);

// removed get/set_showbraces (does anybody want/use them?)
template <typename ch, typename char_traits>
std::basic_ostream<ch, char_traits>& operator<<(std::basic_ostream<ch,
char_traits>& os, uuid const& u);
template <typename ch, typename char_traits>
std::basic_istream<ch, char_traits>& operator>>(std::basic_istream<ch,
char_traits>& os, uuid& u);

class nil_generator // always generates a nil uuid
  typedef uuid result_type;
  uuid operator()();
uuid nil(); // easy to use function - should it be included?

template <typename RandomGenerator = boost::mt19937>
class random_generator
  typedef uuid result_type;

  explicit random_generator(RandomGenerator & gen);
  explicit random_generator(RandomGenerator * gen);
  uuid operator()();

// I guess technically a transformer since it does not have a zero
// operator()
class name_based_generator // uses sha1 hash
  typedef uuid result_type;

  explicit name_based_generator(uuid const& namespace_uuid);

  template <typename ch, typename char_traits, typename allocator>
  uuid operator()(std::basic_string<ch, char_traits, allocator> const&
  uuid operator()(const char* name); // use std::strlen
  uuid operator()(const wchar_t* name); // use std::wcslen

  template <typename ByteInputIterator>
  uuid operator()(ByteInputIterator begin, ByteInputIterator end);

class windows_generator // uses UuidCreate
  typedef uuid result_type;
  uuid operator()();

class linux_generator // used uuid_generate
  typedef uuid result_type;

  uuid operator()();

// on windows - will typedef to windows_generator
// on linux - will typedef to linix_generator
typedef ... native_generator;

} //namespace uuids

using uuids::uuid; // so nobody has to type boost::uuids::uuid

} //namespace boost


uuid Generator concept

X - a type that is a model of uuid generator
x - an object of type X

Associated Types:
Result Type - X::result_type - this must be convertable to

Valid Expressions:
x() - return a boost::uuids::uuid

Andy Tompkins

Boost list run by bdawes at, gregod at, cpdaniel at, john at