Remove ancient, unmaintained xcode project files
[ardour.git] / libs / pbd / id.cc
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 #include "pbd/id.h"
24 #include "pbd/string_convert.h"
25
26 #include <string>
27
28 using namespace std;
29 using namespace PBD;
30
31 Glib::Threads::Mutex* ID::counter_lock = 0;
32 uint64_t ID::_counter = 0;
33
34 void
35 ID::init ()
36 {
37         if (!counter_lock) {
38                 counter_lock = new Glib::Threads::Mutex;
39         }
40 }
41
42 ID::ID ()
43 {
44         reset ();
45 }
46
47 ID::ID (const ID& other)
48 {
49         _id = other._id;
50 }
51
52 ID::ID (string str)
53 {
54         /* danger, will robinson: could result in non-unique ID */
55         string_assign (str);
56 }
57
58 ID::ID (uint64_t n)
59 {
60         /* danger, will robinson: could result in non-unique ID */
61         _id = n;
62 }
63
64 void
65 ID::reset ()
66 {
67         Glib::Threads::Mutex::Lock lm (*counter_lock);
68         _id = ++_counter;
69 }
70
71 bool
72 ID::string_assign (string str)
73 {
74         return string_to_uint64 (str, _id);
75 }
76
77 std::string
78 ID::to_s () const
79 {
80         return to_string (_id);
81 }
82
83 bool
84 ID::operator== (const string& str) const
85 {
86         return to_string (_id) == str;
87 }
88
89 ID&
90 ID::operator= (string str)
91 {
92         string_assign (str);
93         return *this;
94 }
95
96 ID&
97 ID::operator= (const ID& other)
98 {
99         if (&other != this) {
100                 _id = other._id;
101         }
102         return *this;
103 }
104
105 ostream&
106 operator<< (ostream& ostr, const ID& id)
107 {
108         ostr << id.to_s();
109         return ostr;
110 }
111