OpenStructure
Loading...
Searching...
No Matches
query_impl.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_IMPL_HH
20#define OST_QUERY_IMPL_HH
21
22#include <vector>
23#include <string>
24#include <set>
25
26#include <boost/logic/tribool.hpp>
27
29#include "query_impl_fw.hh"
30#include "query_ast.hh"
31#include <ost/range.hh>
33#include "atom_impl_fw.hh"
34#include "residue_impl_fw.hh"
35#include "chain_impl_fw.hh"
36#include <ost/mol/mol.hh>
39
40namespace ost { namespace mol { namespace impl {
41
74
77public:
79 QueryToken(const Range& range, tok::Type type,
80 const Range& value_range=Range());
81
84 bool IsEOF() const;
86 const Range& GetRange() const;
89 const Range& GetValueRange() const;
90private:
91 tok::Type type_;
92 Range range_;
93 Range value_range_;
94};
95
98public:
99 QueryLexer(const String& query_string);
102private:
104 // lexer position.
105 void EatWhitespaces();
107 QueryToken LexToken();
108 QueryToken LexQuotedStringLiteral();
109 QueryToken LexNumericToken();
110 QueryToken LexIdentOrStringToken();
111
112 String query_string_;
113 size_t current_;
114 QueryToken tok_;
115};
116
118struct SelStmt {
123 : sel_id(Prop::UNDEF),
125 param(0) { }
126 SelStmt(Prop::ID id ,CompOP op, const ParamType& parm)
127 : sel_id(id),
128 comp_op(op),
129 param(parm) { }
130
131 bool operator ==(const SelStmt& rhs) {
132 return sel_id == rhs.sel_id && comp_op == rhs.comp_op && param == rhs.param;
133 }
134};
138
140struct SelItem {
142 size_t value;
143};
144
155
157typedef std::vector<SelItem> SelStack;
158
160typedef std::vector<SelStmt> SelStmts;
161
165public:
166 friend class mol::QueryState;
168 QueryImpl(const String& query_string="");
173 bool IsValid() const;
174
176 bool IsEmpty() const;
177
179 const String& GetQueryString() const;
180
181
183
186private:
187
189 Node* BuildAST();
191 void ASTToSelStack(const Node* src_ast,Prop::Level target_level,
192 SelStack& stack);
193
196 bool IsAlwaysUndef(const Node* ast_node, Prop::Level target_level);
197
199 void ExtractSelStmts(const Node* ast);
200
202 Node* ParsePropValueExpr(QueryLexer& lexer);
203
206 Node* ParseSubExpr(QueryLexer& lexer, bool paren=false);
207
210 Node* ParseParenSubExpr(QueryLexer& lexer);
211
215 Node* ParseBracketSubExpr(QueryLexer& lexer);
216
219 Node* ParseWithinExpr(QueryLexer& lexer);
220
229 bool ParsePoint(QueryLexer& lexer, geom::Vec3& point);
230
233 bool Expect(tok::Type type, const String& s, const QueryToken& token);
234
237 bool ExpectNumeric(const QueryToken& token);
238
241 bool ExpectLogicalOperator(const QueryToken& token);
242
245 bool ExpectComparisonOperator(const QueryToken& token);
246
253 bool ExpectNotEnd(const QueryToken& token, const String& s);
254
257 bool ParseValue(const Prop& sel, const QueryToken& op,
258 QueryLexer& lexer, ParamType& value);
259
262 Node* ParseValueOrRange(const Prop& s, const QueryToken& op,
263 QueryLexer& lexer);
265 Node* Concatenate(Node* lhs, Node* rhs, LogicOP logical_op);
266
267 String query_string_;
268 bool has_error_;
269 bool empty_optimize_;
270 QueryErrorDesc error_desc_;
271 std::vector<GenProp> gen_prop_list_;
272 int num_gen_prop_;
273protected:
274 std::vector<SelStmt> sel_values_;
275 std::vector<SelStack> sel_stacks_;
276 std::vector<std::set<size_t> > indices_;
277 std::vector<bool> inversion_stack_;
278 std::vector<QueryImplP> bracketed_expr_;
279};
280
281}}} // ns
282
283#endif
Three dimensional vector class, using Real precision.
Definition vec3.hh:48
Protein or molecule.
definition of EntityView
Holds state used during query evaluation.
query statement implementation
mol::QueryState CreateQueryState(const EntityHandle &h) const
std::vector< SelStack > sel_stacks_
const String & GetQueryString() const
Retrieve query String.
QueryImpl(const String &query_string="")
Construct new QueryImpl object.
std::vector< bool > inversion_stack_
std::vector< SelStmt > sel_values_
bool IsEmpty() const
Check if query was empty, ie matching all.
std::vector< std::set< size_t > > indices_
bool IsValid() const
Find out if the query String is valid.
std::vector< QueryImplP > bracketed_expr_
const QueryErrorDesc & GetErrorDescription() const
mol::QueryState CreateQueryState(const EntityView &v) const
QueryToken CurrentToken() const
QueryLexer(const String &query_string)
const Range & GetRange() const
Get character range of this token.
tok::Type GetType() const
const Range & GetValueRange() const
bool IsEOF() const
Returns true if token is end of file (or end of line) token.
QueryToken(const Range &range, tok::Type type, const Range &value_range=Range())
std::string String
Definition base.hh:54
std::vector< SelItem > SelStack
std::vector< SelStmt > SelStmts
boost::variant< int, Real, WithinParam, StringOrRegexParam > ParamType
Definition query_ast.hh:71
Definition base.dox:1
ID
Defined properties.
Struct to store info about GenericProperties parsed from the.
EntityPropertyMapper mapper
GenProp(EntityPropertyMapper epm)
bool operator==(const SelStmt &rhs)
SelStmt(Prop::ID id, CompOP op, const ParamType &parm)