Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_05 / synfig-core / src / synfig / uniqueid.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file uniqueid.h
3 **      \brief Template Header
4 **
5 **      $Id: uniqueid.h,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_UNIQUEID_H
26 #define __SYNFIG_UNIQUEID_H
27
28 /* === H E A D E R S ======================================================= */
29
30 /* === M A C R O S ========================================================= */
31
32 /* === T Y P E D E F S ===================================================== */
33
34 /* === C L A S S E S & S T R U C T S ======================================= */
35
36 namespace synfig {
37         
38 class UniqueIDLessThan;
39         
40 /*! \class UniqueID
41 **      \brief \todo
42 */
43 class UniqueID
44 {
45         friend class UniqueIDLessThan;
46         
47         int id_;
48         
49         explicit UniqueID(int id_):id_(id_) { }
50         
51         static int next_id();
52         
53 public:
54         
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_; }
60         
61         UniqueID():id_(next_id()) { }
62         
63         void make_unique() { id_=next_id(); }
64         
65         static const UniqueID nil() { return UniqueID(0); }
66         
67         operator bool()const { return static_cast<bool>(id_); }
68
69         void mimic(const UniqueID& x) { id_=x.id_; }
70         
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
75
76 /*! \class UniqueIDLessThan
77 **      \brief A function class used for sorting based on UniqueIDs
78 */
79 class UniqueIDLessThan
80 {
81 public:
82         bool operator()(const UniqueID &lhs, const UniqueID &rhs)const
83         { return lhs.id_<rhs.id_; }
84 };
85
86
87 }; // END of namespace synfig
88
89 /* === E N D =============================================================== */
90
91 #endif