1 // This file is part of The New Aspell
2 // Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license
3 // version 2.0 or 2.1. You should have received a copy of the LGPL
4 // license along with this library if you did not you can find
5 // it at http://www.gnu.org/.
18 // to avoid operator* being used unexpectedly. for example
19 // without this the following will compile
21 // PosibErr<StackPtr<T > > pe = fun();
22 // and operator* and StackPtr(T *) will be used. The explicit
23 // doesn't protect us here due to PosibErr
24 StackPtr(const StackPtr & other);
25 // becuase I am paranoid
26 StackPtr & operator=(const StackPtr & other);
30 explicit StackPtr(T * p = 0) : ptr(p) {}
32 StackPtr(StackPtr & other) : ptr (other.release()) {}
36 StackPtr & operator=(StackPtr & other)
37 {reset(other.release()); return *this;}
39 T & operator* () const {return *ptr;}
40 T * operator-> () const {return ptr;}
41 T * get() const {return ptr;}
42 operator T * () const {return ptr;}
44 T * release () {T * p = ptr; ptr = 0; return p;}
46 void del() {delete ptr; ptr = 0;}
47 void reset(T * p) {assert(ptr==0); ptr = p;}
48 StackPtr & operator=(T * p) {reset(p); return *this;}