LOOS  v2.3.2
Kernel.cpp
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 #include <Kernel.hpp>
24 #include <Atom.hpp>
25 
26 namespace loos {
27 
29  std::vector<internal::Action*>::iterator i;
30  for (i = actions.begin(); i != actions.end(); i++)
31  delete (*i);
32  }
33 
35  act->setStack(&val_stack);
36  actions.push_back(act);
37  }
38 
39  void Kernel::pop(void) {
40  if (actions.empty())
41  throw(LOOSError("Attempting to pop from an empty action stack"));
42  actions.pop_back();
43  }
44 
45 
46 
47  void Kernel::execute(pAtom pa) {
48 
49  std::vector<internal::Action*>::iterator i;
50  for (i=actions.begin(); i != actions.end(); i++) {
51  (*i)->setAtom(pa);
52  try {
53  (*i)->execute();
54  }
55  catch (LOOSError& e) {
56  stack().clear();
57  throw(e);
58  }
59  }
60 
61  }
62 
63 
64  void Kernel::clearActions(void) { actions.clear(); }
65 
66  internal::ValueStack& Kernel::stack(void) { return(val_stack); }
67 
68  std::ostream& operator<<(std::ostream& os, const Kernel& k) {
69  std::vector<internal::Action*>::const_iterator i;
70 
71  os << "Commands:\n";
72  for (i=k.actions.begin(); i != k.actions.end(); i++)
73  os << (*i)->name() << std::endl;
74  os << std::endl;
75  return(os);
76  }
77 
78 }
79 
~Kernel()
The data stack...
Definition: Kernel.cpp:28
Base class for all commands...
void push(internal::Action *)
Add a command, setting the data-stack pointer...
Definition: Kernel.cpp:34
Generic LOOS exception.
Definition: exceptions.hpp:40
void execute(pAtom pa=pAtom())
Execute the stored commands for a specific atom.
Definition: Kernel.cpp:47
Namespace for most things not already encapsulated within a class.