Skip to content

Visitor Pattern for Dynamic::Var #2291

@obiltschnig

Description

@obiltschnig

Implement the Visitor pattern for Dynamic::Var and Dynamic::VarHolder.

Main issue here is how to deal with unknown types. A simple solution would be to just deal with a limited set of types (basically all for which we have a VarHolder, and simply throw a Poco::NotImplementedException in VarHolder::accept(). Will probably be sufficient for my initial use case.

It would be interesting to implement accept() as a template, with the Visitor class as template argument. This would make it possible to provide customized Visitor classes, containing visit() methods for all used types. However, for obvious reasons C++ does not support virtual member function templates.

A different idea would be a "dynamic" Visitor class with the ability to register "visit" functions for a specific type as std::function objects or lambdas. Something to consider for 2.0.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions