OpenStructure
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
stage
include
ost
mol
impl
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-2011 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
28
#include <
ost/mol/module_config.hh
>
29
#include "
query_impl_fw.hh
"
30
#include "
query_ast.hh
"
31
#include <
ost/range.hh
>
32
#include <
ost/mol/query_error.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
>
37
#include <
ost/mol/query_state.hh
>
38
#include <
ost/mol/entity_property_mapper.hh
>
39
40
namespace
ost {
namespace
mol {
namespace
impl {
41
42
namespace
tok {
44
typedef
enum
{
45
IntegralValue
,
46
FloatingValue
,
47
Colon
,
48
Coma
,
49
Dot
,
50
And
,
51
Or
,
52
Not
,
53
Equal
,
54
NotEqual
,
55
GreaterEqualThan
,
56
GreaterThan
,
57
LessThan
,
58
LessEqualThan
,
59
Identifier
,
60
Within
,
61
LeftCurlyBrace
,
62
RightCurlyBrace
,
63
LeftParen
,
64
RightParen
,
65
LeftBracket
,
66
RightBracket
,
67
None
,
68
UnknownChar
,
69
UnterminatedQuote
,
70
String
71
}
72
Type
;
73
}
74
76
class
QueryToken
{
77
public
:
78
QueryToken
();
79
QueryToken
(
const
Range
& range,
tok::Type
type,
80
const
Range
& value_range=
Range
());
81
82
tok::Type
GetType
()
const
;
84
bool
IsEOF
()
const
;
86
const
Range
&
GetRange
()
const
;
89
const
Range
&
GetValueRange
()
const
;
90
private
:
91
tok::Type
type_;
92
Range
range_;
93
Range
value_range_;
94
};
95
97
class
QueryLexer
{
98
public
:
99
QueryLexer
(
const
String
& query_string);
100
QueryToken
NextToken
();
101
QueryToken
CurrentToken
()
const
;
102
private
:
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
118
struct
SelStmt
{
119
Prop::ID
sel_id
;
120
CompOP
comp_op
;
121
ParamType
param
;
122
SelStmt
()
123
:
sel_id
(
Prop
::UNDEF),
124
comp_op
(
COP_EQ
),
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
};
135
typedef
enum
{
136
LOGIC
,
VALUE
137
}
SelItemType
;
138
140
struct
SelItem
{
141
SelItemType
type
;
142
size_t
value
;
143
};
144
148
struct
GenProp
{
149
EntityPropertyMapper
mapper
;
150
float
default_val
;
151
bool
has_default
;
152
GenProp
(
EntityPropertyMapper
epm) :
153
mapper
(epm),
default_val
(0.0),
has_default
(false) {}
154
};
155
157
typedef
std::vector<SelItem>
SelStack
;
158
160
typedef
std::vector<SelStmt>
SelStmts
;
161
164
class
QueryImpl
{
165
public
:
166
friend
class
mol::QueryState
;
168
QueryImpl
(
const
String
& query_string=
""
);
171
QueryImpl
(
Node
* ast);
173
bool
IsValid
()
const
;
174
176
bool
IsEmpty
()
const
;
177
179
const
String
&
GetQueryString
()
const
;
180
181
182
const
QueryErrorDesc
&
GetErrorDescription
()
const
;
183
184
mol::QueryState
CreateQueryState
(
const
EntityHandle
& h)
const
;
185
mol::QueryState
CreateQueryState
(
const
EntityView
& v)
const
;
186
private
:
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_;
273
protected
:
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
Generated on Mon Nov 11 2013 09:56:13 for OpenStructure by
1.8.1.1