1 #ifndef INC_RefCount_hpp__
2 #define INC_RefCount_hpp__
3 /* ANTLR Translator Generator
4 * Project led by Terence Parr at http://www.jGuru.com
5 * Software rights: http://www.antlr.org/license.html
7 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/RefCount.hpp#2 $
10 #include <antlr/config.hpp>
12 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
17 class ANTLR_API RefCount {
23 Ref(T* p) : ptr(p), count(1) {}
25 Ref* increment() {++count;return this;}
26 bool decrement() {return (--count==0);}
29 Ref& operator=(const Ref&);
33 explicit RefCount(T* p = 0)
34 : ref(p ? new Ref(p) : 0)
37 RefCount(const RefCount<T>& other)
38 : ref(other.ref ? other.ref->increment() : 0)
43 if (ref && ref->decrement())
46 RefCount<T>& operator=(const RefCount<T>& other)
48 Ref* tmp = other.ref ? other.ref->increment() : 0;
49 if (ref && ref->decrement())
57 return ref ? ref->ptr : 0;
62 return ref ? ref->ptr : 0;
67 return ref ? ref->ptr : 0;
70 template<class newType> operator RefCount<newType>()
72 return RefCount<newType>(ref);
76 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
80 #endif //INC_RefCount_hpp__