replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2007 Georgia Tech Research Corporation, INRIA
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Authors: George Riley <riley@ece.gatech.edu>
19 * Gustavo Carneiro <gjcarneiro@gmail.com>,
20 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
22 #ifndef SIMPLE_REF_COUNT_H
23 #define SIMPLE_REF_COUNT_H
31 * \brief A template-based reference counting class
33 * This template can be used to give reference-counting powers
34 * to a class. This template does not require this class to
35 * have a virtual destructor or no parent class.
37 * Note: if you are moving to this template from the RefCountBase class,
38 * you need to be careful to mark appropriately your destructor virtual
39 * if needed. i.e., if your class has subclasses, _do_ mark your destructor
43 * Note: we rely on the fairly common EBCO (empty base class optimization)
44 * to get rid of the empty parent when the user does not provide
45 * a non-trivial parent.
47 template <typename T, typename PARENT = empty>
48 class SimpleRefCount : public PARENT
54 SimpleRefCount (const SimpleRefCount &o)
57 SimpleRefCount &operator = (const SimpleRefCount &o)
62 * Increment the reference count. This method should not be called
63 * by user code. SimpleRefCount instances are expected to be used in
64 * conjunction with the Ptr template which would make calling Ref
65 * unecessary and dangerous.
67 inline void Ref (void) const
72 * Decrement the reference count. This method should not be called
73 * by user code. SimpleRefCount instances are expected to be used in
74 * conjunction with the Ptr template which would make calling Ref
75 * unecessary and dangerous.
77 inline void Unref (void) const
82 delete static_cast<T*> (const_cast<SimpleRefCount *> (this));
87 * Get the reference count of the object.
88 * Normally not needed; for language bindings.
90 uint32_t GetReferenceCount (void) const
96 // Note we make this mutable so that the const methods can still
98 mutable uint32_t m_count;
103 #endif /* SIMPLE_REF_COUNT_H */