moreupdates
[synfig.git] / synfig-core / trunk / 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SYNFIG_UNIQUEID_H
25 #define __SYNFIG_UNIQUEID_H
26
27 /* === H E A D E R S ======================================================= */
28
29 /* === M A C R O S ========================================================= */
30
31 /* === T Y P E D E F S ===================================================== */
32
33 /* === C L A S S E S & S T R U C T S ======================================= */
34
35 namespace synfig {
36         
37 class UniqueIDLessThan;
38         
39 /*! \class UniqueID
40 **      \brief \todo
41 */
42 class UniqueID
43 {
44         friend class UniqueIDLessThan;
45         
46         int id_;
47         
48         explicit UniqueID(int id_):id_(id_) { }
49         
50         static int next_id();
51         
52 public:
53         
54         //! Returns the internal unique identifier for this object.
55         /*! The return value from this isn't really useful for
56         **      much other than debug output. Nonetheless, that is
57         **      one step above useless, so here it is. */
58         const int &get_uid()const { return id_; }
59         
60         UniqueID():id_(next_id()) { }
61         
62         void make_unique() { id_=next_id(); }
63         
64         static const UniqueID nil() { return UniqueID(0); }
65         
66         operator bool()const { return static_cast<bool>(id_); }
67
68         void mimic(const UniqueID& x) { id_=x.id_; }
69         
70         bool operator==(const UniqueID &rhs)const { return id_==rhs.id_; }
71         bool operator!=(const UniqueID &rhs)const { return id_!=rhs.id_; }
72         bool operator<(const UniqueID &rhs)const { return id_<rhs.id_; }
73 }; // END of class UniqueID
74
75 /*! \class UniqueIDLessThan
76 **      \brief A function class used for sorting based on UniqueIDs
77 */
78 class UniqueIDLessThan
79 {
80 public:
81         bool operator()(const UniqueID &lhs, const UniqueID &rhs)const
82         { return lhs.id_<rhs.id_; }
83 };
84
85
86 }; // END of namespace synfig
87
88 /* === E N D =============================================================== */
89
90 #endif