summaryrefslogtreecommitdiff
path: root/libs/pbd/id.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2006-07-07 23:51:30 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2006-07-07 23:51:30 +0000
commit8b46567e0677eb25c965ed46b80da8808fa33b2b (patch)
treef34e3d1cbdab142e7f155d981fee5fb56a82c431 /libs/pbd/id.cc
parent6f2e8de6a05d9d52069fa1f95c3264b5f151df5f (diff)
id_t becomes a fully-fledged object, UUID's used for IDs, generic MIDI now owns bindings, MIDI binding concept removed from libardour itself in favor of generic Controllables
git-svn-id: svn://localhost/ardour2/trunk@669 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/id.cc')
-rw-r--r--libs/pbd/id.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/libs/pbd/id.cc b/libs/pbd/id.cc
new file mode 100644
index 0000000000..57ddb5b128
--- /dev/null
+++ b/libs/pbd/id.cc
@@ -0,0 +1,75 @@
+#include <ostream>
+#include <iostream>
+
+#include <string.h>
+#include <uuid/uuid.h>
+
+#include <pbd/id.h>
+
+using namespace std;
+using namespace PBD;
+
+ID::ID ()
+{
+ uuid_generate (id);
+}
+
+ID::ID (string str)
+{
+ string_assign (str);
+}
+
+int
+ID::string_assign (string str)
+{
+ /* first check for old-style all-numeric ID's */
+
+ if (strcspn (str.c_str(), "0123456789") == 0) {
+ /* all chars are numeric. just render the existing ID into the space in
+ which we would otherwise store a UUID.
+ */
+
+ memset (id, ' ', sizeof (id));
+ snprintf ((char*) id, sizeof (id), str.c_str());
+
+ } else {
+
+ /* OK, its UUID, probably */
+
+ if (uuid_parse (str.c_str(), id)) {
+ /* XXX error */
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+void
+ID::print (char* buf) const
+{
+ uuid_unparse (id, buf);
+}
+
+ID&
+ID::operator= (string str)
+{
+ string_assign (str);
+ return *this;
+}
+
+bool
+ID::operator== (const ID& other) const
+{
+ return memcmp (id, other.id, sizeof (id)) == 0;
+}
+
+ostream&
+operator<< (ostream& ostr, const ID& id)
+{
+ char buf[37];
+ id.print (buf);
+ ostr << buf;
+ return ostr;
+}
+