Loading...
Searching...
No Matches
TaQLNode.h
Go to the documentation of this file.
//# TaQLNode.h: Envelope class for a node in the raw TaQL parse tree
//# Copyright (C) 2005
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef TABLES_TAQLNODE_H
#define TABLES_TAQLNODE_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/tables/TaQL/TaQLNodeRep.h>
#include <casacore/tables/TaQL/TaQLStyle.h>
#include <iostream>
#include <mutex>
#include <vector>
#include <memory>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//# Forward Declaration.
class AipsIO;
class TaQLNodeVisitor;
class TaQLMultiNode;
class TaQLConstNodeRep;
class TaQLRegexNodeRep;
class TaQLMultiNodeRep;
class TaQLQueryNodeRep;
// <summary>
// Envelope class for a node in the raw TaQL parse tree.
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="" tests="tTaQLNode">
// </reviewed>
// <prerequisite>
//# Classes you should understand before using this one.
// <li> <linkto group=TableGram.h#TableGramFunctions>TableGram</linkto>
// <li> Note 199 describing
// <a href="../notes/199.html">
// TaQL</a>
// </prerequisite>
// <synopsis>
// The result of parsing a TaQL command is stored in TaQLNode objects.
// Each part of the command can have its own specialized
// <linkto class=TaQLNodeRep>TaQLNodeRep</linkto> object, which forms
// the letter in the TaQLNode envelope.
// <br>The actual scanning/parsing of the command is done using flex/bison
// as defined in the TableGram files.
// </synopsis>
// <motivation>
// The letter-envelope idiom (counted pointer) makes if much easier
// to keep track of memory, especially in the case of exceptions.
// </motivation>
class TaQLNode
{
public:
// Default constructor.
TaQLNode()
{}
// Construct for given letter. It takes over the pointer.
TaQLNode (TaQLNodeRep* rep)
{ itsRep.reset (rep); }
// Copy constructor (reference semantics).
TaQLNode (const TaQLNode& that)
{ itsRep = that.itsRep; }
// Assignment (reference semantics).
TaQLNode& operator= (const TaQLNode& that)
{ if (this != &that) {
itsRep = that.itsRep;
}
return *this;
}
// Get the TaQL style.
const TaQLStyle& style() const
{ return itsRep->style(); }
virtual ~TaQLNode() noexcept = default;
// Parse a TaQL command and return the result.
// An exception is thrown in case of parse errors.
// The parse tree is deleted by function clearNodeCreated.
static TaQLNode parse (const String& command);
// Does the envelope contain a letter?
Bool isValid() const
{ return Bool(itsRep); }
// Return the type of letter.
char nodeType() const
{ return itsRep->nodeType(); }
// Get read access to the letter.
const TaQLNodeRep* getRep() const
{ return itsRep.get(); }
// Let the visitor visit the node.
// If no node, return an empty result.
TaQLNodeResult visit (TaQLNodeVisitor& visitor) const
{ return (itsRep ? itsRep->visit (visitor) : TaQLNodeResult()); }
// Print the node (recursively) in the given stream.
void show (std::ostream& os) const
{ if (itsRep) itsRep->show (os); }
// Save and restore the entire parse tree.
// <group>
void save (AipsIO& aio) const;
static TaQLNode restore (AipsIO& aio);
// </group>
protected:
std::shared_ptr<TaQLNodeRep> itsRep;
private:
// Delete all nodes that were created by the parser.
static void clearNodesCreated();
public:
// Helper functions for save/restore of tree.
// <group>
void saveNode (AipsIO& aio) const;
static TaQLNode restoreNode (AipsIO& aio);
static TaQLMultiNode restoreMultiNode (AipsIO& aio);
// </group>
// The object getting the final tree.
static TaQLNode theirNode;
// A list of objects created by the parser and deleted at the end.
static std::vector<TaQLNode*> theirNodesCreated;
// Keep the TaQL style to use.
static TaQLStyle theirStyle;
// Use a mutex to guard the statics.
static std::mutex theirMutex;
};
// <summary>
// Envelope class for a node containing a constant value.
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="" tests="tTaQLNode">
// </reviewed>
// <synopsis>
// This is a specialization of the envelope class
// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
// a constant value.
// </synopsis>
class TaQLConstNode: public TaQLNode
{
public:
explicit TaQLConstNode (TaQLConstNodeRep* rep);
void setIsTableName();
const String& getString() const;
private:
TaQLConstNodeRep* itsNRep;
};
// <summary>
// Envelope class for a node containing a constant regex value.
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="" tests="tTaQLNode">
// </reviewed>
// <synopsis>
// This is a specialization of the envelope class
// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
// a constant regex or pattern value.
// </synopsis>
class TaQLRegexNode: public TaQLNode
{
public:
explicit TaQLRegexNode (TaQLRegexNodeRep* rep);
const String& getString() const;
Bool caseInsensitive() const;
Bool negate() const;
private:
TaQLRegexNodeRep* itsNRep;
};
// <summary>
// Envelope class for a node containing a list of nodes.
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="" tests="tTaQLNode">
// </reviewed>
// <synopsis>
// This is a specialization of the envelope class
// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
// a list of nodes.
// </synopsis>
class TaQLMultiNode: public TaQLNode
{
public:
TaQLMultiNode();
explicit TaQLMultiNode (Bool isSetOrArray);
TaQLMultiNode (TaQLMultiNodeRep* rep);
void add (const TaQLNode& node);
void add (TaQLNodeRep* noderep);
void setIsSetOrArray();
void setPPFix (const String& prefix, const String& postfix);
void setSeparator (const String& sep);
void setSeparator (uInt incr, const String& sep);
const TaQLMultiNodeRep* getMultiRep() const
{ return itsNRep; }
private:
TaQLMultiNodeRep* itsNRep;
};
// <summary>
// Envelope class for a node containing a selection command.
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="" tests="tTaQLNode">
// </reviewed>
// <synopsis>
// This is a specialization of the envelope class
// <linkto class=TaQLNode>TaQLNode</linkto> for a node containing
// a selection command.
// </synopsis>
class TaQLQueryNode: public TaQLNode
{
public:
TaQLQueryNode (TaQLQueryNodeRep* rep);
void setBrackets();
void setNoExecute();
void setFromExecute();
private:
TaQLQueryNodeRep* itsNRep;
};
} //# NAMESPACE CASACORE - END
#endif
casacore::AipsIO
Definition AipsIO.h:167
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::TaQLConstNodeRep
Definition TaQLNodeDer.h:60
casacore::TaQLConstNode::TaQLConstNode
TaQLConstNode(TaQLConstNodeRep *rep)
casacore::TaQLConstNode::setIsTableName
void setIsTableName()
casacore::TaQLConstNode::getString
const String & getString() const
casacore::TaQLConstNode::itsNRep
TaQLConstNodeRep * itsNRep
Definition TaQLNode.h:186
casacore::TaQLMultiNodeRep
Raw TaQL parse tree node defining a list of nodes.
Definition TaQLNodeDer.h:246
casacore::TaQLMultiNode
Envelope class for a node containing a list of nodes.
Definition TaQLNode.h:225
casacore::TaQLMultiNode::TaQLMultiNode
TaQLMultiNode()
casacore::TaQLMultiNode::setIsSetOrArray
void setIsSetOrArray()
casacore::TaQLMultiNode::TaQLMultiNode
TaQLMultiNode(TaQLMultiNodeRep *rep)
casacore::TaQLMultiNode::itsNRep
TaQLMultiNodeRep * itsNRep
Definition TaQLNode.h:239
casacore::TaQLMultiNode::getMultiRep
const TaQLMultiNodeRep * getMultiRep() const
Definition TaQLNode.h:236
casacore::TaQLMultiNode::add
void add(const TaQLNode &node)
casacore::TaQLMultiNode::setSeparator
void setSeparator(const String &sep)
casacore::TaQLMultiNode::setPPFix
void setPPFix(const String &prefix, const String &postfix)
casacore::TaQLMultiNode::TaQLMultiNode
TaQLMultiNode(Bool isSetOrArray)
casacore::TaQLMultiNode::setSeparator
void setSeparator(uInt incr, const String &sep)
casacore::TaQLMultiNode::add
void add(TaQLNodeRep *noderep)
casacore::TaQLNodeRep
Definition TaQLNodeRep.h:75
casacore::TaQLNodeResult
Envelope class to hold the result of a visit to the node tree.
Definition TaQLNodeResult.h:105
casacore::TaQLNodeVisitor
Definition TaQLNodeVisitor.h:72
casacore::TaQLNode::TaQLNode
TaQLNode(TaQLNodeRep *rep)
Construct for given letter.
Definition TaQLNode.h:89
casacore::TaQLNode::operator=
TaQLNode & operator=(const TaQLNode &that)
Assignment (reference semantics).
Definition TaQLNode.h:97
casacore::TaQLNode::~TaQLNode
virtual ~TaQLNode() noexcept=default
casacore::TaQLNode::restore
static TaQLNode restore(AipsIO &aio)
casacore::TaQLNode::save
void save(AipsIO &aio) const
Save and restore the entire parse tree.
casacore::TaQLNode::itsRep
std::shared_ptr< TaQLNodeRep > itsRep
Definition TaQLNode.h:143
casacore::TaQLNode::theirNode
static TaQLNode theirNode
The object getting the final tree.
Definition TaQLNode.h:158
casacore::TaQLNode::style
const TaQLStyle & style() const
Get the TaQL style.
Definition TaQLNode.h:105
casacore::TaQLNode::theirMutex
static std::mutex theirMutex
Use a mutex to guard the statics.
Definition TaQLNode.h:164
casacore::TaQLNode::TaQLNode
TaQLNode()
Default constructor.
Definition TaQLNode.h:85
casacore::TaQLNode::getRep
const TaQLNodeRep * getRep() const
Get read access to the letter.
Definition TaQLNode.h:124
casacore::TaQLNode::theirNodesCreated
static std::vector< TaQLNode * > theirNodesCreated
A list of objects created by the parser and deleted at the end.
Definition TaQLNode.h:160
casacore::TaQLNode::restoreMultiNode
static TaQLMultiNode restoreMultiNode(AipsIO &aio)
casacore::TaQLNode::isValid
Bool isValid() const
Does the envelope contain a letter?
Definition TaQLNode.h:116
casacore::TaQLNode::restoreNode
static TaQLNode restoreNode(AipsIO &aio)
casacore::TaQLNode::parse
static TaQLNode parse(const String &command)
Parse a TaQL command and return the result.
casacore::TaQLNode::show
void show(std::ostream &os) const
Print the node (recursively) in the given stream.
Definition TaQLNode.h:133
casacore::TaQLNode::visit
TaQLNodeResult visit(TaQLNodeVisitor &visitor) const
Let the visitor visit the node.
Definition TaQLNode.h:129
casacore::TaQLNode::clearNodesCreated
static void clearNodesCreated()
Delete all nodes that were created by the parser.
casacore::TaQLNode::TaQLNode
TaQLNode(const TaQLNode &that)
Copy constructor (reference semantics).
Definition TaQLNode.h:93
casacore::TaQLNode::saveNode
void saveNode(AipsIO &aio) const
Helper functions for save/restore of tree.
casacore::TaQLNode::nodeType
char nodeType() const
Return the type of letter.
Definition TaQLNode.h:120
casacore::TaQLNode::theirStyle
static TaQLStyle theirStyle
Keep the TaQL style to use.
Definition TaQLNode.h:162
casacore::TaQLQueryNodeRep
Raw TaQL parse tree node defining a selection command.
Definition TaQLNodeDer.h:745
casacore::TaQLQueryNode::setNoExecute
void setNoExecute()
casacore::TaQLQueryNode::TaQLQueryNode
TaQLQueryNode(TaQLQueryNodeRep *rep)
casacore::TaQLQueryNode::setFromExecute
void setFromExecute()
casacore::TaQLQueryNode::setBrackets
void setBrackets()
casacore::TaQLQueryNode::itsNRep
TaQLQueryNodeRep * itsNRep
Definition TaQLNode.h:262
casacore::TaQLRegexNodeRep
Raw TaQL parse tree node defining a constant regex value.
Definition TaQLNodeDer.h:117
casacore::TaQLRegexNode::TaQLRegexNode
TaQLRegexNode(TaQLRegexNodeRep *rep)
casacore::TaQLRegexNode::getString
const String & getString() const
casacore::TaQLRegexNode::itsNRep
TaQLRegexNodeRep * itsNRep
Definition TaQLNode.h:209
casacore::TaQLRegexNode::caseInsensitive
Bool caseInsensitive() const
casacore::TaQLRegexNode::negate
Bool negate() const
casacore::TaQLStyle
Definition TaQLStyle.h:63
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40