GME  13
ATokPtr.h
Go to the documentation of this file.
00001 /* ATokPtr.h
00002  *
00003  * SOFTWARE RIGHTS
00004  *
00005  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
00006  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
00007  * company may do whatever they wish with source code distributed with
00008  * PCCTS or the code generated by PCCTS, including the incorporation of
00009  * PCCTS, or its output, into commerical software.
00010  *
00011  * We encourage users to develop software with PCCTS.  However, we do ask
00012  * that credit is given to us for developing PCCTS.  By "credit",
00013  * we mean that if you incorporate our source code into one of your
00014  * programs (commercial product, research project, or otherwise) that you
00015  * acknowledge this fact somewhere in the documentation, research report,
00016  * etc...  If you like PCCTS and have developed a nice tool with the
00017  * output, please mention that you developed it using PCCTS.  In
00018  * addition, we ask that this header remain intact in our source code.
00019  * As long as these guidelines are kept, we expect to continue enhancing
00020  * this system and expect to make other tools available as they are
00021  * completed.
00022  *
00023  * ANTLR 1.33
00024  * Written by Russell Quong June 30, 1995
00025  * Adapted by Terence Parr to ANTLR stuff
00026  * Parr Research Corporation
00027  * with Purdue University and AHPCRC, University of Minnesota
00028  * 1989-1998
00029  */
00030 
00031 #ifndef ATokPtr_h
00032 #define ATokPtr_h
00033 
00034 // pointer to a reference counted object
00035 // robust in that an unused ANTLRTokenPtr can point to NULL.
00036 
00037 class ANTLRAbstractToken;
00038 
00039 class ANTLRTokenPtr {
00040 public:
00041     ANTLRTokenPtr(ANTLRAbstractToken *addr=NULL){ptr_ = addr; ref();}
00042     ANTLRTokenPtr(const ANTLRTokenPtr &lhs)     {ptr_ = lhs.ptr_; lhs.ref();}
00043     ~ANTLRTokenPtr();
00044 
00045     // use ANTLRTokenPtr as a pointer to ANTLRToken
00046 //
00047 //  8-Apr-97    MR1     Make operator -> a const member function
00048 //                        as well as some other member functions
00049 //
00050     ANTLRAbstractToken *operator-> () const { return ptr_; }            // MR1
00051 //
00052 //  7-Apr-97 133MR1
00053 //           Fix suggested by Andreas Magnusson
00054 //                      (Andreas.Magnusson@mailbox.swipnet.se)
00055     void operator = (const ANTLRTokenPtr & lhs);                        // MR1
00056     void operator = (ANTLRAbstractToken *addr);
00057     int operator != (const ANTLRTokenPtr &q) const                      // MR1 // MR11 unsigned -> int
00058         { return this->ptr_ != q.ptr_; }
00059     int operator == (const ANTLRTokenPtr &q) const                      // MR1 // MR11 unsigned -> int
00060         { return this->ptr_ == q.ptr_; }
00061     int operator == (const ANTLRAbstractToken *addr) const      // MR11
00062     { return this->ptr_ == addr; }
00063     int operator != (const ANTLRAbstractToken *addr) const      // MR11
00064     { return this->ptr_ != addr; }
00065 
00066     void ref() const;
00067     void deref();
00068 
00069 protected:
00070     ANTLRAbstractToken *ptr_;
00071 };
00072 
00073 //typedef ANTLRTokenPtr _ANTLRTokenPtr;
00074 
00075 /*
00076  * Since you cannot redefine operator->() to return one of the user's
00077  * token object types, we must down cast.  This is a drag.  Here's
00078  * a macro that helps.  template: "mytoken(a-smart-ptr)->myfield".
00079  */
00080 #define mytoken(tk) ((ANTLRToken *)(tk.operator->()))
00081 
00082 #endif