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