1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_UNIQUEID_H
26 #define __SYNFIG_UNIQUEID_H
28 /* === H E A D E R S ======================================================= */
30 /* === M A C R O S ========================================================= */
32 /* === T Y P E D E F S ===================================================== */
34 /* === C L A S S E S & S T R U C T S ======================================= */
38 class UniqueIDLessThan;
45 friend class UniqueIDLessThan;
49 explicit UniqueID(int id_):id_(id_) { }
55 //! Returns the internal unique identifier for this object.
56 /*! The return value from this isn't really useful for
57 ** much other than debug output. Nonetheless, that is
58 ** one step above useless, so here it is. */
59 const int &get_uid()const { return id_; }
61 UniqueID():id_(next_id()) { }
63 void make_unique() { id_=next_id(); }
65 static const UniqueID nil() { return UniqueID(0); }
67 operator bool()const { return static_cast<bool>(id_); }
69 void mimic(const UniqueID& x) { id_=x.id_; }
71 bool operator==(const UniqueID &rhs)const { return id_==rhs.id_; }
72 bool operator!=(const UniqueID &rhs)const { return id_!=rhs.id_; }
73 bool operator<(const UniqueID &rhs)const { return id_<rhs.id_; }
74 }; // END of class UniqueID
76 /*! \class UniqueIDLessThan
77 ** \brief A function class used for sorting based on UniqueIDs
79 class UniqueIDLessThan
82 bool operator()(const UniqueID &lhs, const UniqueID &rhs)const
83 { return lhs.id_<rhs.id_; }
87 }; // END of namespace synfig
89 /* === E N D =============================================================== */