r3951 - in trunk/birnet: . tests
- From: timj svn gnome org
- To: svn-commits-list gnome org
- Subject: r3951 - in trunk/birnet: . tests
- Date: Mon, 9 Oct 2006 19:17:44 -0400 (EDT)
Author: timj
Date: 2006-10-09 19:17:43 -0400 (Mon, 09 Oct 2006)
New Revision: 3951
Modified:
trunk/birnet/ChangeLog
trunk/birnet/Makefile.am
trunk/birnet/birnet-zintern.cc
trunk/birnet/birnetcdefs.h
trunk/birnet/birnetthread.cc
trunk/birnet/birnetthread.hh
trunk/birnet/birnetutf8.cc
trunk/birnet/birnetutils.cc
trunk/birnet/birnetutils.hh
trunk/birnet/tests/Makefile.am
trunk/birnet/tests/strings.cc
Log:
Mon Oct 9 23:47:30 2006 Tim Janik <timj gtk org>
* birnetcdefs.h: ensure we have FALSE, TRUE, ABS, MIN, MAX, CLAMP,
ARRAY_SIZE and STRFUNC.
* birnetutils.hh: don't publically include glib.h, adapted affected
callers. pre-declare ThreadTable to use atomic functions in class
ReferenceCountImpl.
* birnetutils.hh, birnetutils.cc: added string utilities to convert
strings to and from bool, int, uint, float, double and double vector.
added utilities to convert strings tolower, toupper, totitle, to strip
strings and to print into strings in printf style.
added uuid string test and comparison and errno to string conversion.
* birnet-zintern.cc: conveted somewhat more to C++.
* tests/strings.cc: added uuid string functions tests.
Modified: trunk/birnet/ChangeLog
===================================================================
--- trunk/birnet/ChangeLog 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/ChangeLog 2006-10-09 23:17:43 UTC (rev 3951)
@@ -1,3 +1,22 @@
+Mon Oct 9 23:47:30 2006 Tim Janik <timj gtk org>
+
+ * birnetcdefs.h: ensure we have FALSE, TRUE, ABS, MIN, MAX, CLAMP,
+ ARRAY_SIZE and STRFUNC.
+
+ * birnetutils.hh: don't publically include glib.h, adapted affected
+ callers. pre-declare ThreadTable to use atomic functions in class
+ ReferenceCountImpl.
+
+ * birnetutils.hh, birnetutils.cc: added string utilities to convert
+ strings to and from bool, int, uint, float, double and double vector.
+ added utilities to convert strings tolower, toupper, totitle, to strip
+ strings and to print into strings in printf style.
+ added uuid string test and comparison and errno to string conversion.
+
+ * birnet-zintern.cc: conveted somewhat more to C++.
+
+ * tests/strings.cc: added uuid string functions tests.
+
Mon Oct 9 23:00:39 2006 Tim Janik <timj gtk org>
* birnetutf8.hh, birnetutf8.cc: wrap GLib isalnum() and friends to
Modified: trunk/birnet/Makefile.am
===================================================================
--- trunk/birnet/Makefile.am 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/Makefile.am 2006-10-09 23:17:43 UTC (rev 3951)
@@ -6,6 +6,8 @@
SUBDIRS = . tests
INCLUDES += -I$(top_srcdir) -I$(top_builddir) -I$(srcdir) -I. $(BIRNET_CFLAGS)
+DEFS = -DBIRNET_LOG_DOMAIN=\"BIRNET\"
+
GLIB_MKENUMS = glib-mkenums
birnet_headers = $(strip \
Modified: trunk/birnet/birnet-zintern.cc
===================================================================
--- trunk/birnet/birnet-zintern.cc 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/birnet-zintern.cc 2006-10-09 23:17:43 UTC (rev 3951)
@@ -16,6 +16,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <birnet/birnet.hh>
+#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -23,18 +24,18 @@
namespace Birnet {
-static gboolean use_compression = FALSE;
-static gboolean use_base_name = FALSE;
+static bool use_compression = FALSE;
+static bool use_base_name = FALSE;
typedef struct {
- guint pos;
- gboolean pad;
+ uint pos;
+ bool pad;
} Config;
static Config config_init = { 0, 0 };
static inline void
print_uchar (Config *config,
- guint8 d)
+ uint8 d)
{
if (config->pos > 70)
{
@@ -76,34 +77,32 @@
#define to_upper(c) ((c) >='a' && (c) <='z' ? (c) - 'a' + 'A' : (c))
#define is_alnum(c) (((c) >='A' && (c) <='Z') || ((c) >='a' && (c) <='z') || ((c) >='0' && (c) <='9'))
-static gchar*
-to_cupper (const gchar *istring)
+static String
+to_cupper (const String &str)
{
- gchar *string = g_strdup (istring), *s = string;
- while (*s)
- {
- if (is_alnum (*s))
- *s = to_upper (*s);
- else
- *s = '_';
- s++;
- }
- return string;
+ String s (str);
+ for (uint i = 0; i < s.size(); i++)
+ if (Unichar::isalnum (s[i]))
+ s[i] = Unichar::toupper (s[i]);
+ else
+ s[i] = '_';
+ return s;
}
static void
-gen_zfile (const gchar *name,
- const gchar *file)
+gen_zfile (const char *name,
+ const char *file)
{
+ g_printerr ("note: %s", name);
FILE *f = fopen (file, "r");
- guint8 *data = NULL;
- guint i, dlen = 0, mlen = 0;
+ uint8 *data = NULL;
+ uint i, dlen = 0, mlen = 0;
Bytef *cdata;
uLongf clen;
- gchar *fname = use_base_name ? g_path_get_basename (file) : g_strdup (file);
+ String fname = use_base_name ? Path::basename (file) : file;
Config config;
if (!f)
- g_error ("failed to open \"%s\": %s", file, g_strerror (errno));
+ BIRNET_ERROR ("failed to open \"%s\": %s", file, string_from_errno (errno).c_str());
do
{
if (mlen <= dlen + 1024)
@@ -116,7 +115,7 @@
while (!feof (f));
if (ferror (f))
- g_error ("failed to read from \"%s\": %s", file, g_strerror (errno));
+ BIRNET_ERROR ("failed to read from \"%s\": %s", file, string_from_errno (errno).c_str());
if (use_compression)
{
@@ -141,7 +140,7 @@
break;
}
if (err)
- g_error ("while compressing \"%s\": %s", file, err);
+ BIRNET_ERROR ("while compressing \"%s\": %s", file, err);
}
else
{
@@ -152,29 +151,28 @@
g_print ("/* birnet-zintern file dump of %s */\n", file);
config = config_init;
- printf ("#define %s_NAME \"", to_cupper (name));
- for (i = 0; fname[i]; i++)
+ printf ("#define %s_NAME \"", to_cupper (name).c_str());
+ for (i = 0; i < fname.size(); i++)
print_uchar (&config, fname[i]);
printf ("\"\n");
- printf ("#define %s_SIZE (%u)\n", to_cupper (name), dlen);
+ printf ("#define %s_SIZE (%u)\n", to_cupper (name).c_str(), dlen);
config = config_init;
- printf ("static const unsigned char %s_DATA[%lu + 1] =\n", to_cupper (name), clen);
+ printf ("static const unsigned char %s_DATA[%lu + 1] =\n", to_cupper (name).c_str(), clen);
printf ("( \"");
for (i = 0; i < clen; i++)
print_uchar (&config, cdata[i]);
printf ("\");\n");
fclose (f);
- g_free (fname);
g_free (data);
if (cdata != data)
g_free (cdata);
}
-static gint
-help (gchar *arg)
+static int
+help (char *arg)
{
g_printerr ("usage: birnet-zintern [-h] [-b] [-z] [[name file]...]\n");
g_printerr (" -h Print usage information\n");
@@ -186,8 +184,8 @@
}
extern "C" int
-main (gint argc,
- gchar *argv[])
+main (int argc,
+ char *argv[])
{
GSList *plist = NULL;
Modified: trunk/birnet/birnetcdefs.h
===================================================================
--- trunk/birnet/birnetcdefs.h 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/birnetcdefs.h 2006-10-09 23:17:43 UTC (rev 3951)
@@ -27,11 +27,17 @@
BIRNET_EXTERN_C_BEGIN();
/* --- standard macros --- */
+#ifndef FALSE
+# define FALSE false
+#endif
+#ifndef TRUE
+# define TRUE true
+#endif
#define BIRNET_ABS(a) ((a) > -(a) ? (a) : -(a))
#define BIRNET_MIN(a,b) ((a) <= (b) ? (a) : (b))
#define BIRNET_MAX(a,b) ((a) >= (b) ? (a) : (b))
#define BIRNET_CLAMP(v,mi,ma) ((v) < (mi) ? (mi) : ((v) > (ma) ? (ma) : (v)))
-#ifdef _BIRNET_SOURCE_EXTENSIONS
+#define BIRNET_ARRAY_SIZE(array) (sizeof (array) / sizeof ((array)[0]))
#undef ABS
#define ABS BIRNET_ABS
#undef MIN
@@ -40,9 +46,16 @@
#define MAX BIRNET_MAX
#undef CLAMP
#define CLAMP BIRNET_CLAMP
+#undef ARRAY_SIZE
+#define ARRAY_SIZE BIRNET_ARRAY_SIZE
#undef STRFUNC
-#define STRFUNC G_STRFUNC
-#endif /* _BIRNET_SOURCE_EXTENSIONS */
+#if defined (__GNUC__)
+# define STRFUNC ((const char*) (__PRETTY_FUNCTION__))
+#elif defined (G_HAVE_ISO_VARARGS)
+# define STRFUNC G_STRFUNC /* GLib present */
+#else
+# define STRFUNC ("<unknown>()")
+#endif
/* --- likelyness hinting --- */
#define BIRNET__BOOL(expr) __extension__ ({ bool _birnet__bool; if (expr) _birnet__bool = 1; else _birnet__bool = 0; _birnet__bool; })
@@ -285,8 +298,8 @@
void (*thread_awake_after) (BirnetUInt64 stamp);
void (*thread_emit_wakeups) (BirnetUInt64 wakeup_stamp);
void (*thread_set_wakeup) (BirnetThreadWakeup wakeup_func,
- gpointer wakeup_data,
- GDestroyNotify destroy);
+ void *wakeup_data,
+ void (*destroy_data) (void*));
void (*thread_abort) (BirnetThread *thread);
void (*thread_queue_abort) (BirnetThread *thread);
bool (*thread_aborted) (void);
@@ -302,7 +315,7 @@
void* (*qdata_get) (uint glib_quark);
void (*qdata_set) (uint glib_quark,
void *data,
- GDestroyNotify destroy);
+ void (*destroy_data) (void*));
void* (*qdata_steal) (uint glib_quark);
void (*mutex_init) (BirnetMutex *mutex);
void (*mutex_lock) (BirnetMutex *mutex);
Modified: trunk/birnet/birnetthread.cc
===================================================================
--- trunk/birnet/birnetthread.cc 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/birnetthread.cc 2006-10-09 23:17:43 UTC (rev 3951)
@@ -238,11 +238,11 @@
}
void
-Thread::Self::set_wakeup (BirnetThreadWakeup wakeup_func,
- void *wakeup_data,
- GDestroyNotify destroy)
+Thread::Self::set_wakeup (BirnetThreadWakeup wakeup_func,
+ void *wakeup_data,
+ void (*destroy_data) (void*))
{
- ThreadTable.thread_set_wakeup (wakeup_func, wakeup_data, destroy);
+ ThreadTable.thread_set_wakeup (wakeup_func, wakeup_data, destroy_data);
}
OwnedMutex&
Modified: trunk/birnet/birnetthread.hh
===================================================================
--- trunk/birnet/birnetthread.hh 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/birnetthread.hh 2006-10-09 23:17:43 UTC (rev 3951)
@@ -24,7 +24,6 @@
namespace Birnet {
class Thread;
-extern BirnetThreadTable ThreadTable; /*< private >*/
class Mutex {
BirnetMutex mutex;
@@ -131,9 +130,9 @@
static void awake_after (uint64 stamp);
static void set_wakeup (BirnetThreadWakeup wakeup_func,
void *wakeup_data,
- GDestroyNotify destroy);
+ void (*destroy_data) (void*));
static OwnedMutex& owned_mutex ();
- static void exit (void *retval = NULL) G_GNUC_NORETURN;
+ static void exit (void *retval = NULL) BIRNET_NORETURN;
};
/* DataListContainer API */
template<typename Type> inline void set_data (DataKey<Type> *key,
Modified: trunk/birnet/birnetutf8.cc
===================================================================
--- trunk/birnet/birnetutf8.cc 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/birnetutf8.cc 2006-10-09 23:17:43 UTC (rev 3951)
@@ -17,6 +17,7 @@
* Boston, MA 02111-1307, USA.
*/
#include "birnetutf8.hh"
+#include <glib.h>
namespace Birnet {
namespace Unichar {
Modified: trunk/birnet/birnetutils.cc
===================================================================
--- trunk/birnet/birnetutils.cc 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/birnetutils.cc 2006-10-09 23:17:43 UTC (rev 3951)
@@ -18,6 +18,7 @@
*/
#include <glib.h>
#include "birnetutils.hh"
+#include "birnetutf8.hh"
#include "birnetthread.hh"
#include "birnetmsg.hh"
#include "birnetcpu.hh"
@@ -297,6 +298,265 @@
return result;
}
+/* --- string utils --- */
+String
+string_tolower (const String &str)
+{
+ String s (str);
+ for (uint i = 0; i < s.size(); i++)
+ s[i] = Unichar::tolower (s[i]);
+ return s;
+}
+
+String
+string_toupper (const String &str)
+{
+ String s (str);
+ for (uint i = 0; i < s.size(); i++)
+ s[i] = Unichar::toupper (s[i]);
+ return s;
+}
+
+String
+string_totitle (const String &str)
+{
+ String s (str);
+ for (uint i = 0; i < s.size(); i++)
+ s[i] = Unichar::totitle (s[i]);
+ return s;
+}
+
+String
+string_printf (const char *format,
+ ...)
+{
+ String str;
+ va_list args;
+ va_start (args, format);
+ str = string_vprintf (format, args);
+ va_end (args);
+ return str;
+}
+
+String
+string_vprintf (const char *format,
+ va_list vargs)
+{
+ char *str = NULL;
+ if (vasprintf (&str, format, vargs) == 0 && str)
+ {
+ String s = str;
+ free (str);
+ return s;
+ }
+ else
+ return format;
+}
+
+String
+string_strip (const String &str)
+{
+ const char *cstr = str.c_str();
+ uint start = 0, end = str.size();
+ while (end and strchr (" \t\n\r", cstr[end-1]))
+ end--;
+ while (strchr (" \t\n\r", cstr[start]))
+ start++;
+ return String (cstr + start, end - start);
+}
+
+bool
+string_to_bool (const String &string)
+{
+ static const char *spaces = " \t\n\r";
+ const char *p = string.c_str();
+ /* skip spaces */
+ while (*p && strchr (spaces, *p))
+ p++;
+ /* ignore signs */
+ if (p[0] == '-' || p[0] == '+')
+ {
+ p++;
+ /* skip spaces */
+ while (*p && strchr (spaces, *p))
+ p++;
+ }
+ /* handle numbers */
+ if (p[0] >= '0' && p[0] <= '9')
+ return 0 != string_to_uint (p);
+ /* handle special words */
+ if (strncasecmp (p, "ON", 2) == 0)
+ return 1;
+ if (strncasecmp (p, "OFF", 3) == 0)
+ return 0;
+ /* handle non-numbers */
+ return !(p[0] == 0 ||
+ p[0] == 'f' || p[0] == 'F' ||
+ p[0] == 'n' || p[0] == 'N');
+}
+
+String
+string_from_bool (bool value)
+{
+ return String (value ? "1" : "0");
+}
+
+uint64
+string_to_uint (const String &string,
+ uint base)
+{
+ const char *p = string.c_str();
+ while (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r')
+ p++;
+ bool hex = p[0] == '0' && (p[1] == 'X' || p[1] == 'x');
+ return strtoull (hex ? p + 2 : p, NULL, hex ? 16 : base);
+}
+
+String
+string_from_uint (uint64 value)
+{
+ return string_printf ("%llu", value);
+}
+
+bool
+string_has_int (const String &string)
+{
+ const char *p = string.c_str();
+ while (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r')
+ p++;
+ return p[0] >= '0' && p[0] <= '9';
+}
+
+int64
+string_to_int (const String &string,
+ uint base)
+{
+ const char *p = string.c_str();
+ while (*p == ' ' || *p == '\n' || *p == '\t' || *p == '\r')
+ p++;
+ bool hex = p[0] == '0' && (p[1] == 'X' || p[1] == 'x');
+ return strtoll (hex ? p + 2 : p, NULL, hex ? 16 : base);
+}
+
+String
+string_from_int (int64 value)
+{
+ return string_printf ("%lld", value);
+}
+
+double
+string_to_double (const String &string)
+{
+ return g_ascii_strtod (string.c_str(), NULL);
+}
+
+String
+string_from_float (float value)
+{
+ char numbuf[G_ASCII_DTOSTR_BUF_SIZE + 1] = { 0, };
+ g_ascii_formatd (numbuf, G_ASCII_DTOSTR_BUF_SIZE, "%.7g", value);
+ return String (numbuf);
+}
+
+String
+string_from_double (double value)
+{
+ char numbuf[G_ASCII_DTOSTR_BUF_SIZE + 1] = { 0, };
+ g_ascii_formatd (numbuf, G_ASCII_DTOSTR_BUF_SIZE, "%.17g", value);
+ return String (numbuf);
+}
+
+vector<double>
+string_to_vector (const String &string)
+{
+ vector<double> dvec;
+ const char *spaces = " \t\n";
+ const char *obrace = "{([";
+ const char *delims = ";";
+ const char *cbrace = "])}";
+ const char *number = "+-0123456789eE.,";
+ const char *s = string.c_str();
+ /* skip spaces */
+ while (*s && strchr (spaces, *s))
+ s++;
+ /* skip opening brace */
+ if (*s && strchr (obrace, *s))
+ s++;
+ const char *d = s;
+ while (*d && !strchr (cbrace, *d))
+ {
+ while (*d && strchr (spaces, *d)) /* skip spaces */
+ d++;
+ s = d; /* start of number */
+ if (!*d || (!strchr (number, *d) && /* ... if any */
+ !strchr (delims, *d)))
+ break;
+ while (*d && strchr (number, *d)) /* pass across number */
+ d++;
+ dvec.push_back (string_to_double (String (s, d - s)));
+ while (*d && strchr (spaces, *d)) /* skip spaces */
+ d++;
+ if (*d && strchr (delims, *d))
+ d++; /* eat delimiter */
+ }
+ // printf ("vector: %d: %s\n", dvec.size(), string_from_vector (dvec).c_str());
+ return dvec;
+}
+
+String
+string_from_vector (const vector<double> &dvec,
+ const String &delim)
+{
+ String s;
+ for (uint i = 0; i < dvec.size(); i++)
+ {
+ if (i > 0)
+ s += delim;
+ s += string_from_double (dvec[i]);
+ }
+ return s;
+}
+
+String
+string_from_errno (int errno_val)
+{
+ char buffer[1024] = { 0, };
+ /* strerror_r() is broken on GNU systems, especially if _GNU_SOURCE is defined, so fall back to strerror() */
+ if (strerror_r (errno_val, buffer, sizeof (buffer)) < 0 || !buffer[0])
+ return strerror (errno_val);
+ return buffer;
+}
+
+bool
+string_is_uuid (const String &uuid_string) /* check uuid formatting */
+{
+ int i, l = uuid_string.size();
+ if (l != 36)
+ return false;
+ // 00000000-0000-0000-0000-000000000000
+ for (i = 0; i < l; i++)
+ if (i == 8 || i == 13 || i == 18 || i == 23)
+ {
+ if (uuid_string[i] != '-')
+ return false;
+ continue;
+ }
+ else if ((uuid_string[i] >= '0' && uuid_string[i] <= '9') ||
+ (uuid_string[i] >= 'a' && uuid_string[i] <= 'f') ||
+ (uuid_string[i] >= 'A' && uuid_string[i] <= 'F'))
+ continue;
+ else
+ return false;
+ return true;
+}
+
+int
+string_cmp_uuid (const String &uuid_string1,
+ const String &uuid_string2) /* -1=smaller, 0=equal, +1=greater (assuming valid uuid strings) */
+{
+ return strcasecmp (uuid_string1.c_str(), uuid_string2.c_str()); /* good enough for numeric equality and defines stable order */
+}
+
/* --- file utils --- */
namespace Path {
Modified: trunk/birnet/birnetutils.hh
===================================================================
--- trunk/birnet/birnetutils.hh 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/birnetutils.hh 2006-10-09 23:17:43 UTC (rev 3951)
@@ -19,7 +19,6 @@
#ifndef __BIRNET_UTILS_XX_HH__
#define __BIRNET_UTILS_XX_HH__
-#include <glib.h> // FIXME
#include <birnet/birnetcdefs.h>
#include <string>
#include <vector>
@@ -112,6 +111,56 @@
extern inline void BREAKPOINT() { raise_sigtrap(); }
#endif /* __i386__ */
+/* --- threading implementaiton bit --- */
+extern BirnetThreadTable ThreadTable; /* private, provided by birnetthreadimpl.cc */
+
+/* --- string functionality --- */
+String string_tolower (const String &str);
+String string_toupper (const String &str);
+String string_totitle (const String &str);
+String string_printf (const char *format, ...) BIRNET_PRINTF (1, 2);
+String string_vprintf (const char *format, va_list vargs);
+String string_strip (const String &str);
+bool string_to_bool (const String &string);
+String string_from_bool (bool value);
+uint64 string_to_uint (const String &string, uint base = 10);
+String string_from_uint (uint64 value);
+bool string_has_int (const String &string);
+int64 string_to_int (const String &string, uint base = 10);
+String string_from_int (int64 value);
+String string_from_float (float value);
+double string_to_double (const String &string);
+String string_from_double (double value);
+inline String string_from_float (double value) { return string_from_double (value); }
+inline double string_to_float (const String &string) { return string_to_double (string); }
+template<typename Type> Type string_to_type (const String &string);
+template<typename Type> String string_from_type (Type value);
+template<> inline double string_to_type<double> (const String &string) { return string_to_double (string); }
+template<> inline String string_from_type<double> (double value) { return string_from_double (value); }
+template<> inline float string_to_type<float> (const String &string) { return string_to_float (string); }
+template<> inline String string_from_type<float> (float value) { return string_from_float (value); }
+template<> inline bool string_to_type<bool> (const String &string) { return string_to_bool (string); }
+template<> inline String string_from_type<bool> (bool value) { return string_from_bool (value); }
+template<> inline int16 string_to_type<int16> (const String &string) { return string_to_int (string); }
+template<> inline String string_from_type<int16> (int16 value) { return string_from_int (value); }
+template<> inline uint16 string_to_type<uint16> (const String &string) { return string_to_uint (string); }
+template<> inline String string_from_type<uint16> (uint16 value) { return string_from_uint (value); }
+template<> inline int string_to_type<int> (const String &string) { return string_to_int (string); }
+template<> inline String string_from_type<int> (int value) { return string_from_int (value); }
+template<> inline uint string_to_type<uint> (const String &string) { return string_to_uint (string); }
+template<> inline String string_from_type<uint> (uint value) { return string_from_uint (value); }
+template<> inline int64 string_to_type<int64> (const String &string) { return string_to_int (string); }
+template<> inline String string_from_type<int64> (int64 value) { return string_from_int (value); }
+template<> inline uint64 string_to_type<uint64> (const String &string) { return string_to_uint (string); }
+template<> inline String string_from_type<uint64> (uint64 value) { return string_from_uint (value); }
+vector<double> string_to_vector (const String &string);
+String string_from_vector (const vector<double> &dvec,
+ const String &delim = " ");
+String string_from_errno (int errno_val);
+bool string_is_uuid (const String &uuid_string); /* check uuid formatting */
+int string_cmp_uuid (const String &uuid_string1,
+ const String &uuid_string2); /* -1=smaller, 0=equal, +1=greater (assuming valid uuid strings) */
+
/* --- file/path functionality --- */
namespace Path {
const String dirname (const String &path);
@@ -144,7 +193,7 @@
/* --- cleanup registration --- */
uint cleanup_add (uint timeout_ms,
- GDestroyNotify handler,
+ void (*destroy_data) (void*),
void *data);
void cleanup_force_handlers (void);
@@ -153,8 +202,8 @@
uint32 filler,
uint length);
/* --- memory utils --- */
-void* malloc_aligned (gsize total_size,
- gsize alignment,
+void* malloc_aligned (size_t total_size,
+ size_t alignment,
uint8 **free_pointer);
/* --- C++ demangling --- */
@@ -217,16 +266,12 @@
ref_cas (uint32 oldv,
uint32 newv) const
{
-#if GLIB_CHECK_VERSION (2, 9, 1)
- return g_atomic_int_compare_and_exchange ((volatile int*) &ref_field, oldv, newv);
-#else
- return g_atomic_int_compare_and_exchange ((int*) &ref_field, oldv, newv);
-#endif
+ return ThreadTable.atomic_uint_cas (&ref_field, oldv, newv);
}
inline uint32
ref_get() const
{
- return g_atomic_int_get ((volatile int*) &ref_field);
+ return ThreadTable.atomic_uint_get (&ref_field);
}
protected:
inline uint32
Modified: trunk/birnet/tests/Makefile.am
===================================================================
--- trunk/birnet/tests/Makefile.am 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/tests/Makefile.am 2006-10-09 23:17:43 UTC (rev 3951)
@@ -5,7 +5,7 @@
include $(top_srcdir)/Makefile.decl
INCLUDES += -I$(top_srcdir) -I$(top_builddir) -I. $(BIRNET_CFLAGS)
-DEFS += -DG_LOG_DOMAIN='"$(basename $(@F))"' -DPARANOID -DG_DISABLE_CONST_RETURNS
+DEFS += -DBIRNET_LOG_DOMAIN='"$(basename $(@F))"' -DPARANOID -DG_DISABLE_CONST_RETURNS
TESTS =
noinst_PROGRAMS = $(TESTS)
Modified: trunk/birnet/tests/strings.cc
===================================================================
--- trunk/birnet/tests/strings.cc 2006-10-09 21:08:01 UTC (rev 3950)
+++ trunk/birnet/tests/strings.cc 2006-10-09 23:17:43 UTC (rev 3951)
@@ -194,6 +194,48 @@
TDONE();
}
+static void
+uuid_tests (void)
+{
+ TSTART ("uuid string test");
+ TASSERT (string_is_uuid ("00000000-0000-0000-0000-000000000000") == true);
+ TASSERT (string_is_uuid ("6ba7b812-9dad-11d1-80b4-00c04fd430c8") == true);
+ TASSERT (string_is_uuid ("6BA7B812-9DAD-11D1-80B4-00C04FD430C8") == true);
+ TASSERT (string_is_uuid ("a425fd92-4f06-11db-aea9-000102e7e309") == true);
+ TASSERT (string_is_uuid ("A425FD92-4F06-11DB-AEA9-000102E7E309") == true);
+ TASSERT (string_is_uuid ("dc380602-a739-4be1-a5cb-53c437ffe39f") == true);
+ TASSERT (string_is_uuid ("DC380602-A739-4BE1-A5CB-53C437FFE39F") == true);
+ // TASSERT (string_is_uuid (NULL) == false);
+ TASSERT (string_is_uuid ("") == false);
+ TASSERT (string_is_uuid ("gba7b812-9dad-11d1-80b4-00c04fd430c8") == false);
+ TASSERT (string_is_uuid ("Gba7b812-9dad-11d1-80b4-00c04fd430c8") == false);
+ TASSERT (string_is_uuid ("6ba7b812.9dad-11d1-80b4-00c04fd430c8") == false);
+ TASSERT (string_is_uuid ("6ba7b812-9dad.11d1-80b4-00c04fd430c8") == false);
+ TASSERT (string_is_uuid ("6ba7b812-9dad-11d1.80b4-00c04fd430c8") == false);
+ TASSERT (string_is_uuid ("6ba7b812-9dad-11d1-80b4.00c04fd430c8") == false);
+ TASSERT (string_is_uuid ("6ba7b812-9dad-11d1-80b4-00c04fd430c8-") == false);
+ TASSERT (string_is_uuid ("6ba7b812-9dad-11d1-80b4-00c04fd430c80") == false);
+ TASSERT (string_is_uuid ("6ba7b812-9dad-11d1-80b4-00c04fd430c") == false);
+ TDONE();
+ TSTART ("uuid string cmp");
+ TASSERT (string_cmp_uuid ("00000000-0000-0000-0000-000000000000", "A425FD92-4F06-11DB-AEA9-000102E7E309") < 0);
+ TASSERT (string_cmp_uuid ("A425FD92-4F06-11DB-AEA9-000102E7E309", "00000000-0000-0000-0000-000000000000") > 0);
+ TASSERT (string_cmp_uuid ("00000000-0000-0000-0000-000000000000", "6ba7b812-9dad-11d1-80b4-00c04fd430c8") < 0);
+ TASSERT (string_cmp_uuid ("6BA7B812-9DAD-11D1-80B4-00C04FD430C8", "00000000-0000-0000-0000-000000000000") > 0);
+ TASSERT (string_cmp_uuid ("00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000") == 0);
+ TASSERT (string_cmp_uuid ("6BA7B812-9DAD-11D1-80B4-00C04FD430C8", "A425FD92-4F06-11DB-AEA9-000102E7E309") < 0);
+ TASSERT (string_cmp_uuid ("6ba7b812-9dad-11d1-80b4-00c04fd430c8", "A425FD92-4F06-11DB-AEA9-000102E7E309") < 0);
+ TASSERT (string_cmp_uuid ("6BA7B812-9DAD-11D1-80B4-00C04FD430C8", "a425fd92-4f06-11db-aea9-000102e7e309") < 0);
+ TASSERT (string_cmp_uuid ("6ba7b812-9dad-11d1-80b4-00c04fd430c8", "a425fd92-4f06-11db-aea9-000102e7e309") < 0);
+ TASSERT (string_cmp_uuid ("A425FD92-4F06-11DB-AEA9-000102E7E309", "a425fd92-4f06-11db-aea9-000102e7e309") == 0);
+ TASSERT (string_cmp_uuid ("6ba7b812-9DAD-11d1-80B4-00c04fd430c8", "6BA7B812-9dad-11D1-80b4-00C04FD430C8") == 0);
+ TASSERT (string_cmp_uuid ("A425FD92-4F06-11DB-AEA9-000102E7E309", "6BA7B812-9DAD-11D1-80B4-00C04FD430C8") > 0);
+ TASSERT (string_cmp_uuid ("A425FD92-4F06-11DB-AEA9-000102E7E309", "6ba7b812-9dad-11d1-80b4-00c04fd430c8") > 0);
+ TASSERT (string_cmp_uuid ("a425fd92-4f06-11db-aea9-000102e7e309", "6BA7B812-9DAD-11D1-80B4-00C04FD430C8") > 0);
+ TASSERT (string_cmp_uuid ("a425fd92-4f06-11db-aea9-000102e7e309", "6ba7b812-9dad-11d1-80b4-00c04fd430c8") > 0);
+ TDONE();
+}
+
} // Anon
int
@@ -202,6 +244,7 @@
{
birnet_init_test (&argc, &argv);
+ uuid_tests();
random_unichar_test();
random_tf8_and_unichar_test();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]