LOOS  v2.3.2
KernelActions.hpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
6  Department of Biochemistry and Biophysics
7  School of Medicine & Dentistry, University of Rochester
8 
9  This package (LOOS) is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation under version 3 of the License.
12 
13  This package is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 
24 
25 
26 #if !defined(LOOS_KERNELACTIONS_HPP)
27 #define LOOS_KERNELACTIONS_HPP
28 
29 
30 #include <iostream>
31 #include <string>
32 #include <stdexcept>
33 #include <string.h>
34 
35 
36 #include <loos_defs.hpp>
37 #include <boost/regex.hpp>
38 
39 #include <exceptions.hpp>
40 
41 #include "KernelValue.hpp"
42 #include "KernelStack.hpp"
43 
44 
45 
46 namespace loos {
47 
48  class BackboneSelector;
49 
51 
55  namespace internal {
56 
58 
67  class Action {
68  protected:
72  pAtom atom;
74  std::string my_name;
75 
76  // Some utility functions...
77 
79  int binComp(void);
80 
81  bool negativeOperand(void);
82 
83  void binaryFalseResult(void);
84 
86  void requireAtom(void);
87 
88  public:
89  Action(const std::string s) : stack(0), atom(pAtom()), my_name(s) { }
90 
91  void setStack(ValueStack*);
92  void setAtom(pAtom&);
93 
94  virtual std::string name(void) const;
95 
96  virtual void execute(void) =0;
97  virtual ~Action() { }
98 
99  };
100 
101 
102 
104  class pushString : public Action {
105  Value val;
106  public:
107  explicit pushString(const std::string str) : Action("pushString"), val(str) { }
108  void execute(void);
109  std::string name(void) const;
110  };
111 
113  class pushInt : public Action {
114  Value val;
115  public:
116  explicit pushInt(const long i) : Action("pushInt"), val(i) { }
117  void execute(void);
118  std::string name(void) const;
119  };
120 
122  class pushFloat : public Action {
123  Value val;
124  public:
125  explicit pushFloat(const float f) : Action("pushFloat"), val(f) { }
126  void execute(void);
127  std::string name(void) const;
128  };
129 
130 
132  class drop : public Action {
133  public:
134  drop() : Action("drop") { }
135  void execute(void);
136  };
137 
139  class dup : public Action {
140  public:
141  dup() : Action("dup") { }
142  void execute(void);
143  };
144 
145 
147  class equals : public Action {
148  public:
149  equals() : Action("==") { }
150  void execute(void);
151  };
152 
154  class lessThan : public Action {
155  public:
156  lessThan() : Action("<") { }
157  void execute(void);
158  };
159 
161  class lessThanEquals : public Action {
162  public:
163  lessThanEquals() : Action("<=") { }
164  void execute(void);
165  };
166 
168  class greaterThan : public Action {
169  public:
170  greaterThan() : Action(">") { }
171  void execute(void);
172  };
173 
175  class greaterThanEquals : public Action {
176  public:
177  greaterThanEquals() : Action(">=") { }
178  void execute(void);
179  };
180 
182 
187  class matchRegex : public Action {
188  boost::regex regexp;
189  public:
190  explicit matchRegex(const std::string s) : Action("matchRegex"), regexp(s, boost::regex::perl|boost::regex::icase), pattern(s) { }
191  void execute(void);
192  std::string name(void) const;
193 
194  private:
195  std::string pattern;
196  };
197 
198 
200 
205  class matchStringAsRegex : public Action {
206  public:
207  matchStringAsRegex() : Action("matchStringAsRegex") { }
208  void execute(void);
209  };
210 
211 
213 
219  class extractNumber : public Action {
220  public:
221  explicit extractNumber(const std::string s) : Action("extractNumber"),
222  regexp(s, boost::regex::perl|boost::regex::icase),
223  pattern(s) { }
224 
225  void execute(void);
226  std::string name(void) const;
227 
228  private:
229  boost::regex regexp;
230  std::string pattern;
231  };
232 
233 
234 
235 
237  class pushAtomName : public Action {
238  public:
239  pushAtomName() : Action("pushAtomName") { }
240  void execute(void);
241  };
242 
244  class pushAtomId : public Action {
245  public:
246  pushAtomId() : Action("pushAtomId") { }
247  void execute(void);
248  };
249 
251  class pushAtomIndex : public Action {
252  public:
253  pushAtomIndex() : Action("pushAtomIndex") { }
254  void execute(void);
255  };
256 
258  class pushAtomResname : public Action {
259  public:
260  pushAtomResname() : Action("pushAtomResname") { }
261  void execute(void);
262  };
263 
265  class pushAtomResid : public Action {
266  public:
267  pushAtomResid() : Action("pushAtomResid") { }
268  void execute(void);
269  };
270 
272  class pushAtomSegid : public Action {
273  public:
274  pushAtomSegid() : Action("pushAtomSegid") { }
275  void execute(void);
276  };
277 
279  class pushAtomChainId : public Action {
280  public:
281  pushAtomChainId() : Action("pushAtomChainId") { }
282  void execute(void);
283  };
284 
285 
286 
287  // Logical operations... Assumes stack args are ints...
288 
290  class logicalAnd : public Action{
291  public:
292  logicalAnd() : Action("&&") { }
293  void execute(void);
294  };
295 
297  class logicalOr : public Action {
298  public:
299  logicalOr() : Action("||") { }
300  void execute(void);
301  };
302 
303 
305  class logicalNot : public Action {
306  public:
307  logicalNot() : Action("!") { }
308  void execute(void);
309  };
310 
312  class logicalTrue : public Action {
313  public:
314  logicalTrue() : Action("TRUE") { }
315  void execute(void);
316  };
317 
318 
320  class Hydrogen : public Action {
321  public:
322  Hydrogen() : Action("Hydrogen") { }
323  void execute(void);
324  };
325 
327  class Backbone : public Action {
328  static BackboneSelector bbsel; // Make this class-level since we only need one to wrap
329  public:
330  Backbone() : Action("Backbone") { }
331  void execute(void);
332  };
333 
334 
335  }
336 
337 }
338 
339 
340 
341 #endif
342 
Test for equality: ARG1 ARG ==.
Push an integer onto the data stack.
Push atom's residue id onto the stack.
Push atom name onto the stack.
Push atom'ss residue name onto the stack.
Extracts a number for a string on the stack using a regular expression: ARG1 regexp(S) ...
Push a float onto the data stack.
Shortcut for checking for hydrogens...
Base class for all commands...
Predicate for selecting backbone.
Definition: Selectors.hpp:53
Relation operators...: ARG1 ARG2 <.
Push a std::string onto the data stack.
int binComp(void)
Compare the top two items on the stack...
ValueStack * stack
Pointer to the data stack.
Push atom index onto the stack.
Push atom's chain ID onto the stack.
void requireAtom(void)
Check to make sure an atom has been set...
Drop the top item from the stack.
Push atom's segid onto the stack.
Duplicate the top item on the stack.
std::string my_name
Record of command-name (for printing)
Namespace for most things not already encapsulated within a class.
Value class for the LOOS Kernel (virtual machine)
Definition: KernelValue.hpp:51
Regular expression matching: ARG1 regexp(ARG2)
Regular expression matching: ARG1 regexp(S)
Shortcut for checking for backbone atoms...
Always returns true...
pAtom atom
Pointer to the atom we'll be working on...
Push atom id onto the stack.