Use PBD string conversion functions in PBD::ID instead of snprintf
[ardour.git] / libs / pbd / id.cc
index 9b04c88e656a83e55396af656ffcb05bbf82878d..6898da2d123177fba4c1d8ee49fcc761ea5644e2 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 <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;
+               counter_lock = new Glib::Threads::Mutex;
 }
 
 ID::ID ()
@@ -59,14 +61,14 @@ ID::ID (string str)
 void
 ID::reset ()
 {
-       Glib::Mutex::Lock lm (*counter_lock);
+       Glib::Threads::Mutex::Lock lm (*counter_lock);
        _id = _counter++;
-}      
+}
 
-int
+bool
 ID::string_assign (string str)
 {
-       return sscanf (str.c_str(), "%" PRIu64, &_id) != 0;
+       return string_to_uint64 (str, _id);
 }
 
 void
@@ -75,17 +77,16 @@ ID::print (char* buf, uint32_t bufsize) const
        snprintf (buf, bufsize, "%" PRIu64, _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&
@@ -105,11 +106,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;
 }