Generic MIDI control now saves+restores its state; PBD::ID now requires a buffer...
[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 #include <string>
12
13 using namespace std;
14 using namespace PBD;
15
16 Glib::Mutex* ID::counter_lock = 0;
17 uint64_t ID::_counter = 0;
18
19 void
20 ID::init ()
21 {
22         counter_lock = new Glib::Mutex;
23 }
24
25 ID::ID ()
26 {
27         Glib::Mutex::Lock lm (*counter_lock);
28         _id = _counter++;
29 }
30
31 ID::ID (string str)
32 {
33         string_assign (str);
34 }
35
36 int
37 ID::string_assign (string str)
38 {
39         return sscanf (str.c_str(), "%" PRIu64, &_id) != 0;
40 }
41
42 void
43 ID::print (char* buf, uint32_t bufsize) const
44 {
45         snprintf (buf, bufsize, "%" PRIu64, _id);
46 }
47
48 string ID::to_s() const
49 {
50     char buf[32]; // see print()
51     print(buf, sizeof (buf));
52     return string(buf);
53 }
54
55 ID&
56 ID::operator= (string str)
57 {
58         string_assign (str);
59         return *this;
60 }
61
62 ostream&
63 operator<< (ostream& ostr, const ID& _id)
64 {
65         char buf[32];
66         _id.print (buf, sizeof (buf));
67         ostr << buf;
68         return ostr;
69 }
70