ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/CompositeVisitor.cpp
Revision: 1118
Committed: Mon Apr 19 03:52:27 2004 UTC (20 years, 2 months ago) by tim
File size: 1786 byte(s)
Log Message:
new implement of quickLate using visitor and composite pattern

File Contents

# Content
1 #include <cstring>
2 #include "CompositeVisitor.hpp"
3 CompositeVisitor::~CompositeVisitor(){
4 VisitorIterator i;
5 BaseVisitor* curVisitor;
6
7 for(curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i))
8 delete curVisitor;
9
10 visitorList.clear();
11
12 }
13 void CompositeVisitor::addVisitor(BaseVisitor* newVisitor, int priority){
14 VisitorIterator i;
15 int curPriority;
16
17 for(i = visitorList.begin(); i != visitorList.end(); i++){
18 curPriority = (*i).second;
19 //if new visitor has higher priority, just insert it before current visitor
20 if(priority > curPriority){
21 visitorList.insert(i, make_pair(newVisitor, priority));
22 }
23 }
24
25 //if new visitor has lowest priority, insert it at the end of the list
26 visitorList.insert(visitorList.end(), make_pair(newVisitor, priority));
27 }
28
29 BaseVisitor* CompositeVisitor::beginVisitor(VisitorIterator& i){
30 i = visitorList.begin();
31 return i != visitorList.end() ? (*i).first : NULL;
32 }
33
34 BaseVisitor* CompositeVisitor::nextVisitor(VisitorIterator& i){
35 ++i;
36 return i != visitorList.end() ? (*i).first : NULL;
37
38 }
39
40 void CompositeVisitor::internalVisit(StuntDouble* sd){
41 VisitorIterator i;
42 BaseVisitor* curVisitor;
43
44 for(curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i))
45 sd->accept(curVisitor);
46 }
47
48 const string CompositeVisitor::toString(){
49 VisitorIterator i;
50 char buffer[65535];
51
52 for(i = visitorList.begin(); i != visitorList.end(); i++){
53 sprintf(buffer, "Priority = %d\n", (*i).second);
54 strcat(buffer, (((*i).first)->toString()).c_str());
55 }
56
57 return buffer;
58 }
59
60 void CompositeVisitor::update(){
61 VisitorIterator i;
62 BaseVisitor* curVisitor;
63
64 for(curVisitor = beginVisitor(i); curVisitor; curVisitor = nextVisitor(i))
65 curVisitor->update();
66 }

Properties

Name Value
svn:executable *