2006-07-13 23:43:32 -04:00
|
|
|
#include <ostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
|
#endif
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include <pbd/id.h>
|
2006-08-09 21:22:45 -04:00
|
|
|
#include <string>
|
2006-07-13 23:43:32 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace PBD;
|
|
|
|
|
|
|
|
Glib::Mutex* ID::counter_lock = 0;
|
|
|
|
uint64_t ID::_counter = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
ID::init ()
|
|
|
|
{
|
|
|
|
counter_lock = new Glib::Mutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID::ID ()
|
|
|
|
{
|
|
|
|
Glib::Mutex::Lock lm (*counter_lock);
|
2006-08-24 03:37:17 -04:00
|
|
|
_id = _counter++;
|
2006-07-13 23:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ID::ID (string str)
|
|
|
|
{
|
|
|
|
string_assign (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID::string_assign (string str)
|
|
|
|
{
|
2006-08-24 03:37:17 -04:00
|
|
|
return sscanf (str.c_str(), "%" PRIu64, &_id) != 0;
|
2006-07-13 23:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-21 15:01:50 -04:00
|
|
|
ID::print (char* buf, uint32_t bufsize) const
|
2006-07-13 23:43:32 -04:00
|
|
|
{
|
2006-10-21 15:01:50 -04:00
|
|
|
snprintf (buf, bufsize, "%" PRIu64, _id);
|
2006-07-13 23:43:32 -04:00
|
|
|
}
|
|
|
|
|
2006-08-09 21:22:45 -04:00
|
|
|
string ID::to_s() const
|
|
|
|
{
|
2006-10-21 15:01:50 -04:00
|
|
|
char buf[32]; // see print()
|
|
|
|
print(buf, sizeof (buf));
|
2006-08-09 21:22:45 -04:00
|
|
|
return string(buf);
|
|
|
|
}
|
|
|
|
|
2006-07-13 23:43:32 -04:00
|
|
|
ID&
|
|
|
|
ID::operator= (string str)
|
|
|
|
{
|
|
|
|
string_assign (str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ostream&
|
2006-08-24 03:37:17 -04:00
|
|
|
operator<< (ostream& ostr, const ID& _id)
|
2006-07-13 23:43:32 -04:00
|
|
|
{
|
|
|
|
char buf[32];
|
2006-10-21 15:01:50 -04:00
|
|
|
_id.print (buf, sizeof (buf));
|
2006-07-13 23:43:32 -04:00
|
|
|
ostr << buf;
|
|
|
|
return ostr;
|
|
|
|
}
|
|
|
|
|