Defining Visitables - GerdHirsch/Cpp-VisitorFrameworkCyclicAcyclic GitHub Wiki
Create a Header for each Type you want to make visitable, and let it inherit from
Repository::VisitableImpl<..>
.
#include "MyRepository.h"
class E1 : public Repository::VisitableImpl<E1>
{
public:
void operation() {...}
std::string toString() const { return "E1"; }
};
Types that don't inherit from your Repository, like NonVisitable
below can be adapted by an Adapter.
class NonVisitable{
public:
int someOperation(){...}
std::string toString() const { return "NonVisitable"; }
};
If you want to inherit from a "Visitable" like E1
above, choose the following syntax:
class E2 : public Repository::VisitableImpl<E2, E1>
{
public:
std::string toString() const { return "E2"; }
};
The second argument to VisitableImpl<..>
must be a type of Visitable
.
see also SwitchCyclicAcyclicVisitables.h