casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef TABLES_TAQLNODE_H
27#define TABLES_TAQLNODE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/TaQLNodeRep.h>
32#include <casacore/tables/TaQL/TaQLStyle.h>
33
34#include <iostream>
35#include <mutex>
36#include <vector>
37#include <memory>
38
39namespace casacore { // # NAMESPACE CASACORE - BEGIN
40
41// # Forward Declaration.
42class AipsIO;
43class TaQLNodeVisitor;
44class TaQLMultiNode;
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
81class TaQLNode {
82 public:
83 // Default constructor.
85
86 // Construct for given letter. It takes over the pointer.
87 TaQLNode(TaQLNodeRep* rep) { itsRep.reset(rep); }
88
89 // Copy constructor (reference semantics).
90 TaQLNode(const TaQLNode& that) { itsRep = that.itsRep; }
91
92 // Assignment (reference semantics).
93 TaQLNode& operator=(const TaQLNode& that) {
94 if (this != &that) {
95 itsRep = that.itsRep;
96 }
97 return *this;
98 }
99
100 // Get the TaQL style.
101 const TaQLStyle& style() const { return itsRep->style(); }
102
103 virtual ~TaQLNode() noexcept = default;
104
105 // Parse a TaQL command and return the result.
106 // An exception is thrown in case of parse errors.
107 // The parse tree is deleted by function clearNodeCreated.
108 static TaQLNode parse(const String& command);
109
110 // Does the envelope contain a letter?
111 Bool isValid() const { return Bool(itsRep); }
112
113 // Return the type of letter.
114 char nodeType() const { return itsRep->nodeType(); }
115
116 // Get read access to the letter.
117 const TaQLNodeRep* getRep() const { return itsRep.get(); }
118
119 // Let the visitor visit the node.
120 // If no node, return an empty result.
122 return (itsRep ? itsRep->visit(visitor) : TaQLNodeResult());
123 }
124
125 // Print the node (recursively) in the given stream.
126 void show(std::ostream& os) const {
127 if (itsRep) itsRep->show(os);
128 }
129
130 // Save and restore the entire parse tree.
131 // <group>
132 void save(AipsIO& aio) const;
133 static TaQLNode restore(AipsIO& aio);
134 // </group>
135
136 protected:
137 std::shared_ptr<TaQLNodeRep> itsRep;
138
139 private:
140 // Delete all nodes that were created by the parser.
141 static void clearNodesCreated();
142
143 public:
144 // Helper functions for save/restore of tree.
145 // <group>
146 void saveNode(AipsIO& aio) const;
149 // </group>
150
151 // The object getting the final tree.
153 // A list of objects created by the parser and deleted at the end.
154 static std::vector<TaQLNode*> theirNodesCreated;
155 // Keep the TaQL style to use.
157 // Use a mutex to guard the statics.
158 static std::mutex theirMutex;
159};
160
161// <summary>
162// Envelope class for a node containing a constant value.
163// </summary>
164// <use visibility=local>
165// <reviewed reviewer="" date="" tests="tTaQLNode">
166// </reviewed>
167// <synopsis>
168// This is a specialization of the envelope class
169// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
170// a constant value.
171// </synopsis>
172class TaQLConstNode : public TaQLNode {
173 public:
176 const String& getString() const;
177
178 private:
180};
181
182// <summary>
183// Envelope class for a node containing a constant regex value.
184// </summary>
185// <use visibility=local>
186// <reviewed reviewer="" date="" tests="tTaQLNode">
187// </reviewed>
188// <synopsis>
189// This is a specialization of the envelope class
190// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
191// a constant regex or pattern value.
192// </synopsis>
193class TaQLRegexNode : public TaQLNode {
194 public:
196 const String& getString() const;
198 Bool negate() const;
199
200 private:
202};
203
204// <summary>
205// Envelope class for a node containing a list of nodes.
206// </summary>
207// <use visibility=local>
208// <reviewed reviewer="" date="" tests="tTaQLNode">
209// </reviewed>
210// <synopsis>
211// This is a specialization of the envelope class
212// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
213// a list of nodes.
214// </synopsis>
215class TaQLMultiNode : public TaQLNode {
216 public:
218 explicit TaQLMultiNode(Bool isSetOrArray);
220 void add(const TaQLNode& node);
221 void add(TaQLNodeRep* noderep);
223 void setPPFix(const String& prefix, const String& postfix);
224 void setSeparator(const String& sep);
225 void setSeparator(uInt incr, const String& sep);
226 const TaQLMultiNodeRep* getMultiRep() const { return itsNRep; }
227
228 private:
230};
231
232// <summary>
233// Envelope class for a node containing a selection command.
234// </summary>
235// <use visibility=local>
236// <reviewed reviewer="" date="" tests="tTaQLNode">
237// </reviewed>
238// <synopsis>
239// This is a specialization of the envelope class
240// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
241// a selection command.
242// </synopsis>
243class TaQLQueryNode : public TaQLNode {
244 public:
249
250 private:
252};
253
254} // namespace casacore
255
256#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
TaQLConstNode(TaQLConstNodeRep *rep)
const String & getString() const
TaQLConstNodeRep * itsNRep
Definition TaQLNode.h:179
Raw TaQL parse tree node defining a list of nodes.
Envelope class for a node containing a list of nodes.
Definition TaQLNode.h:215
TaQLMultiNode(TaQLMultiNodeRep *rep)
TaQLMultiNodeRep * itsNRep
Definition TaQLNode.h:229
const TaQLMultiNodeRep * getMultiRep() const
Definition TaQLNode.h:226
void add(const TaQLNode &node)
void setSeparator(const String &sep)
void setPPFix(const String &prefix, const String &postfix)
TaQLMultiNode(Bool isSetOrArray)
void setSeparator(uInt incr, const String &sep)
void add(TaQLNodeRep *noderep)
Envelope class to hold the result of a visit to the node tree.
TaQLNode(TaQLNodeRep *rep)
Construct for given letter.
Definition TaQLNode.h:87
TaQLNode & operator=(const TaQLNode &that)
Assignment (reference semantics).
Definition TaQLNode.h:93
virtual ~TaQLNode() noexcept=default
static TaQLNode restore(AipsIO &aio)
void save(AipsIO &aio) const
Save and restore the entire parse tree.
std::shared_ptr< TaQLNodeRep > itsRep
Definition TaQLNode.h:137
static TaQLNode theirNode
The object getting the final tree.
Definition TaQLNode.h:152
const TaQLStyle & style() const
Get the TaQL style.
Definition TaQLNode.h:101
static std::mutex theirMutex
Use a mutex to guard the statics.
Definition TaQLNode.h:158
TaQLNode()
Default constructor.
Definition TaQLNode.h:84
const TaQLNodeRep * getRep() const
Get read access to the letter.
Definition TaQLNode.h:117
static std::vector< TaQLNode * > theirNodesCreated
A list of objects created by the parser and deleted at the end.
Definition TaQLNode.h:154
static TaQLMultiNode restoreMultiNode(AipsIO &aio)
Bool isValid() const
Does the envelope contain a letter?
Definition TaQLNode.h:111
static TaQLNode restoreNode(AipsIO &aio)
static TaQLNode parse(const String &command)
Parse a TaQL command and return the result.
void show(std::ostream &os) const
Print the node (recursively) in the given stream.
Definition TaQLNode.h:126
TaQLNodeResult visit(TaQLNodeVisitor &visitor) const
Let the visitor visit the node.
Definition TaQLNode.h:121
static void clearNodesCreated()
Delete all nodes that were created by the parser.
TaQLNode(const TaQLNode &that)
Copy constructor (reference semantics).
Definition TaQLNode.h:90
void saveNode(AipsIO &aio) const
Helper functions for save/restore of tree.
char nodeType() const
Return the type of letter.
Definition TaQLNode.h:114
static TaQLStyle theirStyle
Keep the TaQL style to use.
Definition TaQLNode.h:156
Raw TaQL parse tree node defining a selection command.
TaQLQueryNode(TaQLQueryNodeRep *rep)
TaQLQueryNodeRep * itsNRep
Definition TaQLNode.h:251
Raw TaQL parse tree node defining a constant regex value.
TaQLRegexNode(TaQLRegexNodeRep *rep)
const String & getString() const
TaQLRegexNodeRep * itsNRep
Definition TaQLNode.h:201
Bool caseInsensitive() const
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40