Make error reporters on SystemAllocatorPolicy public.
1 // vim: set sts=8 ts=2 sw=2 tw=99 et:
3 // Copyright (C) 2013, David Anderson and AlliedModders LLC
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice, this
10 // list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 // * Neither the name of AlliedModders LLC nor the names of its contributors
15 // may be used to endorse or promote products derived from this software
16 // without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
30 #ifndef _include_amtl_refcounting_h_
31 #define _include_amtl_refcounting_h_
33 #include <am-utility.h>
37 template <typename T> class Ref;
39 // Holds a refcounted T without addrefing it. This is similar to PassRef<>
40 // below, but is intended only for freshly allocated objects which start
41 // with reference count 1, and we don't want to add an extra ref just by
42 // assigning to PassRef<> or Ref<>.
53 return ReturnAndVoid(thing_);
60 // When returning a value, we'd rather not be needlessly changing the refcount,
61 // so we have a special type to use for returns.
76 PassRef(const Newborn<T *> &other)
77 : thing_(other.release())
79 // Don't addref, newborn means already addref'd.
83 inline PassRef(const Ref<S> &other);
85 PassRef(const PassRef &other)
86 : thing_(other.release())
90 PassRef(const PassRef<S> &other)
91 : thing_(other.release())
102 operator T *() const {
105 T *operator ->() const {
108 T *operator *() const {
111 bool operator !() const {
116 return ReturnAndVoid(thing_);
119 template <typename S>
120 PassRef &operator =(const PassRef<S> &other) {
122 thing_ = other.release();
127 // Disallowed operators.
128 PassRef &operator =(T *other);
129 PassRef &operator =(Newborn<T> &other);
144 // Classes which are refcounted should inherit from this.
145 template <typename T>
158 assert(refcount_ > 0);
159 if (--refcount_ == 0)
160 delete static_cast<T *>(this);
171 // Simple class for automatic refcounting.
172 template <typename T>
187 Ref(const Ref &other)
188 : thing_(other.thing_)
192 template <typename S>
193 Ref(const Ref<S> &other)
198 Ref(const PassRef<T> &other)
199 : thing_(other.release())
202 template <typename S>
203 Ref(const PassRef<S> &other)
204 : thing_(other.release())
207 Ref(const Newborn<T> &other)
208 : thing_(other.release())
216 T *operator ->() const {
219 T *operator *() const {
225 bool operator !() const {
229 template <typename S>
230 Ref &operator =(S *thing) {
237 template <typename S>
238 Ref &operator =(const PassRef<S> &other) {
240 thing_ = other.release();
244 template <typename S>
245 Ref &operator =(const Newborn<S> &other) {
247 thing_ = other.release();
251 Ref &operator =(const Ref &other) {
253 thing_ = other.thing_;
272 template <typename T> template <typename S>
273 PassRef<T>::PassRef(const Ref<S> &other)
281 #endif // _include_amtl_refcounting_h_