www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



c++ - Fast Template Visitor Library

↑ ↓ ← Anand Krishnamoorthi <anand.shankar.k gmail.com> writes:
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
↑ ↓ → Anand Krishnamoorthi <anand.shankar.k gmail.com> writes:
I'll test it in Digital Mars C++, G++ soon and post the results.

Anand.
Apr 24 2007