Remove PBD::to_string() function from pbd/convert.h
[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 ID::ID ()
42 {
43         reset ();
44 }
45
46 ID::ID (const ID& other)
47 {
48         _id = other._id;
49 }
50
51 ID::ID (string str)
52 {
53         string_assign (str);
54 }
55
56 void
57 ID::reset ()
58 {
59         Glib::Threads::Mutex::Lock lm (*counter_lock);
60         _id = _counter++;
61 }
62
63 bool
64 ID::string_assign (string str)
65 {
66         return string_to_uint64 (str, _id);
67 }
68
69 std::string
70 ID::to_s () const
71 {
72         return to_string (_id);
73 }
74
75 bool
76 ID::operator== (const string& str) const
77 {
78         return to_string (_id) == str;
79 }
80
81 ID&
82 ID::operator= (string str)
83 {
84         string_assign (str);
85         return *this;
86 }
87
88 ID&
89 ID::operator= (const ID& other)
90 {
91         if (&other != this) {
92                 _id = other._id;
93         }
94         return *this;
95 }
96
97 ostream&
98 operator<< (ostream& ostr, const ID& id)
99 {
100         ostr << id.to_s();
101         return ostr;
102 }
103