1 |
|
#include <cstring> |
2 |
|
#include "CompositeVisitor.hpp" |
3 |
+ |
#include "RigidBody.hpp" |
4 |
+ |
#include "DirectionalAtom.hpp" |
5 |
|
CompositeVisitor::~CompositeVisitor(){ |
6 |
|
VisitorIterator i; |
7 |
|
BaseVisitor* curVisitor; |
39 |
|
|
40 |
|
} |
41 |
|
|
42 |
< |
void CompositeVisitor::internalVisit(StuntDouble* sd){ |
42 |
> |
void CompositeVisitor::visit(Atom* atom){ |
43 |
|
VisitorIterator i; |
44 |
|
BaseVisitor* curVisitor; |
45 |
|
|
46 |
|
for(curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i)) |
47 |
< |
sd->accept(curVisitor); |
47 |
> |
atom->accept(curVisitor); |
48 |
|
} |
49 |
|
|
50 |
+ |
void CompositeVisitor::visit(DirectionalAtom* datom){ |
51 |
+ |
VisitorIterator i; |
52 |
+ |
BaseVisitor* curVisitor; |
53 |
+ |
|
54 |
+ |
for(curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i)) |
55 |
+ |
datom->accept(curVisitor); |
56 |
+ |
} |
57 |
+ |
void CompositeVisitor::visit(RigidBody* rb){ |
58 |
+ |
VisitorIterator i; |
59 |
+ |
BaseVisitor* curVisitor; |
60 |
+ |
vector<Atom*> myAtoms; |
61 |
+ |
vector<Atom*>::iterator atomIter; |
62 |
+ |
|
63 |
+ |
myAtoms = rb->getAtoms(); |
64 |
+ |
|
65 |
+ |
for(curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i)){ |
66 |
+ |
rb->accept(curVisitor); |
67 |
+ |
|
68 |
+ |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
69 |
+ |
(*atomIter)->accept(curVisitor); |
70 |
+ |
} |
71 |
+ |
|
72 |
+ |
|
73 |
+ |
|
74 |
+ |
} |
75 |
+ |
|
76 |
|
const string CompositeVisitor::toString(){ |
77 |
|
VisitorIterator i; |
78 |
+ |
string result; |
79 |
|
char buffer[65535]; |
80 |
+ |
|
81 |
+ |
sprintf(buffer ,"******************************************************************\n"); |
82 |
+ |
result += buffer; |
83 |
|
|
84 |
+ |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
85 |
+ |
result += buffer; |
86 |
+ |
|
87 |
+ |
sprintf(buffer , "Visitor Description: visitor manager maintaining a priority list\n"); |
88 |
+ |
result += buffer; |
89 |
+ |
|
90 |
+ |
sprintf(buffer , "visitors in current priority list:\n"); |
91 |
+ |
result += buffer; |
92 |
+ |
|
93 |
|
for(i = visitorList.begin(); i != visitorList.end(); i++){ |
94 |
< |
sprintf(buffer, "Priority = %d\n", (*i).second); |
95 |
< |
strcat(buffer, (((*i).first)->toString()).c_str()); |
94 |
> |
sprintf(buffer, "Priority = %d\tvisitor = %s\n", (*i).second, ((*i).first->getVisitorName()).c_str()); |
95 |
> |
result += buffer; |
96 |
|
} |
97 |
|
|
98 |
< |
return buffer; |
98 |
> |
sprintf(buffer, "Detail information about every visitor:\n"); |
99 |
> |
|
100 |
> |
|
101 |
> |
for(i = visitorList.begin(); i != visitorList.end(); i++) |
102 |
> |
result += ((*i).first)->toString(); |
103 |
> |
|
104 |
> |
sprintf(buffer ,"******************************************************************\n"); |
105 |
> |
result += buffer; |
106 |
> |
|
107 |
> |
return result; |
108 |
|
} |
109 |
|
|
110 |
|
void CompositeVisitor::update(){ |
113 |
|
|
114 |
|
for(curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i)) |
115 |
|
curVisitor->update(); |
116 |
< |
} |
116 |
> |
} |