1 #ifndef INC_ASTRefCount_hpp__
2 # define INC_ASTRefCount_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
8 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/ASTRefCount.hpp#2 $
11 # include <antlr/config.hpp>
13 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
19 struct ANTLR_API ASTRef
36 static ASTRef* getRef(const AST* p);
38 ASTRef( const ASTRef& );
39 ASTRef& operator=( const ASTRef& );
43 class ANTLR_API ASTRefCount
49 ASTRefCount(const AST* p=0)
50 : ref(p ? ASTRef::getRef(p) : 0)
53 ASTRefCount(const ASTRefCount<T>& other)
54 : ref(other.ref ? other.ref->increment() : 0)
59 if (ref && ref->decrement())
62 ASTRefCount<T>& operator=(AST* other)
64 ASTRef* tmp = ASTRef::getRef(other);
66 if (ref && ref->decrement())
73 ASTRefCount<T>& operator=(const ASTRefCount<T>& other)
75 if( other.ref != ref )
77 ASTRef* 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 ASTRefCount<AST> RefAST;
94 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
98 #endif //INC_ASTRefCount_hpp__