head 1.9; access; symbols UUID_1_6_2:1.8 UUID_1_6_1:1.8 UUID_1_6_0:1.7 UUID_1_5_1:1.6 UUID_1_5_0:1.6 UUID_1_4_2:1.5 UUID_1_4_1:1.5 UUID_1_4_0:1.5 UUID_1_3_2:1.4 UUID_1_3_1:1.3 UUID_1_3_0:1.3; locks; strict; comment @// @; 1.9 date 2008.07.05.12.58.15; author rse; state dead; branches; next 1.8; commitid XLXN7vUmABwPcC9t; 1.8 date 2008.01.10.14.18.46; author rse; state Exp; branches; next 1.7; commitid LqMgFGBgTR7clSMs; 1.7 date 2007.01.01.18.14.54; author rse; state Exp; branches; next 1.6; commitid jOXiIO8S8v7xFP0s; 1.6 date 2006.05.11.09.37.27; author rse; state Exp; branches; next 1.5; commitid u4EPMISJDipjmAwr; 1.5 date 2006.01.13.06.44.30; author rse; state Exp; branches; next 1.4; commitid hYfQc9JIMh4bcphr; 1.4 date 2005.09.25.10.41.18; author rse; state Exp; branches; next 1.3; 1.3 date 2005.08.31.20.08.15; author rse; state Exp; branches; next 1.2; 1.2 date 2005.08.31.20.07.29; author rse; state Exp; branches; next 1.1; 1.1 date 2005.08.31.14.29.56; author rse; state Exp; branches; next ; desc @@ 1.9 log @remove OSSP uuid from CVS -- it is now versioned controlled in a Monotone repository @ text @/* ** OSSP uuid - Universally Unique Identifier ** Copyright (c) 2004-2008 Ralf S. Engelschall ** Copyright (c) 2004-2008 The OSSP Project ** ** This file is part of OSSP uuid, a library for the generation ** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/ ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** uuid++.cc: library C++ API implementation */ #include #include #include "uuid++.hh" /* standard constructor */ uuid::uuid() { uuid_rc_t rc; if ((rc = uuid_create(&ctx)) != UUID_RC_OK) throw uuid_error_t(rc); } /* copy constructor */ uuid::uuid(const uuid &obj) { /* Notice: the copy constructor is the same as the assignment operator (with the object as the argument) below, except that (1) no check for self-assignment is required, (2) no existing internals have to be destroyed and (3) no return value is given back. */ uuid_rc_t rc; if ((rc = uuid_clone(obj.ctx, &ctx)) != UUID_RC_OK) throw uuid_error_t(rc); return; } /* extra constructor via C API object */ uuid::uuid(const uuid_t *obj) { uuid_rc_t rc; if (obj == NULL) throw uuid_error_t(UUID_RC_ARG); if ((rc = uuid_clone(obj, &ctx)) != UUID_RC_OK) throw uuid_error_t(rc); return; } /* extra constructor via binary representation */ uuid::uuid(const void *bin) { uuid_rc_t rc; if (bin == NULL) throw uuid_error_t(UUID_RC_ARG); if ((rc = uuid_create(&ctx)) != UUID_RC_OK) throw uuid_error_t(rc); import(bin); return; } /* extra constructor via string representation */ uuid::uuid(const char *str) { uuid_rc_t rc; if (str == NULL) throw uuid_error_t(UUID_RC_ARG); if ((rc = uuid_create(&ctx)) != UUID_RC_OK) throw uuid_error_t(rc); import(str); return; } /* standard destructor */ uuid::~uuid() { uuid_destroy(ctx); return; } /* assignment operator: import of other C++ API object */ uuid &uuid::operator=(const uuid &obj) { uuid_rc_t rc; if (this == &obj) return *this; if ((rc = uuid_destroy(ctx)) != UUID_RC_OK) throw uuid_error_t(rc); if ((rc = uuid_clone(obj.ctx, &ctx)) != UUID_RC_OK) throw uuid_error_t(rc); return *this; } /* assignment operator: import of other C API object */ uuid &uuid::operator=(const uuid_t *obj) { uuid_rc_t rc; if (obj == NULL) throw uuid_error_t(UUID_RC_ARG); if ((rc = uuid_clone(obj, &ctx)) != UUID_RC_OK) throw uuid_error_t(rc); return *this; } /* assignment operator: import of binary representation */ uuid &uuid::operator=(const void *bin) { if (bin == NULL) throw uuid_error_t(UUID_RC_ARG); import(bin); return *this; } /* assignment operator: import of string representation */ uuid &uuid::operator=(const char *str) { if (str == NULL) throw uuid_error_t(UUID_RC_ARG); import(str); return *this; } /* method: clone object */ uuid uuid::clone(void) { return new uuid(this); } /* method: loading existing UUID by name */ void uuid::load(const char *name) { uuid_rc_t rc; if (name == NULL) throw uuid_error_t(UUID_RC_ARG); if ((rc = uuid_load(ctx, name)) != UUID_RC_OK) throw uuid_error_t(rc); return; } /* method: making new UUID one from scratch */ void uuid::make(unsigned int mode, ...) { uuid_rc_t rc; va_list ap; va_start(ap, mode); if ((mode & UUID_MAKE_V3) || (mode & UUID_MAKE_V5)) { const uuid *ns = (const uuid *)va_arg(ap, const uuid *); const char *name = (const char *)va_arg(ap, char *); if (ns == NULL || name == NULL) throw uuid_error_t(UUID_RC_ARG); rc = uuid_make(ctx, mode, ns->ctx, name); } else rc = uuid_make(ctx, mode); va_end(ap); if (rc != UUID_RC_OK) throw uuid_error_t(rc); return; } /* method: comparison for Nil UUID */ int uuid::isnil(void) { uuid_rc_t rc; int rv; if ((rc = uuid_isnil(ctx, &rv)) != UUID_RC_OK) throw uuid_error_t(rc); return rv; } /* method: comparison against other object */ int uuid::compare(const uuid &obj) { uuid_rc_t rc; int rv; if ((rc = uuid_compare(ctx, obj.ctx, &rv)) != UUID_RC_OK) throw uuid_error_t(rc); return rv; } /* method: comparison for equality */ int uuid::operator==(const uuid &obj) { return (compare(obj) == 0); } /* method: comparison for inequality */ int uuid::operator!=(const uuid &obj) { return (compare(obj) != 0); } /* method: comparison for lower-than */ int uuid::operator<(const uuid &obj) { return (compare(obj) < 0); } /* method: comparison for lower-than-or-equal */ int uuid::operator<=(const uuid &obj) { return (compare(obj) <= 0); } /* method: comparison for greater-than */ int uuid::operator>(const uuid &obj) { return (compare(obj) > 0); } /* method: comparison for greater-than-or-equal */ int uuid::operator>=(const uuid &obj) { return (compare(obj) >= 0); } /* method: import binary representation */ void uuid::import(const void *bin) { uuid_rc_t rc; if ((rc = uuid_import(ctx, UUID_FMT_BIN, bin, UUID_LEN_BIN)) != UUID_RC_OK) throw uuid_error_t(rc); return; } /* method: import string or single integer value representation */ void uuid::import(const char *str) { uuid_rc_t rc; if ((rc = uuid_import(ctx, UUID_FMT_STR, str, UUID_LEN_STR)) != UUID_RC_OK) if ((rc = uuid_import(ctx, UUID_FMT_SIV, str, UUID_LEN_SIV)) != UUID_RC_OK) throw uuid_error_t(rc); return; } /* method: export binary representation */ void *uuid::binary(void) { uuid_rc_t rc; void *bin = NULL; if ((rc = uuid_export(ctx, UUID_FMT_BIN, &bin, NULL)) != UUID_RC_OK) throw uuid_error_t(rc); return bin; } /* method: export string representation */ char *uuid::string(void) { uuid_rc_t rc; char *str = NULL; if ((rc = uuid_export(ctx, UUID_FMT_STR, (void **)&str, NULL)) != UUID_RC_OK) throw uuid_error_t(rc); return str; } /* method: export single integer value representation */ char *uuid::integer(void) { uuid_rc_t rc; char *str = NULL; if ((rc = uuid_export(ctx, UUID_FMT_SIV, (void **)&str, NULL)) != UUID_RC_OK) throw uuid_error_t(rc); return str; } /* method: export textual summary representation */ char *uuid::summary(void) { uuid_rc_t rc; char *txt = NULL; if ((rc = uuid_export(ctx, UUID_FMT_TXT, (void **)&txt, NULL)) != UUID_RC_OK) throw uuid_error_t(rc); return txt; } /* method: return library version */ unsigned long uuid::version(void) { return uuid_version(); } @ 1.8 log @adjust copyright messages for 2008 and bump version in advance @ text @@ 1.7 log @Adjust copyright messages for new year 2007. @ text @d3 2 a4 2 ** Copyright (c) 2004-2007 Ralf S. Engelschall ** Copyright (c) 2004-2007 The OSSP Project @ 1.6 log @Add full support for Single Integer Value (SIV) UUID representation for both importing and exporting in C/C++/Perl/PHP APIs. @ text @d3 2 a4 2 ** Copyright (c) 2004-2006 Ralf S. Engelschall ** Copyright (c) 2004-2006 The OSSP Project @ 1.5 log @Adjust copyright messages for new year 2006. @ text @d246 1 a246 1 /* method: import string representation */ d251 2 a252 1 throw uuid_error_t(rc); d276 10 @ 1.4 log @consistent style: always use 'return' @ text @d3 2 a4 2 ** Copyright (c) 2004-2005 Ralf S. Engelschall ** Copyright (c) 2004-2005 The OSSP Project @ 1.3 log @cleanup source @ text @d53 1 d64 1 d76 1 d88 1 d95 1 d243 1 d252 1 @ 1.2 log @ok, second attempt: complete rewrite from scratch of the C++ API. Now with a manual page and more methods. It is now providing the same functionality as the C API and does no longer miss some parts. @ text @a34 4 /* ** ==== Low-Level C++ API (direct mapping of C API) ==== */ d231 1 a231 1 d247 1 a247 1 @ 1.1 log @Add an experimental C++ API binding which can be enabled under build-time with option --with-cxx. @ text @a34 2 using namespace std; d36 1 a36 1 ** OBJECT CONSTRUCTORS AND DESTRUCTOR d42 3 a44 8 if (uuid_create(&ctx) != UUID_RC_OK) throw "unable to create UUID context"; } /* standard destructor */ uuid::~uuid() { uuid_destroy(ctx); d47 1 a47 1 /* construction: import of other C++ API object (= special C++ copy constructor) */ d51 6 a56 5 operator (with the object as the RHS) below, except that (1) no check for self-assignment is required, (2) no existing internals have to be destroyed and (3) no return value is given back. */ if (uuid_clone(obj.ctx, &ctx) != UUID_RC_OK) throw "unable to clone UUID context"; d59 8 a66 9 /* construction: import of other C API object */ uuid::uuid(uuid_t *obj) { if (obj != NULL) ctx = obj; else { if (uuid_create(&ctx) != UUID_RC_OK) throw "unable to create UUID context"; } d69 2 a70 2 /* construction: import of binary representation */ uuid::uuid(const unsigned char *bin) d72 6 a77 6 if (uuid_create(&ctx) != UUID_RC_OK) throw "unable to create UUID context"; if (bin != NULL) { if (uuid_import(ctx, UUID_FMT_BIN, bin, UUID_LEN_BIN) != UUID_RC_OK) throw "unable to import UUID from binary representation"; } d80 1 a80 1 /* construction: import of string representation */ d83 6 a88 6 if (uuid_create(&ctx) != UUID_RC_OK) throw "unable to create UUID context"; if (str != NULL) { if (uuid_import(ctx, UUID_FMT_STR, str, strlen(str)) != UUID_RC_OK) throw "unable to import UUID from string representation"; } d91 5 a95 3 /* ** IMPORT METHODS */ d97 2 a98 2 /* assignment: import of other C++ API object */ uuid &uuid::operator=(const uuid &rhs) d100 2 a101 1 if (this == &rhs) d103 4 a106 4 if (uuid_destroy(ctx) != UUID_RC_OK) throw "failed to destroy old UUID context"; if (uuid_clone(rhs.ctx, &ctx) != UUID_RC_OK) throw "unable to clone UUID context"; d110 2 a111 2 /* assignment: import of other C API object */ uuid &uuid::operator=(const uuid_t *rhs) d113 5 a117 4 if (rhs == NULL) throw "invalid RHS C object"; if (uuid_clone((uuid_t *)rhs, &ctx) != UUID_RC_OK) throw "unable to clone UUID context"; d121 2 a122 2 /* assignment: import of binary representation */ uuid &uuid::operator=(const unsigned char *rhs) d124 3 a126 4 if (rhs == NULL) throw "invalid RHS string"; if (uuid_import(ctx, UUID_FMT_BIN, (const void *)rhs, UUID_LEN_BIN) != UUID_RC_OK) throw "unable to import into source UUID context"; d130 2 a131 2 /* assignment: import of string representation */ uuid &uuid::operator=(const char *rhs) d133 3 a135 4 if (rhs == NULL) throw "invalid RHS string"; if (uuid_import(ctx, UUID_FMT_STR, (const void *)rhs, strlen(rhs)) != UUID_RC_OK) throw "unable to import into source UUID context"; d139 5 a143 3 /* ** GENERATION METHODS */ d145 1 a145 1 /* generation: loading existing UUID by name */ d148 1 d150 3 a152 3 throw "invalid UUID name"; if (uuid_load(ctx, name) != UUID_RC_OK) throw "unable to load UUID by name"; d156 1 a156 1 /* generation: making new UUID one from scratch */ d159 1 a159 1 uuid_rc_t rv; d164 1 a164 1 const char *ns = (const char *)va_arg(ap, char *); d167 2 a168 2 throw "invalid arguments"; rv = uuid_make(ctx, mode, ns, name); d171 1 a171 1 rv = uuid_make(ctx, mode); d173 2 a174 2 if (rv != UUID_RC_OK) throw "unable to make new UUID"; d178 1 a178 5 /* ** COMPARISON METHODS */ /* comparison: is-Nil-UUID */ d181 1 d184 2 a185 2 if (uuid_isnil(ctx, &rv) != UUID_RC_OK) throw "unable to compare UUID for being Nil-UUID"; d189 2 a190 2 /* comparison: equality */ int uuid::operator==(const uuid &rhs) d192 1 d195 3 a197 3 if (uuid_compare(ctx, rhs.ctx, &rv) != UUID_RC_OK) throw "unable to compare UUID contexts"; return (rv == 0); d200 2 a201 2 /* comparison: inequality */ int uuid::operator!=(const uuid &rhs) d203 2 a204 1 int rv; d206 4 a209 3 if (uuid_compare(ctx, rhs.ctx, &rv) != UUID_RC_OK) throw "unable to compare UUID contexts"; return (rv != 0); d212 2 a213 2 /* comparison: lower-than */ int uuid::operator<(const uuid &rhs) d215 2 a216 1 int rv; d218 4 a221 3 if (uuid_compare(ctx, rhs.ctx, &rv) != UUID_RC_OK) throw "unable to compare UUID contexts"; return (rv < 0); d224 2 a225 2 /* comparison: lower-than-or-equal */ int uuid::operator<=(const uuid &rhs) d227 1 a227 5 int rv; if (uuid_compare(ctx, rhs.ctx, &rv) != UUID_RC_OK) throw "unable to compare UUID contexts"; return (rv <= 0); d230 2 a231 2 /* comparison: greater-than */ int uuid::operator>(const uuid &rhs) d233 1 a233 5 int rv; if (uuid_compare(ctx, rhs.ctx, &rv) != UUID_RC_OK) throw "unable to compare UUID contexts"; return (rv > 0); d235 3 a237 3 /* comparison: greater-than-or-equal */ int uuid::operator>=(const uuid &rhs) d239 3 a241 5 int rv; if (uuid_compare(ctx, rhs.ctx, &rv) != UUID_RC_OK) throw "unable to compare UUID contexts"; return (rv >= 0); d244 2 a245 6 /* ** EXPORT METHODS */ /* export: object representation */ uuid_t *uuid::object(void) d247 3 a249 1 return ctx; d252 2 a253 2 /* export: binary representation */ unsigned char *uuid::binary(void) d255 4 a258 5 unsigned char *bin; bin = NULL; if (uuid_export(ctx, UUID_FMT_BIN, (void **)&bin, NULL) != UUID_RC_OK) throw "unable to export UUID context"; d262 1 a262 1 /* export: string representation */ d265 16 a280 1 char *str; d282 4 a285 4 str = NULL; if (uuid_export(ctx, UUID_FMT_STR, (void **)&str, NULL) != UUID_RC_OK) throw "unable to export UUID context"; return str; @