45#include "visitors/CompositeVisitor.hpp"
54 CompositeVisitor::~CompositeVisitor() {
56 BaseVisitor* curVisitor;
58 for (curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i))
63 void CompositeVisitor::addVisitor(BaseVisitor* newVisitor,
int priority) {
67 for (i = visitorList.begin(); i != visitorList.end(); ++i) {
68 curPriority = (*i).second;
71 if (priority > curPriority) {
72 visitorList.insert(i, std::make_pair(newVisitor, priority));
77 visitorList.insert(visitorList.end(), std::make_pair(newVisitor, priority));
80 BaseVisitor* CompositeVisitor::beginVisitor(VisitorIterator& i) {
81 i = visitorList.begin();
82 return i != visitorList.end() ? (*i).first : NULL;
85 BaseVisitor* CompositeVisitor::nextVisitor(VisitorIterator& i) {
87 return i != visitorList.end() ? (*i).first : NULL;
90 void CompositeVisitor::visit(Atom* atom) {
92 BaseVisitor* curVisitor;
94 for (curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i))
95 atom->accept(curVisitor);
98 void CompositeVisitor::visit(DirectionalAtom* datom) {
100 BaseVisitor* curVisitor;
102 for (curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i))
103 datom->accept(curVisitor);
105 void CompositeVisitor::visit(RigidBody* rb) {
107 BaseVisitor* curVisitor;
108 std::vector<Atom*> myAtoms;
109 std::vector<Atom*>::iterator atomIter;
111 myAtoms = rb->getAtoms();
113 for (curVisitor = beginVisitor(i); curVisitor;
114 curVisitor = nextVisitor(i)) {
115 rb->accept(curVisitor);
117 for (atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
118 (*atomIter)->accept(curVisitor);
122 const std::string CompositeVisitor::toString() {
129 "******************************************************************\n");
132 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
137 "Visitor Description: visitor manager maintaining a priority list\n");
140 snprintf(buffer, 65535,
"visitors in current priority list:\n");
143 for (i = visitorList.begin(); i != visitorList.end(); ++i) {
144 snprintf(buffer, 65535,
"Priority = %d\tvisitor = %s\n", (*i).second,
145 ((*i).first->getVisitorName()).c_str());
149 snprintf(buffer, 65535,
"Detail information about every visitor:\n");
151 for (i = visitorList.begin(); i != visitorList.end(); ++i)
152 result += ((*i).first)->toString();
156 "******************************************************************\n");
162 void CompositeVisitor::update() {
164 BaseVisitor* curVisitor;
166 for (curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i))
167 curVisitor->update();
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.