Created
October 12, 2009 02:39
-
-
Save hone/208078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cpp file | |
TheVisitor::TheVisitor() | |
{ | |
depth = 0; | |
} | |
void TheVisitor::VisitElement( Element* thisele ) | |
{ | |
list<Attr*> attrcopy = thisele->Copyattrs(); | |
list<Node*> nodecopy = thisele->Copynodes(); | |
cout << "<" << thisele->getName(); | |
// print attributes | |
for (list<Attr*>::iterator i = attrcopy.begin(); i != attrcopy.end(); i++) | |
{ | |
(*i)->Accept(*this); | |
} | |
// print inner elements | |
if( nodecopy.empty() ) | |
{ | |
cout << " />" << endl; | |
} | |
else | |
{ | |
cout << ">" << endl; | |
for ( list<Node*>::iterator n = nodecopy.begin(); n != nodecopy.end(); n++) | |
{ | |
depth++; | |
(*n)->Accept(*this); | |
depth--; | |
} | |
printtab(depth); | |
cout << "</" << thisele->getName() << ">" << endl; | |
} | |
} | |
void TheVisitor::printtab() | |
for(int i = 0; i < depth; i++) | |
{ | |
cout << "\t"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the header file | |
class TheVisitor : public Visitor | |
{ | |
// other stuff here | |
private: | |
int depth; | |
void printtab(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment