3 This file is part of libmspcore
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
7 #ifndef MSP_CORE_REFPTR_H_
8 #define MSP_CORE_REFPTR_H_
16 RefPtr(): data(0), count(0) { }
17 RefPtr(T *d): data(d), count(0) { if(data) count=new unsigned(1); }
18 RefPtr(const RefPtr &p): data(p.data), count(p.count) { incref(); }
19 ~RefPtr() { decref(); }
21 RefPtr &operator=(const RefPtr &p)
30 T *get() const { return data; }
31 T &operator*() const { return *data; }
32 T *operator->() const { return data; }
33 operator bool() const { return data!=0; }
36 static RefPtr<T> cast_dynamic(const RefPtr<U> &p) { return RefPtr<T>(dynamic_cast<T *>(p.get()), p.count); }
37 template<typename U> friend class RefPtr;
42 RefPtr(T *d, unsigned *c): data(d), count(c) { incref(); }