00001 #ifndef INC_TokenWithIndex_hpp__ 00002 #define INC_TokenWithIndex_hpp__ 00003 00004 /* ANTLR Translator Generator 00005 * Project led by Terence Parr at http://www.jGuru.com 00006 * Software rights: http://www.antlr.org/license.html 00007 * 00008 * $Id:$ 00009 */ 00010 00011 #include <antlr/config.hpp> 00012 #include <antlr/CommonToken.hpp> 00013 #include <antlr/String.hpp> 00014 00015 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 00016 namespace antlr { 00017 #endif 00018 00019 class ANTLR_API TokenWithIndex : public ANTLR_USE_NAMESPACE(antlr)CommonToken { 00020 public: 00021 // static size_t count; 00022 TokenWithIndex() : CommonToken(), index(0) 00023 { 00024 // std::cout << __PRETTY_FUNCTION__ << std::endl; 00025 // count++; 00026 } 00027 TokenWithIndex(int t, const ANTLR_USE_NAMESPACE(std)string& txt) 00028 : CommonToken(t,txt) 00029 , index(0) 00030 { 00031 // std::cout << __PRETTY_FUNCTION__ << std::endl; 00032 // count++; 00033 } 00034 TokenWithIndex(const ANTLR_USE_NAMESPACE(std)string& s) 00035 : CommonToken(s) 00036 , index(0) 00037 { 00038 // std::cout << __PRETTY_FUNCTION__ << std::endl; 00039 // count++; 00040 } 00041 ~TokenWithIndex() 00042 { 00043 // count--; 00044 } 00045 void setIndex( size_t idx ) 00046 { 00047 index = idx; 00048 } 00049 size_t getIndex( void ) const 00050 { 00051 return index; 00052 } 00053 00054 ANTLR_USE_NAMESPACE(std)string toString() const 00055 { 00056 return ANTLR_USE_NAMESPACE(std)string("[")+ 00057 index+ 00058 ":\""+ 00059 getText()+"\",<"+ 00060 getType()+">,line="+ 00061 getLine()+",column="+ 00062 getColumn()+"]"; 00063 } 00064 00065 static RefToken factory() 00066 { 00067 return RefToken(new TokenWithIndex()); 00068 } 00069 00070 protected: 00071 size_t index; 00072 00073 private: 00074 TokenWithIndex(const TokenWithIndex&); 00075 const TokenWithIndex& operator=(const TokenWithIndex&); 00076 }; 00077 00078 typedef TokenRefCount<TokenWithIndex> RefTokenWithIndex; 00079 00080 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 00081 } 00082 #endif 00083 00084 #endif //INC_CommonToken_hpp__