1 /*! ========================================================================
2 ** Extended Template Library
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
23 ** ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __ETL_REF_COUNT_H
28 #define __ETL_REF_COUNT_H
30 /* === H E A D E R S ======================================================= */
32 #include "_curve_func.h"
35 /* === M A C R O S ========================================================= */
37 /* === T Y P E D E F S ===================================================== */
39 /* === C L A S S E S & S T R U C T S ======================================= */
43 class weak_reference_counter;
45 // ========================================================================
46 /*! \class reference_counter _ref_count.h ETL/ref_count
47 ** \brief Reference counter
48 ** \see weak_reference_counter
51 class reference_counter
53 friend class weak_reference_counter;
58 reference_counter(const bool &x=true):counter_(x?new int(1):0) { }
60 reference_counter(const reference_counter &x):counter_(x.counter_)
61 { if(counter_) (*counter_)++; }
63 reference_counter(const weak_reference_counter &x);
65 ~reference_counter() { detach(); }
67 reference_counter& operator=(const reference_counter &rhs)
70 counter_=rhs.counter_;
96 int count()const { return counter_?*counter_:0; }
98 bool unique()const { return counter_?*counter_==1:0; }
100 operator int()const { return count(); }
101 }; // END of class reference_counter
103 // ========================================================================
104 /*! \class weak_reference_counter _ref_count.h ETL/ref_count
105 ** \brief Weak Reference counter
106 ** \see reference_counter
109 class weak_reference_counter
111 friend class reference_counter;
115 weak_reference_counter():counter_(0) { }
117 weak_reference_counter(const weak_reference_counter &x):counter_(x.counter_) { }
119 weak_reference_counter(const reference_counter &x):counter_(x.counter_) { }
121 ~weak_reference_counter() { }
123 weak_reference_counter& operator=(const reference_counter &rhs)
125 counter_=rhs.counter_;
130 weak_reference_counter& operator=(const weak_reference_counter &rhs)
132 counter_=rhs.counter_;
137 void detach() { counter_=0; }
139 int count()const { return counter_?*counter_:0; }
141 bool unique()const { return counter_?*counter_==1:0; }
143 operator int()const { return count(); }
144 }; // END of class weak_reference_counter
146 inline reference_counter::reference_counter(const weak_reference_counter &x):
149 if(counter_) (*counter_)++;
154 /* === E X T E R N S ======================================================= */
156 /* === E N D =============================================================== */