Remove LocaleGuard from ARDOUR::Route class
[ardour.git] / libs / pbd / id.cc
index d7ac1560a1c6698f7b37f0d18ec4531b04ceace4..bc119b13dcb88e2db6583cdf37488bff410db9ef 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2007 Paul Davis 
+    Copyright (C) 2000-2007 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 */
 
 #include <ostream>
-#include <iostream>
 #include <stdio.h>
 
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
-#endif
-#include <inttypes.h>
-
 #include "pbd/id.h"
+#include "pbd/string_convert.h"
+
 #include <string>
 
 using namespace std;
 using namespace PBD;
 
-Glib::Mutex* ID::counter_lock = 0;
+Glib::Threads::Mutex* ID::counter_lock = 0;
 uint64_t ID::_counter = 0;
 
 void
 ID::init ()
 {
-       if (!counter_lock)
-               counter_lock = new Glib::Mutex;
+       if (!counter_lock) {
+               counter_lock = new Glib::Threads::Mutex;
+       }
 }
 
 ID::ID ()
@@ -54,39 +51,39 @@ ID::ID (const ID& other)
 
 ID::ID (string str)
 {
+       /* danger, will robinson: could result in non-unique ID */
        string_assign (str);
 }
 
-void
-ID::reset ()
+ID::ID (uint64_t n)
 {
-       Glib::Mutex::Lock lm (*counter_lock);
-       _id = _counter++;
-}      
+       /* danger, will robinson: could result in non-unique ID */
+       _id = n;
+}
 
-int
-ID::string_assign (string str)
+void
+ID::reset ()
 {
-       return sscanf (str.c_str(), "%" PRIu64, &_id) != 0;
+       Glib::Threads::Mutex::Lock lm (*counter_lock);
+       _id = ++_counter;
 }
 
-void
-ID::print (char* buf, uint32_t bufsize) const
+bool
+ID::string_assign (string str)
 {
-       snprintf (buf, bufsize, "%" PRIu64, _id);
+       return string_to_uint64 (str, _id);
 }
 
-string ID::to_s() const
+std::string
+ID::to_s () const
 {
-    char buf[32]; // see print()
-    print(buf, sizeof (buf));
-    return string(buf);
+       return to_string (_id);
 }
 
 bool
 ID::operator== (const string& str) const
 {
-       return to_s() == str;
+       return to_string (_id) == str;
 }
 
 ID&
@@ -106,11 +103,9 @@ ID::operator= (const ID& other)
 }
 
 ostream&
-operator<< (ostream& ostr, const ID& _id)
+operator<< (ostream& ostr, const ID& id)
 {
-       char buf[32];
-       _id.print (buf, sizeof (buf));
-       ostr << buf;
+       ostr << id.to_s();
        return ostr;
 }