OpenStructure
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 <ost/mol/module_config.hh>
23 #include <boost/variant.hpp>
24 #include <ost/geom/vec3.hh>
25 #include <ost/mol/view_type_fw.hh>
26 #include <ost/mol/property_id.hh>
27 
28 namespace ost { namespace mol { namespace impl {
29 
35 public:
36  WithinParam(const geom::Vec3& center, float radius);
37  WithinParam(int ref, float radius);
38  WithinParam();
39 
40  float GetRadiusSquare() const;
41 
42  bool operator==(const WithinParam& p) const;
43 
44  const geom::Vec3& GetCenter() const;
45  int GetRef() const;
46  bool HasValidRef() const;
47 private:
48  geom::Vec3 center_;
49  float radius_;
50  int lazily_bound_ref_;
51 };
52 
53 typedef boost::variant<int, float, String, WithinParam> ParamType;
54 
55 // AST node, used internally for building the AST tree.
57 public:
58  Node(): parent_(NULL) { }
59  virtual ~Node() { }
60  virtual void Dump(int level=0) const = 0;
61 
62  Node* GetParent();
63 
64  void SetParent(Node* parent);
65 private:
66  Node* parent_;
67 };
68 
69 typedef enum {
71 } LogicOP;
72 
73 
74 
76 public:
77  LogicOPNode(LogicOP op);
78 
79  ~LogicOPNode();
80 
82  void SetRHS(Node* rhs);
83 
85  void SetLHS(Node* lhs);
86 
88  const Node* GetRHS() const;
89 
91  const Node* GetLHS() const;
92 
93 
95  LogicOP GetOP() const;
96 
97  void SetOP(LogicOP op);
98 
99  virtual void Dump(int level=0) const;
100 
101 private:
102  Node* lhs_;
103  Node* rhs_;
104  LogicOP op_;
105 };
106 
107 typedef enum {
109 } CompOP;
110 
111 
113 public:
114  SelNode(const Prop& sel, CompOP op, const ParamType& value)
115  : sel_(sel), op_(op), param_(value)
116  { }
117 
118  SelNode(const SelNode& rhs)
119  : sel_(rhs.sel_), op_(rhs.op_),param_(rhs.param_)
120  { }
121 
122  virtual void Dump(int level=0) const;
123 
124  const Prop& GetAtomProps() const {
125  return sel_;
126  }
127  CompOP GetCompOP() const {
128  return op_;
129  }
130  const ParamType& GetParm() const {
131  return param_;
132  }
133 private:
134  Prop sel_;
135  CompOP op_;
136  ParamType param_;
137 
138 };
139 
140 }}} // ns
141 
142 #endif