casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TaQLNodeResult.h
Go to the documentation of this file.
00001 //# TaQLNodeResult.h: Classes holding the result of a node tree visit
00002 //# Copyright (C) 2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: TaQLNodeResult.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_TAQLNODERESULT_H
00029 #define TABLES_TAQLNODERESULT_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 // <summary>
00037 // Abstract base class to hold the result of a visit to the node tree.
00038 // </summary>
00039 
00040 // <use visibility=local>
00041 
00042 // <reviewed reviewer="" date="" tests="tTableGram">
00043 // </reviewed>
00044 
00045 // <prerequisite>
00046 //# Classes you should understand before using this one.
00047 //   <li> <linkto class=TaQLNodeVisitor>TaQLNodeVisitor</linkto>
00048 //   <li> Note 199 describing
00049 //        <a href="../notes/199.html">
00050 //        TaQL</a>
00051 // </prerequisite>
00052 
00053 // <synopsis>
00054 // TaQLNodeResultRep is the abstract base class for classes holding
00055 // values filled by visitors to the raw TaQL parse tree. Visitors are
00056 // classes derived from <linkto class=TaQLNodeVisitor>TaQLNodeVisitor</linkto>
00057 // which traverse the parse tree.
00058 // TaQLNodeResultRep is the counted referenced letter class in the envelope
00059 // class <linkto class=TaQLNodeResult>TaQLNodeResult</linkto>.
00060 // </synopsis>
00061 
00062 class TaQLNodeResultRep
00063 {
00064 public:
00065   // Default constructor clears the reference count.
00066   // The count is updated by functions link and unlink.
00067   TaQLNodeResultRep()
00068     : itsCount(0) {}
00069 
00070   // Destructor.
00071   virtual ~TaQLNodeResultRep();
00072 
00073   // Increment the reference count.
00074   static TaQLNodeResultRep* link (TaQLNodeResultRep* rep)
00075   {
00076     if (rep) ++rep->itsCount;
00077     return rep;
00078   }
00079 
00080   // Decrement the reference count.
00081   // Delete the letter if no more references.
00082   static void unlink (TaQLNodeResultRep* rep)
00083   {
00084     if (rep  &&  --rep->itsCount == 0) delete rep;
00085   }
00086 
00087 private:
00088   // Letter objects cannot be copied.
00089   // <group>
00090   TaQLNodeResultRep (const TaQLNodeResultRep&);
00091   TaQLNodeResultRep& operator= (const TaQLNodeResultRep&);
00092   // </group>
00093 
00094   int itsCount;
00095 };
00096 
00097 
00098 // <summary>
00099 // Envelope class to hold the result of a visit to the node tree.
00100 // </summary>
00101 
00102 // <use visibility=local>
00103 
00104 // <reviewed reviewer="" date="" tests="tTableGram">
00105 // </reviewed>
00106 
00107 // <prerequisite>
00108 //# Classes you should understand before using this one.
00109 //   <li> <linkto class=TaQLNodeVisitor>TaQLNodeVisitor</linkto>
00110 //   <li> Note 199 describing
00111 //        <a href="../notes/199.html">
00112 //        TaQL</a>
00113 // </prerequisite>
00114 
00115 // <synopsis>
00116 // TaQLNodeResult is the envelope class for classes holding
00117 // values filled by visitors to the raw TaQL parse tree. Visitors are
00118 // classes derived from <linkto class=TaQLNodeVisitor>TaQLNodeVisitor</linkto>
00119 // which traverse the parse tree.
00120 // The counted referenced letter base class for the envelope is
00121 // class <linkto class=TaQLNodeResultRep>TaQLNodeResultRep</linkto>.
00122 // </synopsis>
00123 class TaQLNodeResult
00124 {
00125 public:
00126   // Default constructor has no letter.
00127   TaQLNodeResult()
00128     : itsRep(0) {}
00129 
00130   // Take the given letter and increment its reference count.
00131   TaQLNodeResult (TaQLNodeResultRep* rep)
00132     { itsRep = TaQLNodeResultRep::link (rep); }
00133 
00134   // Copy constructor (reference semantics).
00135   TaQLNodeResult (const TaQLNodeResult& that)
00136     { itsRep = TaQLNodeResultRep::link (that.itsRep); }
00137 
00138   // Assignment (reference semantics).
00139   TaQLNodeResult& operator= (const TaQLNodeResult& that)
00140     { if (this != &that) {
00141         TaQLNodeResultRep::unlink (itsRep);
00142         itsRep = TaQLNodeResultRep::link (that.itsRep);
00143       }
00144     return *this;
00145     }
00146 
00147   // Destructor decrements the reference count.
00148   // The letter is deleted if no more references.
00149   ~TaQLNodeResult()
00150     { TaQLNodeResultRep::unlink (itsRep); }
00151 
00152   // Does the envelope hold a letter?
00153   Bool isValid() const
00154     { return itsRep; }
00155 
00156 private:
00157   TaQLNodeResultRep* itsRep;
00158 
00159 public:
00160   // Get the actual underlying object.
00161   const TaQLNodeResultRep* getRep() const
00162     { return itsRep; }
00163 };
00164 
00165 } //# NAMESPACE CASA - END
00166 
00167 #endif