remove UUIDs as implemention of PBD::ID, use static counter (not finished - counter state not saved)

git-svn-id: svn://localhost/ardour2/trunk@671 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2006-07-08 13:26:07 +00:00
parent eaf5d6d21f
commit 3dec68cd6b
5 changed files with 32 additions and 49 deletions

View file

@ -453,15 +453,6 @@ conf = Configure (libraries['flac'])
conf.CheckLib ('FLAC', 'FLAC__stream_decoder_new') conf.CheckLib ('FLAC', 'FLAC__stream_decoder_new')
libraries['flac'] = conf.Finish () libraries['flac'] = conf.Finish ()
#
# Check for UUID stuff
libraries['uuid'] = LibraryInfo ()
conf = Configure (libraries['uuid'])
conf.CheckLib ('uuid', 'uuid_generate')
libraries['uuid'] = conf.Finish ()
# #
# Check for liblo # Check for liblo

View file

@ -42,7 +42,6 @@ gtkardour.Merge ([
libraries['gdkmm2'], libraries['gdkmm2'],
libraries['sigc2'], libraries['sigc2'],
libraries['gtk2'], libraries['gtk2'],
libraries['uuid'],
libraries['xml'], libraries['xml'],
libraries['xslt'], libraries['xslt'],
libraries['soundtouch'], libraries['soundtouch'],

View file

@ -50,7 +50,6 @@ if conf.CheckCHeader('execinfo.h'):
pbd = conf.Finish() pbd = conf.Finish()
pbd.Merge ([ libraries['sigc2'], pbd.Merge ([ libraries['sigc2'],
libraries['uuid'],
libraries['xml'], libraries['xml'],
libraries['glibmm2'], libraries['glibmm2'],
libraries['glib2'] ]) libraries['glib2'] ])

View file

@ -1,17 +1,24 @@
#include <ostream> #include <ostream>
#include <iostream> #include <iostream>
#include <stdio.h>
#include <string.h> #ifndef __STDC_FORMAT_MACROS
#include <uuid/uuid.h> #define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#include <pbd/id.h> #include <pbd/id.h>
using namespace std; using namespace std;
using namespace PBD; using namespace PBD;
Glib::Mutex ID::counter_lock;
uint64_t ID::_counter = 0;
ID::ID () ID::ID ()
{ {
uuid_generate (id); Glib::Mutex::Lock lm (counter_lock);
id = _counter++;
} }
ID::ID (string str) ID::ID (string str)
@ -22,33 +29,14 @@ ID::ID (string str)
int int
ID::string_assign (string str) ID::string_assign (string str)
{ {
/* first check for old-style all-numeric ID's */ return sscanf (str.c_str(), "%" PRIu64, &id) != 0;
if (strcspn (str.c_str(), "0123456789") == 0) {
/* all chars are numeric. just render the existing ID into the space in
which we would otherwise store a UUID.
*/
memset (id, ' ', sizeof (id));
snprintf ((char*) id, sizeof (id), str.c_str());
} else {
/* OK, its UUID, probably */
if (uuid_parse (str.c_str(), id)) {
/* XXX error */
return -1;
}
}
return 0;
} }
void void
ID::print (char* buf) const ID::print (char* buf) const
{ {
uuid_unparse (id, buf); /* XXX sizeof buf is unknown. bad API design */
snprintf (buf, 16, "%" PRIu64, id);
} }
ID& ID&
@ -58,16 +46,10 @@ ID::operator= (string str)
return *this; return *this;
} }
bool
ID::operator== (const ID& other) const
{
return memcmp (id, other.id, sizeof (id)) == 0;
}
ostream& ostream&
operator<< (ostream& ostr, const ID& id) operator<< (ostream& ostr, const ID& id)
{ {
char buf[37]; char buf[32];
id.print (buf); id.print (buf);
ostr << buf; ostr << buf;
return ostr; return ostr;

View file

@ -1,9 +1,11 @@
#ifndef __pbd_id_h__ #ifndef __pbd_id_h__
#define __pbd_id_h__ #define __pbd_id_h__
#include <uuid/uuid.h> #include <stdint.h>
#include <string> #include <string>
#include <glibmm/thread.h>
namespace PBD { namespace PBD {
class ID { class ID {
@ -11,21 +13,31 @@ class ID {
ID (); ID ();
ID (std::string); ID (std::string);
bool operator== (const ID& other) const; bool operator== (const ID& other) const {
bool operator!= (const ID& other) const { return id == other.id;
return !operator== (other);
} }
bool operator!= (const ID& other) const {
return id != other.id;
}
ID& operator= (std::string); ID& operator= (std::string);
bool operator< (const ID& other) const { bool operator< (const ID& other) const {
return memcmp (id, other.id, sizeof (id)) < 0; return id < other.id;
} }
void print (char* buf) const; void print (char* buf) const;
static uint64_t counter() { return _counter; }
static void init_counter (uint64_t val) { _counter = val; }
private: private:
uuid_t id; uint64_t id;
int string_assign (std::string); int string_assign (std::string);
static Glib::Mutex counter_lock;
static uint64_t _counter;
}; };
} }