2006-08-03 22:18:45 -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 10:15:05 -04:00
|
|
|
#include <string>
|
2006-08-03 22:18:45 -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);
|
|
|
|
id = _counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID::ID (string str)
|
|
|
|
{
|
|
|
|
string_assign (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID::string_assign (string str)
|
|
|
|
{
|
|
|
|
return sscanf (str.c_str(), "%" PRIu64, &id) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ID::print (char* buf) const
|
|
|
|
{
|
|
|
|
/* XXX sizeof buf is unknown. bad API design */
|
|
|
|
snprintf (buf, 16, "%" PRIu64, id);
|
|
|
|
}
|
|
|
|
|
2006-08-09 10:15:05 -04:00
|
|
|
string ID::to_s() const
|
|
|
|
{
|
|
|
|
char buf[16]; // see print()
|
|
|
|
print(buf);
|
|
|
|
return string(buf);
|
|
|
|
}
|
|
|
|
|
2006-08-03 22:18:45 -04:00
|
|
|
ID&
|
|
|
|
ID::operator= (string str)
|
|
|
|
{
|
|
|
|
string_assign (str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ostream&
|
|
|
|
operator<< (ostream& ostr, const ID& id)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
id.print (buf);
|
|
|
|
ostr << buf;
|
|
|
|
return ostr;
|
|
|
|
}
|
|
|
|
|