name generator ref

This commit is contained in:
Marius Bancila 2018-01-17 12:31:55 +02:00 committed by GitHub
parent ea43f4b9ba
commit daf2fa7965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ Generators:
| `uuid_default_generator` | a function object that generates new UUIDs, using an operating system method to create one (`CoCreateGuid` on Windows, `uuid_generate` on Linux, `CFUUIDCreate` on Mac) | | `uuid_default_generator` | a function object that generates new UUIDs, using an operating system method to create one (`CoCreateGuid` on Windows, `uuid_generate` on Linux, `CFUUIDCreate` on Mac) |
| ` basic_uuid_random_generator` | a function object that generates version 4 UUIDs using a pseudo-random number generator engine. | | ` basic_uuid_random_generator` | a function object that generates version 4 UUIDs using a pseudo-random number generator engine. |
| `uuid_random_generator` | a basic_uuid_random_generator using the Marsenne Twister engine, i.e. `basic_uuid_random_generator<std::mt19937>` | | `uuid_random_generator` | a basic_uuid_random_generator using the Marsenne Twister engine, i.e. `basic_uuid_random_generator<std::mt19937>` |
| `uuid_name_generator` | a function object that generates version 5, name-based UUIDs using SHA1 hashing. |
Utilities: Utilities:
@ -80,6 +81,15 @@ assert(guid.size() == 16);
assert(guid.version() == uuids::uuid_version::random_number_based); assert(guid.version() == uuids::uuid_version::random_number_based);
assert(guid.variant() == uuids::uuid_variant::rfc); assert(guid.variant() == uuids::uuid_variant::rfc);
``` ```
* Creating a new UUID with the name generator
```
uuids::uuid_name_generator gen;
uuid const guid = gen();
assert(!guid.nil());
assert(guid.size() == 16);
assert(guid.version() == uuids::uuid_version::name_based_sha1);
assert(guid.variant() == uuids::uuid_variant::rfc);
```
* Create a UUID from a string * Create a UUID from a string
``` ```
using namespace std::string_literals; using namespace std::string_literals;
@ -192,11 +202,6 @@ auto h2 = std::hash<uuid>{};
assert(h1(str) == h2(guid)); assert(h1(str) == h2(guid));
``` ```
## Limitations
The library can only create new uuids using the underlaying operating system resources.
An alternative to this library could be the [boost::uuid](http://www.boost.org/doc/libs/1_65_1/libs/uuid/) library. This has a similar model, but supports creating all variant of uuids, including md5 and sha1 name based, time based, and random number based values.
## Support ## Support
The library is supported on all major operating systems: Windows, Linux and Mac OS. The library is supported on all major operating systems: Windows, Linux and Mac OS.
@ -207,3 +212,6 @@ A testing project is available in the sources. To build and execute the tests do
* Run the command `cmake ..` from the `build` directory; if you do not have CMake you must install it first. * Run the command `cmake ..` from the `build` directory; if you do not have CMake you must install it first.
* Build the project created in the previous step * Build the project created in the previous step
* Run the executable. * Run the executable.
## Credits
The SHA1 implementation is based on the [TinySHA1](https://github.com/mohaps/TinySHA1) library.