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