1 #ifndef INC_TokenRefCount_hpp__
2 # define INC_TokenRefCount_hpp__
4 /* ANTLR Translator Generator
5 * Project led by Terence Parr at http://www.jGuru.com
6 * Software rights: http://www.antlr.org/license.html
11 # include <antlr/config.hpp>
13 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
19 struct ANTLR_API TokenRef
36 static TokenRef* getRef(const Token* p);
38 TokenRef( const TokenRef& );
39 TokenRef& operator=( const TokenRef& );
43 class ANTLR_API TokenRefCount
49 TokenRefCount(const Token* p=0)
50 : ref(p ? TokenRef::getRef(p) : 0)
53 TokenRefCount(const TokenRefCount<T>& other)
54 : ref(other.ref ? other.ref->increment() : 0)
59 if (ref && ref->decrement())
62 TokenRefCount<T>& operator=(Token* other)
64 TokenRef* tmp = TokenRef::getRef(other);
66 if (ref && ref->decrement())
73 TokenRefCount<T>& operator=(const TokenRefCount<T>& other)
75 if( other.ref != ref )
77 TokenRef* tmp = other.ref ? other.ref->increment() : 0;
79 if (ref && ref->decrement())
87 operator T* () const { return ref ? static_cast<T*>(ref->ptr) : 0; }
88 T* operator->() const { return ref ? static_cast<T*>(ref->ptr) : 0; }
89 T* get() const { return ref ? static_cast<T*>(ref->ptr) : 0; }
92 typedef TokenRefCount<Token> RefToken;
94 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
98 #endif //INC_TokenRefCount_hpp__