RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
FilterExpression.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Takes a list of tokens and parsers them to create a Filter Expression
14
15#ifndef _RBT_FILTEREXPRESSION_H_
16#define _RBT_FILTEREXPRESSION_H_
17
18#include "rxdock/Error.h"
19#include "rxdock/FilterExpressionVisitor.h"
20#include "rxdock/TokenIter.h"
21#include "rxdock/geneticprogram/GPTypes.h"
22
23#include <iostream>
24
25#include <nlohmann/json.hpp>
26
27using json = nlohmann::json;
28
29namespace rxdock {
30
31class FilterExpressionVisitor;
32
34public:
35 static const std::string _CT;
36 virtual void Print() = 0;
37 virtual void Accept(FilterExpressionVisitor &) = 0;
38 virtual int GetNOps() = 0;
39 virtual SmartPtr<FilterExpression> GetOp(int) = 0;
41 // Destructor
43 virtual ~FilterExpression();
44
45 friend void to_json(json &j, const FilterExpression &filterExpression);
46 friend void from_json(const json &j, FilterExpression &filterExpression);
47
48 ReturnType GetValue() { return value; }
49 void SetValue(ReturnType v) { value = v; }
50
52 // Private methods
54
55protected:
56 FilterExpression(); // Default constructor disabled
57 ReturnType value;
58};
59
60void to_json(json &j, const FilterExpression &filterExpression);
61void from_json(const json &j, FilterExpression &filterExpression);
62
63// Useful typedefs
64typedef SmartPtr<FilterExpression> FilterExpressionPtr; // Smart pointer
65typedef std::vector<FilterExpressionPtr> FilterExpressionList;
66// Vector of smart pointers
67typedef FilterExpressionList::iterator FilterExpressionListIter;
68typedef FilterExpressionList::const_iterator FilterExpressionListConstIter;
69
71public:
72 FilterVbleExp(const Vble &);
73 virtual ~FilterVbleExp();
74 void Accept(FilterExpressionVisitor &visitor);
75 void Print() { std::cout << "v" << vble.GetName() << " "; }
76 int GetNOps() { return 0; }
77 const Vble &GetVble() const { return vble; }
78 FilterExpressionPtr GetOp(int i) {
79 throw Error(_WHERE_, "Vble Expressions don't have operands");
80 }
81
82private:
83 const Vble &vble;
84};
85
87public:
89 virtual ~FilterLogExp();
90 void Accept(FilterExpressionVisitor &visitor);
91 void Print() {
92 std::cout << "log ";
93 operand->Print();
94 }
95 virtual int GetNOps() { return 1; }
96 FilterExpressionPtr GetOp(int i) {
97 if (i == 0)
98 return operand;
99 else
100 throw Error(_WHERE_, "Log Expressions only have 1 operand");
101 }
102
103private:
104 FilterExpressionPtr operand;
105};
106
108public:
110 virtual ~FilterExpExp();
111 void Accept(FilterExpressionVisitor &visitor);
112 void Print() {
113 std::cout << "exp ";
114 operand->Print();
115 }
116 virtual int GetNOps() { return 1; }
117 FilterExpressionPtr GetOp(int i) {
118 if (i == 0)
119 return operand;
120 else
121 throw Error(_WHERE_, "Exp Expressions only have 1 operand");
122 }
123
124private:
125 FilterExpressionPtr operand;
126};
127
129public:
131 virtual ~FilterAddExp();
132 void Accept(FilterExpressionVisitor &visitor);
133 void Print() {
134 std::cout << "add ";
135 operand1->Print();
136 operand2->Print();
137 }
138 virtual int GetNOps() { return 2; }
139 FilterExpressionPtr GetOp(int i) {
140 if (i == 0)
141 return operand1;
142 if (i == 1)
143 return operand2;
144 else
145 throw Error(_WHERE_, "Add Expressions only have 2 operands");
146 }
147
148private:
149 FilterExpressionPtr operand1, operand2;
150};
151
153public:
155 virtual ~FilterSubExp();
156 void Accept(FilterExpressionVisitor &visitor);
157 void Print() {
158 std::cout << "sub ";
159 operand1->Print();
160 operand2->Print();
161 }
162 virtual int GetNOps() { return 2; }
163 FilterExpressionPtr GetOp(int i) {
164 if (i == 0)
165 return operand1;
166 if (i == 1)
167 return operand2;
168 else
169 throw Error(_WHERE_, "Sub Expressions only have 2 operands");
170 }
171
172private:
173 FilterExpressionPtr operand1, operand2;
174};
175
177public:
179 virtual ~FilterMulExp();
180 void Accept(FilterExpressionVisitor &visitor);
181 void Print() {
182 std::cout << "mul ";
183 operand1->Print();
184 operand2->Print();
185 }
186 virtual int GetNOps() { return 2; }
187 FilterExpressionPtr GetOp(int i) {
188 if (i == 0)
189 return operand1;
190 if (i == 1)
191 return operand2;
192 else
193 throw Error(_WHERE_, "Mul Expressions only have 2 operands");
194 }
195
196private:
197 FilterExpressionPtr operand1, operand2;
198};
199
201public:
203 virtual ~FilterDivExp();
204 void Accept(FilterExpressionVisitor &visitor);
205 void Print() {
206 std::cout << "div ";
207 operand1->Print();
208 operand2->Print();
209 }
210 virtual int GetNOps() { return 2; }
211 FilterExpressionPtr GetOp(int i) {
212 if (i == 0)
213 return operand1;
214 if (i == 1)
215 return operand2;
216 else
217 throw Error(_WHERE_, "Div Expressions only have 2 operands");
218 }
219
220private:
221 FilterExpressionPtr operand1, operand2;
222};
223
225public:
227 virtual ~FilterAndExp();
228 void Accept(FilterExpressionVisitor &visitor);
229 void Print() {
230 std::cout << "and ";
231 operand1->Print();
232 operand2->Print();
233 }
234 virtual int GetNOps() { return 2; }
235 FilterExpressionPtr GetOp(int i) {
236 if (i == 0)
237 return operand1;
238 if (i == 1)
239 return operand2;
240 else
241 throw Error(_WHERE_, "And Expressions only have 2 operands");
242 }
243
244private:
245 FilterExpressionPtr operand1, operand2;
246};
247
249public:
251 virtual ~FilterIfExp();
252 void Accept(FilterExpressionVisitor &visitor);
253 void Print() {
254 std::cout << "if ";
255 operand1->Print();
256 operand2->Print();
257 operand3->Print();
258 }
259 virtual int GetNOps() { return 3; }
260 FilterExpressionPtr GetOp(int i) {
261 if (i == 0)
262 return operand1;
263 if (i == 1)
264 return operand2;
265 if (i == 2)
266 return operand3;
267 else
268 throw Error(_WHERE_, "Add Expressions only have 3 operands");
269 }
270
271private:
272 FilterExpressionPtr operand1, operand2, operand3;
273};
274
275} // namespace rxdock
276
277#endif //_FilterExpression_H_
Definition Error.h:59
Definition FilterExpression.h:128
Definition FilterExpression.h:224
Definition FilterExpression.h:200
Definition FilterExpression.h:107
Definition FilterExpressionVisitor.h:34
Definition FilterExpression.h:33
Definition FilterExpression.h:248
Definition FilterExpression.h:86
Definition FilterExpression.h:176
Definition FilterExpression.h:152
Definition FilterExpression.h:70
Definition SmartPointer.h:48
Definition Vble.h:22