c++ - Fast Template Visitor Library
Hi, I've been working on a `Visitor' generation library. The main advantages being aimed for are: 1) N number of arguments and return type ( templatized ) 2) Prevent coupling between classes 3) Easy to add new classes 4) Not having to declare a Visitor interface with visit methods 5) Efficient dispatch: equivalent to a virtual function call ( normally a visitor requires 2 virt calls; acyclic visitor requires a dynamic cast ) 6) Add new visit methods at runtime One drawback includes having to register each visit method. But this is also allows runtime flexibility. A visitor can be created as a singleton if needed. The code has been developed using VC++ 8.0. The implementation techniques include assigning tags to classes on the fly, building virtual table internally, creating thunk functions, a cast policy etc. Cvisitor.h contains the library. test1.cpp contains an example for a Shape heirarchy. Please feel free to discuss the code. Comments and suggestions are welcome. Thanks, Anand.
Apr 24 2007
I'll test it in Digital Mars C++, G++ soon and post the results. Anand.
Apr 24 2007