Cleaned up some code and comments.

There should be no impacting changes in this commit.
This commit is contained in:
lmat 2014-07-28 16:52:22 -04:00
parent cbc292cc91
commit ce94872ec8
2 changed files with 43 additions and 38 deletions

View File

@ -108,24 +108,21 @@ guid_copy (const GncGUID *guid)
{
const boost::uuids::uuid * old {reinterpret_cast<const boost::uuids::uuid*> (guid)};
boost::uuids::uuid * ret {new boost::uuids::uuid (*old)};
return reinterpret_cast<GncGUID*>(ret);
return reinterpret_cast<GncGUID*> (ret);
}
static GncGUID * nullguid {reinterpret_cast<GncGUID*>(new boost::uuids::uuid{0})};
static GncGUID * nullguid {reinterpret_cast<GncGUID*> (new boost::uuids::uuid{0})};
/*It looks like we are expected to provide the same pointer every time from this function*/
const GncGUID *
guid_null(void)
guid_null (void)
{
//static boost::uuids::nil_generator nil;
//boost::uuids::uuid * ret {new boost::uuids::uuid {0}};
//return reinterpret_cast<GncGUID*> (ret);
return nullguid;
}
/*Takes an allocated guid pointer and constructs it in place*/
void
guid_replace(GncGUID *guid)
guid_replace (GncGUID *guid)
{
static boost::uuids::random_generator gen;
boost::uuids::uuid * val {reinterpret_cast<boost::uuids::uuid*> (guid)};
@ -142,7 +139,7 @@ guid_new (void)
}
GncGUID
guid_new_return(void)
guid_new_return (void)
{
/*we need to construct our value as a boost guid so that
it can be deconstructed (in place) in guid_replace*/
@ -196,16 +193,16 @@ guid_to_string_buff (const GncGUID * guid, gchar *str)
}
gboolean
string_to_guid(const char * str, GncGUID * guid)
string_to_guid (const char * str, GncGUID * guid)
{
static boost::uuids::string_generator strgen;
boost::uuids::uuid * converted {reinterpret_cast<boost::uuids::uuid*> (guid)};
new (converted) boost::uuids::uuid (strgen(str));
new (converted) boost::uuids::uuid (strgen (str));
return true;
}
gboolean
guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
guid_equal (const GncGUID *guid_1, const GncGUID *guid_2)
{
if (!guid_1 || !guid_2)
return false;
@ -215,7 +212,7 @@ guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
}
gint
guid_compare(const GncGUID *guid_1, const GncGUID *guid_2)
guid_compare (const GncGUID *guid_1, const GncGUID *guid_2)
{
boost::uuids::uuid const * g1 {reinterpret_cast<boost::uuids::uuid const *> (guid_1)};
boost::uuids::uuid const * g2 {reinterpret_cast<boost::uuids::uuid const *> (guid_2)};
@ -229,7 +226,7 @@ guid_compare(const GncGUID *guid_1, const GncGUID *guid_2)
guint
guid_hash_to_guint (gconstpointer ptr)
{
const boost::uuids::uuid * guid = reinterpret_cast<const boost::uuids::uuid*>(ptr);
const boost::uuids::uuid * guid = reinterpret_cast<const boost::uuids::uuid*> (ptr);
if (!guid)
{
@ -239,8 +236,8 @@ guid_hash_to_guint (gconstpointer ptr)
guint hash {0};
unsigned retspot {0};
boost::uuids::uuid::const_iterator guidspot {guid->begin()};
while (guidspot != guid->end()){
boost::uuids::uuid::const_iterator guidspot {guid->begin ()};
while (guidspot != guid->end ()){
hash <<= 4;
hash |= *guidspot;
++guidspot;
@ -251,8 +248,8 @@ guid_hash_to_guint (gconstpointer ptr)
gint
guid_g_hash_table_equal (gconstpointer guid_a, gconstpointer guid_b)
{
return guid_equal (reinterpret_cast<const GncGUID*>(guid_a),
reinterpret_cast<const GncGUID*>(guid_b));
return guid_equal (reinterpret_cast<const GncGUID*> (guid_a),
reinterpret_cast<const GncGUID*> (guid_b));
}
GHashTable *
@ -275,7 +272,7 @@ gnc_string_to_guid (const GValue *src, GValue *dest)
as_string = g_value_get_string (src);
guid = g_new0 (GncGUID, 1);
string_to_guid(as_string, guid);
string_to_guid (as_string, guid);
g_value_take_boxed (dest, guid);
}

View File

@ -1,6 +1,7 @@
/********************************************************************\
* guid.h -- globally unique ID User API *
* Copyright (C) 2000 Dave Peticolas <peticola@cs.ucdavis.edu> *
* 2014 Aaron Laws <dartmetrash@gmail.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -29,45 +30,46 @@ extern "C"
{
#endif
typedef struct _gncGuid {
unsigned char reserved[16];
} GncGUID;
#include <stddef.h>
#include <glib-object.h>
/** @addtogroup Entity
@{ */
/** @addtogroup GncGUID
Globally Unique ID's provide a way to uniquely identify
some thing. A GncGUID is a unique, cryptographically
Globally Unique IDs provide a way to uniquely identify
something. A GncGUID is a unique, cryptographically
random 128-bit value. The identifier is so random that
it is safe to assume that there is no other such item
on the planet Earth, and indeed, not even in the Galaxy
or beyond.
QOF GncGUID's can be used independently of any other subsystem
QOF GncGUIDs can be used independently of any other subsystem
in QOF. In particular, they do not require the use of
other parts of the object subsystem. New GncGUID's are usually
created by initialising a new entity using qof_instance_init,
other parts of the object subsystem. New GncGUIDs are usually
created by initializing a new entity using qof_instance_init,
rather than calling GncGUID functions directly.
@{ */
/** @file guid.h
@brief globally unique ID User API
@author Copyright (C) 2000 Dave Peticolas <peticola@cs.ucdavis.edu>
Copyright 2014 Aaron Laws <dartmetrash@gmail.com>
*/
/** The type used to store guids */
#define GUID_DATA_SIZE 16
#define GNC_TYPE_GUID (gnc_guid_get_type())
#define GNC_VALUE_HOLDS_GUID(value) G_VALUE_HOLDS(value, GNC_TYPE_GUID)
/** The type used to store guids */
typedef struct _gncGuid {
unsigned char reserved[GUID_DATA_SIZE];
} GncGUID;
GType gnc_guid_get_type (void);
const GncGUID* gnc_value_get_guid (const GValue *value);
/** number of characters needed to encode a guid as a string
/** Number of characters needed to encode a guid as a string
* not including the null terminator. */
#define GUID_ENCODING_LENGTH 32
@ -84,13 +86,15 @@ void guid_replace (GncGUID *guid);
*/
GncGUID guid_new_return (void);
/** Returns a GncGUID which is guaranteed
to never reference any entity. */
/** Returns a GncGUID which is guaranteed to never reference any entity.
*
* Do not free this value! The same pointer is returned on each call.*/
const GncGUID * guid_null (void);
/**
* Allocate memory for a GUID. The returned pointer must be freed with
* guid_free.
* Allocate memory for a GUID. This does not construct a GUID. In other words,
* the returned pointer has not necessarily been initialized. The returned
* pointer must be freed with * guid_free.
*/
GncGUID * guid_malloc (void);
@ -140,11 +144,15 @@ gchar * guid_to_string (const GncGUID * guid);
gchar * guid_to_string_buff (const GncGUID * guid, /*@ out @*/ gchar *buff);
/** Given a string, decode the id into the guid if guid is non-NULL.
* The function returns TRUE if the string was a valid 32 character
* hexadecimal number. This function accepts both upper and lower case
* hex digits. If the return value is FALSE, the effect on guid is
* undefined. */
/** Given a string, replace the given guid with the parsed one unless
* the given value is null.
* If null is passed as guid or string, false is returned and nothing
* is done, otherwise, the function returns true.
* This function accepts both uppor and lower case hex digits. If
* letters outside the range of [a-fA-F] are passed, they are silently
* replaced. If non-alphanumeric digits are given, this function will
either return false or replace those values with others.
. */
gboolean string_to_guid(const gchar * string, /*@ out @*/ GncGUID * guid);