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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __pbd_id_h__
|
|
|
|
#define __pbd_id_h__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
#include <glibmm/threads.h>
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-10-16 23:30:28 -04:00
|
|
|
#include "pbd/libpbd_visibility.h"
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
namespace PBD {
|
|
|
|
|
2016-04-12 11:03:44 -04:00
|
|
|
/** a unique ID to identify objects numerically */
|
2013-10-16 23:30:28 -04:00
|
|
|
class LIBPBD_API ID {
|
2008-06-02 17:41:35 -04:00
|
|
|
public:
|
|
|
|
ID ();
|
|
|
|
ID (std::string);
|
2010-02-08 14:37:30 -05:00
|
|
|
ID (const ID&);
|
|
|
|
|
2011-10-18 09:18:47 -04:00
|
|
|
void reset ();
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool operator== (const ID& other) const {
|
2015-10-04 14:51:05 -04:00
|
|
|
return _id == other._id;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!= (const ID& other) const {
|
|
|
|
return _id != other._id;
|
|
|
|
}
|
|
|
|
|
2009-05-13 17:34:09 -04:00
|
|
|
bool operator== (const std::string&) const;
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
ID& operator= (std::string);
|
|
|
|
ID& operator= (const ID&);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
bool operator< (const ID& other) const {
|
|
|
|
return _id < other._id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print (char* buf, uint32_t bufsize) const;
|
|
|
|
std::string to_s() const;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
static uint64_t counter() { return _counter; }
|
|
|
|
static void init_counter (uint64_t val) { _counter = val; }
|
|
|
|
static void init ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint64_t _id;
|
|
|
|
int string_assign (std::string);
|
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
static Glib::Threads::Mutex* counter_lock;
|
2008-06-02 17:41:35 -04:00
|
|
|
static uint64_t _counter;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2013-10-16 23:30:28 -04:00
|
|
|
|
|
|
|
LIBPBD_API std::ostream& operator<< (std::ostream& ostr, const PBD::ID&);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#endif /* __pbd_id_h__ */
|