casacore
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>
33 #include <casacore/tables/TaQL/TaQLNodeRep.h>
34 #include <casacore/tables/TaQL/TaQLStyle.h>
35 #include <casacore/casa/OS/Mutex.h>
36 #include <vector>
37 #include <iostream>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declaration.
42 class AipsIO;
43 class TaQLNodeVisitor;
44 class TaQLMultiNode;
45 class TaQLConstNodeRep;
46 class TaQLRegexNodeRep;
47 class TaQLMultiNodeRep;
48 class TaQLQueryNodeRep;
49 
50 // <summary>
51 // Envelope class for a node in the raw TaQL parse tree.
52 // </summary>
53 
54 // <use visibility=local>
55 
56 // <reviewed reviewer="" date="" tests="tTaQLNode">
57 // </reviewed>
58 
59 // <prerequisite>
60 //# Classes you should understand before using this one.
61 // <li> <linkto group=TableGram.h#TableGramFunctions>TableGram</linkto>
62 // <li> Note 199 describing
63 // <a href="../notes/199.html">
64 // TaQL</a>
65 // </prerequisite>
66 
67 // <synopsis>
68 // The result of parsing a TaQL command is stored in TaQLNode objects.
69 // Each part of the command can have its own specialized
70 // <linkto class=TaQLNodeRep>TaQLNodeRep</linkto> object, which forms
71 // the letter in the TaQLNode envelope.
72 // <br>The actual scanning/parsing of the command is done using flex/bison
73 // as defined in the TableGram files.
74 // </synopsis>
75 
76 // <motivation>
77 // The letter-envelope idiom (counted pointer) makes if much easier
78 // to keep track of memory, especially in the case of exceptions.
79 // </motivation>
80 
81 class TaQLNode
82 {
83 public:
84  // Default constructor.
86  : itsRep(0) {}
87 
88  // Construct for given letter. It takes over the pointer.
90  { itsRep = TaQLNodeRep::link (rep); }
91 
92  // Copy constructor (reference semantics).
93  TaQLNode (const TaQLNode& that)
94  { itsRep = TaQLNodeRep::link (that.itsRep); }
95 
96  // Assignment (reference semantics).
98  { if (this != &that) {
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.
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; }
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 private:
147  static void clearNodesCreated();
148 public:
149  // Helper functions for save/restore of tree.
150  // <group>
151  void saveNode (AipsIO& aio) const;
152  static TaQLNode restoreNode (AipsIO& aio);
153  static TaQLMultiNode restoreMultiNode (AipsIO& aio);
154  // </group>
155 
156  // The object getting the final tree.
158  // A list of objects created by the parser and deleted at the end.
159  static std::vector<TaQLNode*> theirNodesCreated;
160  // Keep the TaQL style to use.
162  // Use a mutex to guard the statics.
164 };
165 
166 
167 // <summary>
168 // Envelope class for a node containing a constant value.
169 // </summary>
170 // <use visibility=local>
171 // <reviewed reviewer="" date="" tests="tTaQLNode">
172 // </reviewed>
173 // <synopsis>
174 // This is a specialization of the envelope class
175 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
176 // a constant value.
177 // </synopsis>
178 class TaQLConstNode: public TaQLNode
179 {
180 public:
181  explicit TaQLConstNode (TaQLConstNodeRep* rep);
182  void setIsTableName();
183  const String& getString() const;
184 private:
186 };
187 
188 
189 // <summary>
190 // Envelope class for a node containing a constant regex value.
191 // </summary>
192 // <use visibility=local>
193 // <reviewed reviewer="" date="" tests="tTaQLNode">
194 // </reviewed>
195 // <synopsis>
196 // This is a specialization of the envelope class
197 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
198 // a constant regex or pattern value.
199 // </synopsis>
200 class TaQLRegexNode: public TaQLNode
201 {
202 public:
203  explicit TaQLRegexNode (TaQLRegexNodeRep* rep);
204  const String& getString() const;
205  Bool caseInsensitive() const;
206  Bool negate() const;
207 private:
209 };
210 
211 
212 // <summary>
213 // Envelope class for a node containing a list of nodes.
214 // </summary>
215 // <use visibility=local>
216 // <reviewed reviewer="" date="" tests="tTaQLNode">
217 // </reviewed>
218 // <synopsis>
219 // This is a specialization of the envelope class
220 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
221 // a list of nodes.
222 // </synopsis>
223 class TaQLMultiNode: public TaQLNode
224 {
225 public:
226  TaQLMultiNode();
227  explicit TaQLMultiNode (Bool isSetOrArray);
229  void add (const TaQLNode& node);
230  void add (TaQLNodeRep* noderep);
231  void setIsSetOrArray();
232  void setPPFix (const String& prefix, const String& postfix);
233  void setSeparator (const String& sep);
234  void setSeparator (uInt incr, const String& sep);
236  { return itsNRep; }
237 private:
239 };
240 
241 
242 // <summary>
243 // Envelope class for a node containing a selection command.
244 // </summary>
245 // <use visibility=local>
246 // <reviewed reviewer="" date="" tests="tTaQLNode">
247 // </reviewed>
248 // <synopsis>
249 // This is a specialization of the envelope class
250 // <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
251 // a selection command.
252 // </synopsis>
253 class TaQLQueryNode: public TaQLNode
254 {
255 public:
257  void setBrackets();
258  void setNoExecute();
259  void setFromExecute();
260 private:
262 };
263 
264 
265 } //# NAMESPACE CASACORE - END
266 
267 #endif
Raw TaQL parse tree node defining a selection command.
Definition: TaQLNodeDer.h:761
TaQLMultiNodeRep * itsNRep
Definition: TaQLNode.h:238
void save(AipsIO &aio) const
Save and restore the entire tree.
const TaQLMultiNodeRep * getMultiRep() const
Definition: TaQLNode.h:235
const TaQLNodeRep * getRep() const
Get read access to the letter.
Definition: TaQLNode.h:126
TaQLQueryNodeRep * itsNRep
Definition: TaQLNode.h:261
Envelope class for a node containing a selection command.
Definition: TaQLNode.h:253
static TaQLStyle theirStyle
Keep the TaQL style to use.
Definition: TaQLNode.h:161
static TaQLMultiNode restoreMultiNode(AipsIO &aio)
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
const TaQLStyle & style() const
Get the TaQL style.
Definition: TaQLNodeRep.h:146
char nodeType() const
Get the node type of the derived class.
Definition: TaQLNodeRep.h:142
static void unlink(TaQLNodeRep *rep)
Decrement the reference count.
Definition: TaQLNodeRep.h:136
const TaQLStyle & style() const
Get the TaQL style.
Definition: TaQLNode.h:106
char nodeType() const
Return the type of letter.
Definition: TaQLNode.h:122
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:250
static TaQLNode restoreNode(AipsIO &aio)
static Mutex theirMutex
Use a mutex to guard the statics.
Definition: TaQLNode.h:163
static TaQLNode theirNode
The object getting the final tree.
Definition: TaQLNode.h:157
Envelope class for a node containing a list of nodes.
Definition: TaQLNode.h:223
TaQLNode(const TaQLNode &that)
Copy constructor (reference semantics).
Definition: TaQLNode.h:93
Envelope class for a node containing a constant regex value.
Definition: TaQLNode.h:200
Raw TaQL parse tree node defining a constant regex value.
Definition: TaQLNodeDer.h:118
Class with static members defining the TaQL style.
Definition: TaQLStyle.h:64
TaQLNode(TaQLNodeRep *rep)
Construct for given letter.
Definition: TaQLNode.h:89
TaQLNodeRep * itsRep
Definition: TaQLNode.h:145
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
TaQLNodeResult visit(TaQLNodeVisitor &visitor) const
Let the visitor visit the node.
Definition: TaQLNode.h:131
TaQLNode & operator=(const TaQLNode &that)
Assignment (reference semantics).
Definition: TaQLNode.h:97
void saveNode(AipsIO &aio) const
Helper functions for save/restore of tree.
Wrapper around a pthreads mutex.
Definition: Mutex.h:49
TaQLRegexNodeRep * itsNRep
Definition: TaQLNode.h:208
virtual void show(std::ostream &os) const =0
Print the object in an ostream.
Envelope class for a node containing a constant value.
Definition: TaQLNode.h:178
Envelope class to hold the result of a visit to the node tree.
Bool isValid() const
Does the envelope contain a letter?
Definition: TaQLNode.h:118
static void clearNodesCreated()
static std::vector< TaQLNode * > theirNodesCreated
A list of objects created by the parser and deleted at the end.
Definition: TaQLNode.h:159
TaQLNode()
Default constructor.
Definition: TaQLNode.h:85
static TaQLNodeRep * link(TaQLNodeRep *rep)
Increment the reference count.
Definition: TaQLNodeRep.h:128
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Envelope class for a node in the raw TaQL parse tree.
Definition: TaQLNode.h:81
Class to visit the nodes in the raw TaQL parse tree.
virtual TaQLNodeResult visit(TaQLNodeVisitor &) const =0
Visit a node for tree traversal.
TaQLConstNodeRep * itsNRep
Definition: TaQLNode.h:185
this file contains all the compiler specific defines
Definition: mainpage.dox:28
Representation of a node in the raw TaQL parse tree.
Definition: TaQLNodeRep.h:76
unsigned int uInt
Definition: aipstype.h:51