Skip to content

Instantly share code, notes, and snippets.

@louis-langholtz
Last active January 11, 2018 00:40
Show Gist options
  • Save louis-langholtz/14de230a03d486ad14cc047309819f24 to your computer and use it in GitHub Desktop.
Save louis-langholtz/14de230a03d486ad14cc047309819f24 to your computer and use it in GitHub Desktop.
Runtime Polymorphic Visitor

Extend the runtime polymorphism to vistor like pattern...

namespace playrho {

template <>
void Visit(const d2::EdgeShapeConf& shape, void* userData)
{
    const auto shapeDrawer = static_cast<ShapeDrawer*>(userData);
    shapeDrawer->Visit(shape);
}

This provides application based visitation with userData providing some customization (based on the capability/flexibility of ShapeDrawer) at the point of calling the Visit function on the Shape. Can we do "better" than ShapeDrawer? Can we elegantly have userData pull in a completely configurable lambda per the given class (d2::EdgeShapeConf for instance)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment