TaQLNode.h

Go to the documentation of this file.
00001 //# TaQLNode.h: Envelope class for a node in the raw TaQL parse tree
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$
00027 
00028 #ifndef TABLES_TAQLNODE_H
00029 #define TABLES_TAQLNODE_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/TaQL/TaQLNodeRep.h>
00034 #include <casacore/tables/TaQL/TaQLStyle.h>
00035 #include <casacore/casa/OS/Mutex.h>
00036 #include <vector>
00037 #include <iostream>
00038 
00039 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00040 
00041 //# Forward Declaration.
00042 class AipsIO;
00043 class TaQLNodeVisitor;
00044 class TaQLMultiNode;
00045 class TaQLConstNodeRep;
00046 class TaQLRegexNodeRep;
00047 class TaQLMultiNodeRep;
00048 class TaQLQueryNodeRep;
00049 
00050 // <summary>
00051 // Envelope class for a node in the raw TaQL parse tree.
00052 // </summary>
00053 
00054 // <use visibility=local>
00055 
00056 // <reviewed reviewer="" date="" tests="tTaQLNode">
00057 // </reviewed>
00058 
00059 // <prerequisite>
00060 //# Classes you should understand before using this one.
00061 //   <li> <linkto group=TableGram.h#TableGramFunctions>TableGram</linkto>
00062 //   <li> Note 199 describing
00063 //        <a href="../notes/199.html">
00064 //        TaQL</a>
00065 // </prerequisite>
00066 
00067 // <synopsis>
00068 // The result of parsing a TaQL command is stored in TaQLNode objects.
00069 // Each part of the command can have its own specialized
00070 // <linkto class=TaQLNodeRep>TaQLNodeRep</linkto> object, which forms
00071 // the letter in the TaQLNode envelope.
00072 // <br>The actual scanning/parsing of the command is done using flex/bison
00073 // as defined in the TableGram files.
00074 // </synopsis> 
00075 
00076 // <motivation>
00077 // The letter-envelope idiom (counted pointer) makes if much easier
00078 // to keep track of memory, especially in the case of exceptions.
00079 // </motivation>
00080 
00081 class TaQLNode
00082 {
00083 public:
00084   // Default constructor.
00085   TaQLNode()
00086     : itsRep(0) {}
00087 
00088   // Construct for given letter. It takes over the pointer.
00089   TaQLNode (TaQLNodeRep* rep)
00090     { itsRep = TaQLNodeRep::link (rep); }
00091 
00092   // Copy constructor (reference semantics).
00093   TaQLNode (const TaQLNode& that)
00094     { itsRep = TaQLNodeRep::link (that.itsRep); }
00095 
00096   // Assignment (reference semantics).
00097   TaQLNode& operator= (const TaQLNode& that)
00098     { if (this != &that) {
00099         TaQLNodeRep::unlink (itsRep);
00100         itsRep = TaQLNodeRep::link (that.itsRep);
00101       }
00102     return *this;
00103     }
00104 
00105   // Get the TaQL style.
00106   const TaQLStyle& style() const
00107     { return itsRep->style(); }
00108 
00109   // Destructor deletes the letter if no more references.
00110   ~TaQLNode()
00111     { TaQLNodeRep::unlink (itsRep); }
00112 
00113   // Parse a TaQL command and return the result.
00114   // An exception is thrown in case of parse errors.
00115   static TaQLNode parse (const String& command);
00116 
00117   // Does the envelope contain a letter?
00118   Bool isValid() const
00119     { return itsRep; }
00120 
00121   // Return the type of letter.
00122   char nodeType() const
00123     { return itsRep->nodeType(); }
00124 
00125   // Get read access to the letter.
00126   const TaQLNodeRep* getRep() const
00127     { return itsRep; }
00128 
00129   // Let the visitor visit the node.
00130   // If no node, return an empty result.
00131   TaQLNodeResult visit (TaQLNodeVisitor& visitor) const
00132     { return (itsRep  ?  itsRep->visit (visitor) : TaQLNodeResult()); }
00133 
00134   // Print the node (recursively) in the given stream.
00135   void show (std::ostream& os) const
00136     { if (itsRep) itsRep->show (os); }
00137 
00138   // Save and restore the entire tree.
00139   // <group>
00140   void save (AipsIO& aio) const;
00141   static TaQLNode restore (AipsIO& aio);
00142   // </group>
00143 
00144 protected:
00145   TaQLNodeRep* itsRep;
00146 private:
00147   static void clearNodesCreated();
00148 public:
00149   // Helper functions for save/restore of tree.
00150   // <group>
00151   void saveNode (AipsIO& aio) const;
00152   static TaQLNode restoreNode (AipsIO& aio);
00153   static TaQLMultiNode restoreMultiNode (AipsIO& aio);
00154   // </group>
00155 
00156   // The object getting the final tree.
00157   static TaQLNode theirNode;
00158   // A list of objects created by the parser and deleted at the end.
00159   static std::vector<TaQLNode*> theirNodesCreated;
00160   // Keep the TaQL style to use.
00161   static TaQLStyle theirStyle;
00162   // Use a mutex to guard the statics.
00163   static Mutex theirMutex;
00164 };
00165 
00166 
00167 // <summary>
00168 // Envelope class for a node containing a constant value.
00169 // </summary>
00170 // <use visibility=local>
00171 // <reviewed reviewer="" date="" tests="tTaQLNode">
00172 // </reviewed>
00173 // <synopsis>
00174 // This is a specialization of the envelope class
00175 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
00176 // a constant value.
00177 // </synopsis> 
00178 class TaQLConstNode: public TaQLNode
00179 {
00180 public:
00181   explicit TaQLConstNode (TaQLConstNodeRep* rep);
00182   void setIsTableName();
00183   const String& getString() const;
00184 private:
00185   TaQLConstNodeRep* itsNRep;
00186 };
00187 
00188 
00189 // <summary>
00190 // Envelope class for a node containing a constant regex value.
00191 // </summary>
00192 // <use visibility=local>
00193 // <reviewed reviewer="" date="" tests="tTaQLNode">
00194 // </reviewed>
00195 // <synopsis>
00196 // This is a specialization of the envelope class
00197 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
00198 // a constant regex or pattern value.
00199 // </synopsis> 
00200 class TaQLRegexNode: public TaQLNode
00201 {
00202 public:
00203   explicit TaQLRegexNode (TaQLRegexNodeRep* rep);
00204   const String& getString() const;
00205   Bool caseInsensitive() const;
00206   Bool negate() const;
00207 private:
00208   TaQLRegexNodeRep* itsNRep;
00209 };
00210 
00211 
00212 // <summary>
00213 // Envelope class for a node containing a list of nodes.
00214 // </summary>
00215 // <use visibility=local>
00216 // <reviewed reviewer="" date="" tests="tTaQLNode">
00217 // </reviewed>
00218 // <synopsis>
00219 // This is a specialization of the envelope class
00220 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
00221 // a list of nodes.
00222 // </synopsis> 
00223 class TaQLMultiNode: public TaQLNode
00224 {
00225 public:
00226   TaQLMultiNode();
00227   explicit TaQLMultiNode (Bool isSetOrArray);
00228   TaQLMultiNode (TaQLMultiNodeRep* rep);
00229   void add (const TaQLNode& node);
00230   void add (TaQLNodeRep* noderep);
00231   void setIsSetOrArray();
00232   void setPPFix (const String& prefix, const String& postfix);
00233   void setSeparator (const String& sep);
00234   void setSeparator (uInt incr, const String& sep);
00235   const TaQLMultiNodeRep* getMultiRep() const
00236     { return itsNRep; }
00237 private:
00238   TaQLMultiNodeRep* itsNRep;
00239 };
00240 
00241 
00242 // <summary>
00243 // Envelope class for a node containing a selection command.
00244 // </summary>
00245 // <use visibility=local>
00246 // <reviewed reviewer="" date="" tests="tTaQLNode">
00247 // </reviewed>
00248 // <synopsis>
00249 // This is a specialization of the envelope class
00250 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
00251 // a selection command.
00252 // </synopsis> 
00253 class TaQLQueryNode: public TaQLNode
00254 {
00255 public:
00256   TaQLQueryNode (TaQLQueryNodeRep* rep);
00257   void setBrackets();
00258   void setNoExecute();
00259   void setFromExecute();
00260 private:
00261   TaQLQueryNodeRep* itsNRep;
00262 };
00263 
00264 
00265 } //# NAMESPACE CASACORE - END
00266 
00267 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1