3 * Copyright (C) 2005-2006 Mathias Froehlich
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef ssgSharedPtr_HXX
22 #define ssgSharedPtr_HXX
24 /// This class is a pointer proxy doing reference counting on the object
25 /// it is pointing to.
26 /// It is very similar to the SGSharedPtr class but is made to work together
27 /// with reference counting of plib's ssg reference counters
28 /// For notes on usage see SGSharedPtr.
33 ssgSharedPtr(void) : _ptr(0)
35 ssgSharedPtr(T* ptr) : _ptr(ptr)
37 ssgSharedPtr(const ssgSharedPtr& p) : _ptr(p.ptr())
40 ssgSharedPtr(const ssgSharedPtr<U>& p) : _ptr(p.ptr())
45 ssgSharedPtr& operator=(const ssgSharedPtr& p)
46 { assign(p.ptr()); return *this; }
48 ssgSharedPtr& operator=(const ssgSharedPtr<U>& p)
49 { assign(p.ptr()); return *this; }
51 ssgSharedPtr& operator=(U* p)
52 { assign(p); return *this; }
54 T* operator->(void) const
56 T& operator*(void) const
58 operator T*(void) const
63 bool isShared(void) const
64 { if (_ptr) return 1 < _ptr->getRef(); else return false; }
65 unsigned getNumRefs(void) const
66 { if (_ptr) return _ptr->getRef(); else return 0; }
68 bool valid(void) const
73 { get(p); put(); _ptr = p; }
82 assert(0 < _ptr->getRef());
84 if (_ptr->getRef() == 0) {
90 // The reference itself.