ardour
id.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000-2007 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #include <ostream>
21 #include <stdio.h>
22 
23 #ifndef __STDC_FORMAT_MACROS
24 #define __STDC_FORMAT_MACROS
25 #endif
26 #include <inttypes.h>
27 
28 #include "pbd/id.h"
29 #include <string>
30 
31 using namespace std;
32 using namespace PBD;
33 
34 Glib::Threads::Mutex* ID::counter_lock = 0;
35 uint64_t ID::_counter = 0;
36 
37 void
39 {
40  if (!counter_lock)
41  counter_lock = new Glib::Threads::Mutex;
42 }
43 
44 ID::ID ()
45 {
46  reset ();
47 }
48 
49 ID::ID (const ID& other)
50 {
51  _id = other._id;
52 }
53 
54 ID::ID (string str)
55 {
56  string_assign (str);
57 }
58 
59 void
60 ID::reset ()
61 {
62  Glib::Threads::Mutex::Lock lm (*counter_lock);
63  _id = _counter++;
64 }
65 
66 int
67 ID::string_assign (string str)
68 {
69  return sscanf (str.c_str(), "%" PRIu64, &_id) != 0;
70 }
71 
72 void
73 ID::print (char* buf, uint32_t bufsize) const
74 {
75  snprintf (buf, bufsize, "%" PRIu64, _id);
76 }
77 
78 string ID::to_s() const
79 {
80  char buf[32]; // see print()
81  print(buf, sizeof (buf));
82  return string(buf);
83 }
84 
85 bool
86 ID::operator== (const string& str) const
87 {
88  return to_s() == str;
89 }
90 
91 ID&
92 ID::operator= (string str)
93 {
94  string_assign (str);
95  return *this;
96 }
97 
98 ID&
99 ID::operator= (const ID& other)
100 {
101  if (&other != this) {
102  _id = other._id;
103  }
104  return *this;
105 }
106 
107 ostream&
108 operator<< (ostream& ostr, const ID& _id)
109 {
110  char buf[32];
111  _id.print (buf, sizeof (buf));
112  ostr << buf;
113  return ostr;
114 }
115 
Definition: Beats.hpp:239
Definition: id.h:32
void print(char *buf, uint32_t bufsize) const
Definition: id.cc:73
bool operator==(const RouteProcessorSelection &a, const RouteProcessorSelection &b)
Definition: debug.h:30
ostream & operator<<(ostream &ostr, const ID &_id)
Definition: id.cc:108
LIBARDOUR_API bool init(bool with_vst, bool try_optimization, const char *localedir)
Definition: globals.cc:376
uint64_t _id
Definition: id.h:65