2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2015-10-04 14:51:05 -04:00
|
|
|
Copyright (C) 2000-2007 Paul Davis
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/id.h"
|
2015-08-14 05:56:53 -04:00
|
|
|
#include "pbd/string_convert.h"
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace PBD;
|
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex* ID::counter_lock = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
uint64_t ID::_counter = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
ID::init ()
|
|
|
|
{
|
2017-05-05 07:18:06 -04:00
|
|
|
if (!counter_lock) {
|
2012-07-25 13:48:55 -04:00
|
|
|
counter_lock = new Glib::Threads::Mutex;
|
2017-05-05 07:18:06 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ID::ID ()
|
|
|
|
{
|
2011-10-18 09:18:47 -04:00
|
|
|
reset ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2010-02-08 14:37:30 -05:00
|
|
|
ID::ID (const ID& other)
|
|
|
|
{
|
|
|
|
_id = other._id;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
ID::ID (string str)
|
|
|
|
{
|
2017-05-05 07:18:06 -04:00
|
|
|
/* danger, will robinson: could result in non-unique ID */
|
2008-06-02 17:41:35 -04:00
|
|
|
string_assign (str);
|
|
|
|
}
|
|
|
|
|
2017-05-05 07:18:06 -04:00
|
|
|
ID::ID (uint64_t n)
|
|
|
|
{
|
|
|
|
/* danger, will robinson: could result in non-unique ID */
|
|
|
|
_id = n;
|
|
|
|
}
|
|
|
|
|
2011-10-18 09:18:47 -04:00
|
|
|
void
|
|
|
|
ID::reset ()
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (*counter_lock);
|
2017-05-05 07:18:06 -04:00
|
|
|
_id = ++_counter;
|
2015-10-05 10:17:49 -04:00
|
|
|
}
|
2011-10-18 09:18:47 -04:00
|
|
|
|
2015-08-14 05:56:53 -04:00
|
|
|
bool
|
2008-06-02 17:41:35 -04:00
|
|
|
ID::string_assign (string str)
|
|
|
|
{
|
2015-08-14 05:56:53 -04:00
|
|
|
return string_to_uint64 (str, _id);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2015-08-14 05:56:53 -04:00
|
|
|
std::string
|
|
|
|
ID::to_s () const
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2015-08-14 05:56:53 -04:00
|
|
|
return to_string (_id);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-05-13 17:34:09 -04:00
|
|
|
bool
|
|
|
|
ID::operator== (const string& str) const
|
|
|
|
{
|
2015-08-14 05:56:53 -04:00
|
|
|
return to_string (_id) == str;
|
2009-05-13 17:34:09 -04:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
ID&
|
|
|
|
ID::operator= (string str)
|
|
|
|
{
|
|
|
|
string_assign (str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-02-08 14:37:30 -05:00
|
|
|
ID&
|
|
|
|
ID::operator= (const ID& other)
|
|
|
|
{
|
|
|
|
if (&other != this) {
|
|
|
|
_id = other._id;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
ostream&
|
2015-08-14 05:56:53 -04:00
|
|
|
operator<< (ostream& ostr, const ID& id)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2015-08-14 05:56:53 -04:00
|
|
|
ostr << id.to_s();
|
2008-06-02 17:41:35 -04:00
|
|
|
return ostr;
|
|
|
|
}
|
|
|
|
|