]> pd.if.org Git - pccts/blob - h/ATokPtr.h
auto commit for import
[pccts] / h / ATokPtr.h
1 /* ATokPtr.h
2  *
3  * SOFTWARE RIGHTS
4  *
5  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
6  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
7  * company may do whatever they wish with source code distributed with
8  * PCCTS or the code generated by PCCTS, including the incorporation of
9  * PCCTS, or its output, into commerical software.
10  * 
11  * We encourage users to develop software with PCCTS.  However, we do ask
12  * that credit is given to us for developing PCCTS.  By "credit",
13  * we mean that if you incorporate our source code into one of your
14  * programs (commercial product, research project, or otherwise) that you
15  * acknowledge this fact somewhere in the documentation, research report,
16  * etc...  If you like PCCTS and have developed a nice tool with the
17  * output, please mention that you developed it using PCCTS.  In
18  * addition, we ask that this header remain intact in our source code.
19  * As long as these guidelines are kept, we expect to continue enhancing
20  * this system and expect to make other tools available as they are
21  * completed.
22  *
23  * ANTLR 1.33
24  * Written by Russell Quong June 30, 1995
25  * Adapted by Terence Parr to ANTLR stuff
26  * Parr Research Corporation
27  * with Purdue University and AHPCRC, University of Minnesota
28  * 1989-1995
29  */
30
31 #ifndef ATokPtr_h
32 #define ATokPtr_h
33
34 // pointer to a reference counted object
35 // robust in that an unused ANTLRTokenPtr can point to NULL.
36
37 class ANTLRAbstractToken;
38
39 class ANTLRTokenPtr {
40 public:
41     ANTLRTokenPtr(ANTLRAbstractToken *addr=NULL){ptr_ = addr; ref();}
42     ANTLRTokenPtr(const ANTLRTokenPtr &lhs)     {ptr_ = lhs.ptr_; lhs.ref();}
43     ~ANTLRTokenPtr();
44
45     // use ANTLRTokenPtr as a pointer to ANTLRToken
46     ANTLRAbstractToken *operator-> () { return ptr_; }
47     void operator = (const ANTLRTokenPtr lhs);
48     void operator = (ANTLRAbstractToken *addr);
49     unsigned operator != (const ANTLRTokenPtr &q)
50         { return this->ptr_ != q.ptr_; }
51     unsigned operator == (const ANTLRTokenPtr &q)
52         { return this->ptr_ == q.ptr_; }
53     void ref() const;
54     void deref();
55
56 protected:
57     ANTLRAbstractToken *ptr_;
58 };
59
60 //typedef ANTLRTokenPtr _ANTLRTokenPtr;
61
62 /*
63  * Since you cannot redefine operator->() to return one of the user's
64  * token object types, we must down cast.  This is a drag.  Here's
65  * a macro that helps.  template: "mytoken(a-smart-ptr)->myfield".
66  */
67 #define mytoken(tk) ((ANTLRToken *)(tk.operator->()))
68
69 #endif