Optimize automation-event process splitting
[ardour.git] / libs / pbd / id.cc
index 24cf02ab2ea6f2a0d9591355cb04e2d452a969d4..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 <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;
@@ -37,8 +34,9 @@ uint64_t ID::_counter = 0;
 void
 ID::init ()
 {
-       if (!counter_lock)
+       if (!counter_lock) {
                counter_lock = new Glib::Threads::Mutex;
+       }
 }
 
 ID::ID ()
@@ -53,39 +51,39 @@ ID::ID (const ID& other)
 
 ID::ID (string str)
 {
+       /* danger, will robinson: could result in non-unique ID */
        string_assign (str);
 }
 
+ID::ID (uint64_t n)
+{
+       /* danger, will robinson: could result in non-unique ID */
+       _id = n;
+}
+
 void
 ID::reset ()
 {
        Glib::Threads::Mutex::Lock lm (*counter_lock);
-       _id = _counter++;
-}      
-
-int
-ID::string_assign (string str)
-{
-       return sscanf (str.c_str(), "%" PRIu64, &_id) != 0;
+       _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&
@@ -105,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;
 }