casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TaQLNode.h
Go to the documentation of this file.
1 //# TaQLNode.h: Envelope class for a node in the raw TaQL parse tree
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TABLES_TAQLNODE_H
29 #define TABLES_TAQLNODE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
36 #include <casacore/casa/OS/Mutex.h>
37 #include <vector>
38 #include <iostream>
39 
40 namespace casacore { //# NAMESPACE CASACORE - BEGIN
41 
42 //# Forward Declaration.
43 class AipsIO;
44 class TaQLNodeVisitor;
45 class TaQLMultiNode;
46 class TaQLConstNodeRep;
47 class TaQLRegexNodeRep;
48 class TaQLMultiNodeRep;
49 class TaQLQueryNodeRep;
50 
51 // <summary>
52 // Envelope class for a node in the raw TaQL parse tree.
53 // </summary>
54 
55 // <use visibility=local>
56 
57 // <reviewed reviewer="" date="" tests="tTaQLNode">
58 // </reviewed>
59 
60 // <prerequisite>
61 //# Classes you should understand before using this one.
62 // <li> <linkto group=TableGram.h#TableGramFunctions>TableGram</linkto>
63 // <li> Note 199 describing
64 // <a href="../notes/199.html">
65 // TaQL</a>
66 // </prerequisite>
67 
68 // <synopsis>
69 // The result of parsing a TaQL command is stored in TaQLNode objects.
70 // Each part of the command can have its own specialized
71 // <linkto class=TaQLNodeRep>TaQLNodeRep</linkto> object, which forms
72 // the letter in the TaQLNode envelope.
73 // <br>The actual scanning/parsing of the command is done using flex/bison
74 // as defined in the TableGram files.
75 // </synopsis>
76 
77 // <motivation>
78 // The letter-envelope idiom (counted pointer) makes if much easier
79 // to keep track of memory, especially in the case of exceptions.
80 // </motivation>
81 
82 class TaQLNode
83 {
84 public:
85  // Default constructor.
87  {}
88 
89  // Construct for given letter. It takes over the pointer.
91  { itsRep = rep; }
92 
93  // Copy constructor (reference semantics).
94  TaQLNode (const TaQLNode& that)
95  { itsRep = that.itsRep; }
96 
97  // Assignment (reference semantics).
99  { if (this != &that) {
100  itsRep = that.itsRep;
101  }
102  return *this;
103  }
104 
105  // Get the TaQL style.
106  const TaQLStyle& style() const
107  { return itsRep->style(); }
108 
109  // Destructor deletes the letter if no more references.
111  {}
112 
113  // Parse a TaQL command and return the result.
114  // An exception is thrown in case of parse errors.
115  static TaQLNode parse (const String& command);
116 
117  // Does the envelope contain a letter?
118  Bool isValid() const
119  { return itsRep; }
120 
121  // Return the type of letter.
122  char nodeType() const
123  { return itsRep->nodeType(); }
124 
125  // Get read access to the letter.
126  const TaQLNodeRep* getRep() const
127  { return itsRep.get(); }
128 
129  // Let the visitor visit the node.
130  // If no node, return an empty result.
132  { return (itsRep ? itsRep->visit (visitor) : TaQLNodeResult()); }
133 
134  // Print the node (recursively) in the given stream.
135  void show (std::ostream& os) const
136  { if (itsRep) itsRep->show (os); }
137 
138  // Save and restore the entire tree.
139  // <group>
140  void save (AipsIO& aio) const;
141  static TaQLNode restore (AipsIO& aio);
142  // </group>
143 
144 protected:
146 
147 private:
148  // Delete all nodes that were created by the parser.
149  static void clearNodesCreated();
150 
151 public:
152  // Helper functions for save/restore of tree.
153  // <group>
154  void saveNode (AipsIO& aio) const;
155  static TaQLNode restoreNode (AipsIO& aio);
156  static TaQLMultiNode restoreMultiNode (AipsIO& aio);
157  // </group>
158 
159  // The object getting the final tree.
161  // A list of objects created by the parser and deleted at the end.
162  static std::vector<TaQLNode*> theirNodesCreated;
163  // Keep the TaQL style to use.
165  // Use a mutex to guard the statics.
167 };
168 
169 
170 // <summary>
171 // Envelope class for a node containing a constant value.
172 // </summary>
173 // <use visibility=local>
174 // <reviewed reviewer="" date="" tests="tTaQLNode">
175 // </reviewed>
176 // <synopsis>
177 // This is a specialization of the envelope class
178 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
179 // a constant value.
180 // </synopsis>
181 class TaQLConstNode: public TaQLNode
182 {
183 public:
184  explicit TaQLConstNode (TaQLConstNodeRep* rep);
185  void setIsTableName();
186  const String& getString() const;
187 private:
189 };
190 
191 
192 // <summary>
193 // Envelope class for a node containing a constant regex value.
194 // </summary>
195 // <use visibility=local>
196 // <reviewed reviewer="" date="" tests="tTaQLNode">
197 // </reviewed>
198 // <synopsis>
199 // This is a specialization of the envelope class
200 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
201 // a constant regex or pattern value.
202 // </synopsis>
203 class TaQLRegexNode: public TaQLNode
204 {
205 public:
206  explicit TaQLRegexNode (TaQLRegexNodeRep* rep);
207  const String& getString() const;
208  Bool caseInsensitive() const;
209  Bool negate() const;
210 private:
212 };
213 
214 
215 // <summary>
216 // Envelope class for a node containing a list of nodes.
217 // </summary>
218 // <use visibility=local>
219 // <reviewed reviewer="" date="" tests="tTaQLNode">
220 // </reviewed>
221 // <synopsis>
222 // This is a specialization of the envelope class
223 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
224 // a list of nodes.
225 // </synopsis>
226 class TaQLMultiNode: public TaQLNode
227 {
228 public:
229  TaQLMultiNode();
230  explicit TaQLMultiNode (Bool isSetOrArray);
232  void add (const TaQLNode& node);
233  void add (TaQLNodeRep* noderep);
234  void setIsSetOrArray();
235  void setPPFix (const String& prefix, const String& postfix);
236  void setSeparator (const String& sep);
237  void setSeparator (uInt incr, const String& sep);
239  { return itsNRep; }
240 private:
242 };
243 
244 
245 // <summary>
246 // Envelope class for a node containing a selection command.
247 // </summary>
248 // <use visibility=local>
249 // <reviewed reviewer="" date="" tests="tTaQLNode">
250 // </reviewed>
251 // <synopsis>
252 // This is a specialization of the envelope class
253 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
254 // a selection command.
255 // </synopsis>
256 class TaQLQueryNode: public TaQLNode
257 {
258 public:
260  void setBrackets();
261  void setNoExecute();
262  void setFromExecute();
263 private:
265 };
266 
267 
268 } //# NAMESPACE CASACORE - END
269 
270 #endif
char nodeType() const
Return the type of letter.
Definition: TaQLNode.h:122
Raw TaQL parse tree node defining a selection command.
Definition: TaQLNodeDer.h:762
TaQLMultiNodeRep * itsNRep
Definition: TaQLNode.h:241
TaQLQueryNodeRep * itsNRep
Definition: TaQLNode.h:264
Envelope class for a node containing a selection command.
Definition: TaQLNode.h:256
static TaQLStyle theirStyle
Keep the TaQL style to use.
Definition: TaQLNode.h:164
static TaQLMultiNode restoreMultiNode(AipsIO &aio)
void add(const TaQLNode &node)
static TaQLNode parse(const String &command)
Parse a TaQL command and return the result.
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
TaQLRegexNode(TaQLRegexNodeRep *rep)
const TaQLStyle & style() const
Get the TaQL style.
Definition: TaQLNode.h:106
TaQLConstNode(TaQLConstNodeRep *rep)
void setSeparator(const String &sep)
Bool isValid() const
Does the envelope contain a letter?
Definition: TaQLNode.h:118
Raw TaQL parse tree node defining a constant value.
Definition: TaQLNodeDer.h:61
static TaQLNode restore(AipsIO &aio)
void show(std::ostream &os) const
Print the node (recursively) in the given stream.
Definition: TaQLNode.h:135
Raw TaQL parse tree node defining a list of nodes.
Definition: TaQLNodeDer.h:251
void setPPFix(const String &prefix, const String &postfix)
static TaQLNode restoreNode(AipsIO &aio)
static Mutex theirMutex
Use a mutex to guard the statics.
Definition: TaQLNode.h:166
static TaQLNode theirNode
The object getting the final tree.
Definition: TaQLNode.h:160
Envelope class for a node containing a list of nodes.
Definition: TaQLNode.h:226
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
TaQLNode(const TaQLNode &that)
Copy constructor (reference semantics).
Definition: TaQLNode.h:94
Envelope class for a node containing a constant regex value.
Definition: TaQLNode.h:203
Raw TaQL parse tree node defining a constant regex value.
Definition: TaQLNodeDer.h:119
const String & getString() const
Class with static members defining the TaQL style.
Definition: TaQLStyle.h:64
Bool caseInsensitive() const
TaQLNode(TaQLNodeRep *rep)
Construct for given letter.
Definition: TaQLNode.h:90
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
~TaQLNode()
Destructor deletes the letter if no more references.
Definition: TaQLNode.h:110
TaQLNode & operator=(const TaQLNode &that)
Assignment (reference semantics).
Definition: TaQLNode.h:98
const String & getString() const
Wrapper around a pthreads mutex.
Definition: Mutex.h:58
TaQLRegexNodeRep * itsNRep
Definition: TaQLNode.h:211
Envelope class for a node containing a constant value.
Definition: TaQLNode.h:181
Envelope class to hold the result of a visit to the node tree.
void save(AipsIO &aio) const
Save and restore the entire tree.
static void clearNodesCreated()
Delete all nodes that were created by the parser.
static std::vector< TaQLNode * > theirNodesCreated
A list of objects created by the parser and deleted at the end.
Definition: TaQLNode.h:162
TaQLNode()
Default constructor.
Definition: TaQLNode.h:86
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void saveNode(AipsIO &aio) const
Helper functions for save/restore of tree.
const TaQLNodeRep * getRep() const
Get read access to the letter.
Definition: TaQLNode.h:126
Envelope class for a node in the raw TaQL parse tree.
Definition: TaQLNode.h:82
Class to visit the nodes in the raw TaQL parse tree.
TaQLQueryNode(TaQLQueryNodeRep *rep)
TaQLNodeResult visit(TaQLNodeVisitor &visitor) const
Let the visitor visit the node.
Definition: TaQLNode.h:131
CountedPtr< TaQLNodeRep > itsRep
Definition: TaQLNode.h:145
TaQLConstNodeRep * itsNRep
Definition: TaQLNode.h:188
const TaQLMultiNodeRep * getMultiRep() const
Definition: TaQLNode.h:238
Representation of a node in the raw TaQL parse tree.
Definition: TaQLNodeRep.h:76
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42