OpenStructure
Loading...
Searching...
No Matches
query_ast.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of the OpenStructure project <www.openstructure.org>
3//
4// Copyright (C) 2008-2020 by the OpenStructure authors
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License as published by the Free
8// Software Foundation; either version 3.0 of the License, or (at your option)
9// any later version.
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 FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13// details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with this library; if not, write to the Free Software Foundation, Inc.,
17// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18//------------------------------------------------------------------------------
19#ifndef OST_QUERY_AST_HH
20#define OST_QUERY_AST_HH
21
22#include <boost/regex.hpp>
23
25#include <boost/variant.hpp>
26#include <ost/geom/vec3.hh>
29
30#include "query_ast_fw.hh"
31
32namespace ost { namespace mol { namespace impl {
33
39public:
40 WithinParam(const geom::Vec3& center, float radius);
41 WithinParam(int ref, float radius);
43
44 float GetRadiusSquare() const;
45
46 bool operator==(const WithinParam& p) const;
47
48 const geom::Vec3& GetCenter() const;
49 int GetRef() const;
50 bool HasValidRef() const;
51private:
52 geom::Vec3 center_;
53 float radius_;
54 int lazily_bound_ref_;
55};
56
57// holds either a simple string or a full regex, constructed from a glob-style string
59 public:
61 explicit StringOrRegexParam(const String& s);
62 bool Match(const String& s) const;
63 bool operator==(const StringOrRegexParam&) const;
64 const String& str() const {return s_;}
65 private:
66 bool is_regex_;
67 boost::regex r_;
68 String s_;
69};
70
71typedef boost::variant<int, Real, WithinParam, StringOrRegexParam> ParamType;
72
73// AST node, used internally for building the AST tree.
75public:
76 Node(): parent_(NULL) { }
77 virtual ~Node() { }
78 virtual void Dump(int level=0) const = 0;
79
81
82 void SetParent(Node* parent);
83private:
84 Node* parent_;
85};
86
87
88
90public:
92
94
96 void SetRHS(Node* rhs);
97
99 void SetLHS(Node* lhs);
100
102 const Node* GetRHS() const;
103
105 const Node* GetLHS() const;
106
107
109 LogicOP GetOP() const;
110
111 void SetOP(LogicOP op);
112
113 virtual void Dump(int level=0) const;
114
115private:
116 Node* lhs_;
117 Node* rhs_;
118 LogicOP op_;
119};
120
121
123public:
124 SelNode(const Prop& sel, CompOP op, const ParamType& value)
125 : sel_(sel), op_(op), param_(value)
126 { }
127
128 SelNode(const SelNode& rhs)
129 : sel_(rhs.sel_), op_(rhs.op_),param_(rhs.param_)
130 { }
131
132 virtual void Dump(int level=0) const;
133
134 const Prop& GetAtomProps() const {
135 return sel_;
136 }
138 return op_;
139 }
140 const ParamType& GetParm() const {
141 return param_;
142 }
143private:
144 Prop sel_;
145 CompOP op_;
146 ParamType param_;
147
148};
149
150}}} // ns
151
152#endif
Three dimensional vector class, using Real precision.
Definition vec3.hh:48
const Node * GetRHS() const
Get right-hand side.
LogicOP GetOP() const
Get logic operation.
const Node * GetLHS() const
Get left-hand side argument.
virtual void Dump(int level=0) const
void SetRHS(Node *rhs)
set right-hane side node
void SetLHS(Node *lhs)
set left hand-side node
virtual void Dump(int level=0) const =0
void SetParent(Node *parent)
const ParamType & GetParm() const
Definition query_ast.hh:140
CompOP GetCompOP() const
Definition query_ast.hh:137
SelNode(const SelNode &rhs)
Definition query_ast.hh:128
virtual void Dump(int level=0) const
const Prop & GetAtomProps() const
Definition query_ast.hh:134
SelNode(const Prop &sel, CompOP op, const ParamType &value)
Definition query_ast.hh:124
bool Match(const String &s) const
bool operator==(const StringOrRegexParam &) const
const String & str() const
Definition query_ast.hh:64
WithinParam(int ref, float radius)
WithinParam(const geom::Vec3 &center, float radius)
bool operator==(const WithinParam &p) const
const geom::Vec3 & GetCenter() const
std::string String
Definition base.hh:54
#define DLLEXPORT_OST_MOL
boost::variant< int, Real, WithinParam, StringOrRegexParam > ParamType
Definition query_ast.hh:71
Definition base.dox:1