remove UUIDs as implemention of PBD::ID, use static counter (not finished - counter...
[ardour.git] / libs / pbd / id.cc
1 #include <ostream>
2 #include <iostream>
3 #include <stdio.h>
4
5 #ifndef __STDC_FORMAT_MACROS
6 #define __STDC_FORMAT_MACROS
7 #endif
8 #include <inttypes.h>
9
10 #include <pbd/id.h>
11
12 using namespace std;
13 using namespace PBD;
14
15 Glib::Mutex ID::counter_lock;
16 uint64_t ID::_counter = 0;
17
18 ID::ID ()
19 {
20         Glib::Mutex::Lock lm (counter_lock);
21         id = _counter++;
22 }
23
24 ID::ID (string str)
25 {
26         string_assign (str);
27 }
28
29 int
30 ID::string_assign (string str)
31 {
32         return sscanf (str.c_str(), "%" PRIu64, &id) != 0;
33 }
34
35 void
36 ID::print (char* buf) const
37 {
38         /* XXX sizeof buf is unknown. bad API design */
39         snprintf (buf, 16, "%" PRIu64, id);
40 }
41
42 ID&
43 ID::operator= (string str)
44 {
45         string_assign (str);
46         return *this;
47 }
48
49 ostream&
50 operator<< (ostream& ostr, const ID& id)
51 {
52         char buf[32];
53         id.print (buf);
54         ostr << buf;
55         return ostr;
56 }
57