OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-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_AST_HH
20 #define OST_QUERY_AST_HH
21 
22 #include <boost/regex.hpp>
23 
24 #include <ost/mol/module_config.hh>
25 #include <boost/variant.hpp>
26 #include <ost/geom/vec3.hh>
27 #include <ost/mol/view_type_fw.hh>
28 #include <ost/mol/property_id.hh>
29 
30 #include "query_ast_fw.hh"
31 
32 namespace ost { namespace mol { namespace impl {
33 
39 public:
40  WithinParam(const geom::Vec3& center, float radius);
41  WithinParam(int ref, float radius);
42  WithinParam();
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;
51 private:
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 
71 typedef boost::variant<int, float, WithinParam, StringOrRegexParam> ParamType;
72 
73 // AST node, used internally for building the AST tree.
75 public:
76  Node(): parent_(NULL) { }
77  virtual ~Node() { }
78  virtual void Dump(int level=0) const = 0;
79 
80  Node* GetParent();
81 
82  void SetParent(Node* parent);
83 private:
84  Node* parent_;
85 };
86 
87 
88 
90 public:
91  LogicOPNode(LogicOP op);
92 
93  ~LogicOPNode();
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 
115 private:
116  Node* lhs_;
117  Node* rhs_;
118  LogicOP op_;
119 };
120 
121 
123 public:
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  }
137  CompOP GetCompOP() const {
138  return op_;
139  }
140  const ParamType& GetParm() const {
141  return param_;
142  }
143 private:
144  Prop sel_;
145  CompOP op_;
146  ParamType param_;
147 
148 };
149 
150 }}} // ns
151 
152 #endif