|
Boost : |
Subject: Re: [boost] [UUID] Code for UUIDs as PODs and other changes
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-12-06 15:20:42
On Sat, Dec 6, 2008 at 14:48, Roman Yakovenko <roman.yakovenko_at_[hidden]> wrote:
>
> Sorry for noise. I didn't see "native_generator" typedef "on Windows".
>
> May be it worth to introduce "native_generator.hpp" header, which will
> select the platform and "include" the native generator?
>
No, the noise was a good thing. I think I like the native_generator
better, in retrospect. I'm thinking of something like this (with the
details better flushed out):
#ifdef BOOST_HAS_E2FSPROGS
#include <uuid/uuid.h>
struct native_default {
void generate(uuiid &u) { uuid_generate(&*u.begin()); }
};
struct native_time_based {
void generate(uuiid &u) { uuid_generate_time(&*u.begin()); }
};
struct native_random {
void generate(uuiid &u) { uuid_generate_random(&*u.begin()); }
};
#elif BOOST_HAS_WINDOWS
#include <rpc.h>
struct native_default {
void generate(uuiid &u) { UUID u_; UuidCreate(&u_);
u.assign((uint8_t*)&u_, 16+(uint8_t*)&u_); }
};
// And others, possibly
#endif
template <typename NativeStrategy = native_default>
struct native_generator : NativeStrategy {
uuid operator()() const {
uuid u; NativeStrategy::generate(u); return u;
}
};
Looks like less code duplication overall, too.
With SFINAE it should even work for SHA1 and MD5 generators, with an
overloaded constructor to pass a uuid to the Strategy's constructor,
and an overloaded operator() that takes a message to hash.
The one problem is if people wanted more choice. I was thinking that
the http://www.ossp.org/pkg/lib/uuid/ could provide another generator
in the old scheme, but that may also just be a waste of effort, since
it's less common than the e2fsprogs libs. Also, what it provides are
the same things that Boost.UUID provides natively, so...
~ Scott
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk