Sign in to follow this  
  • entries
    94
  • comments
    127
  • views
    83097

Hierarchical Visitor Pattern

Sign in to follow this  
Seriema

814 views

As many of you I use TinyXML for my XML in C++ parsing needs. I lurk on the mailing list too. Once in a while the project manager Lee Thomason decides to change or add something, other than normal fixes. Last time I got involved was when he was going to add a copy constructor. I suggested using the Template Method to implement deep copies. I even implemented it and submitted the patch, so my code's in there! ;)

Now it's time again. He was going to add two new features; a Visitor pattern functionality and a PrintToMemory function. I joined in on the discussion and with a hot tip on (see below) got him on the right track. Of course, DrunkenCoder had something to do with this. ;)

PrintToMemory is obviously a typical Visitor and a perfect way to test the new visitor functionality. It just traverses the whole XML tree and prints it to a in memory buffer, think std::string. The initial Visitor he suggested was a plain game dev vanilla visitor, a special visitor most of us use that allows us to know when we leave a node (so we can differentiate between childs and siblings). But what about those cases when you want to trim away a whole section? I was doing something like that for my MediatorMenu project. This has already been solved and named the Hierarchical Visitor Pattern. I highly recommend you read that!

Lee contacted me about my PrintToMemoryVisitor proposal and I just sent in the patches. I slimmed his Visitor pattern as I like it too. I'll post again when we've sorted things out and my code once again becomes a small part of TinyXML. ^^
Sign in to follow this  


1 Comment


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now