Defining which Types to visit - GerdHirsch/Cpp-VisitorFrameworkCyclicAcyclic GitHub Wiki
Single Point of Decision (SPoD)
Create a Header MyRepository.h with the following definitions:
just define a List of Types you want to visit:
#include<visitor/cyclic/Repository.h>
#include<visitor/acyclic/Repository.h>
class E1; class E2; class NonVisitable;
using typelist = VisitorFramework::Typelist<E1, E2, NonVisitable>;
You only need forward declarations of the types. If a type is not Visitable, use an Adapter.
and define (instantiate) a Repository:
with the properties you want your Implementations to have
//CAR = shortcut for CyclicAcyclicRepository
//namespace CAR = VisitorFramework::Cyclic;
namespace CAR = VisitorFramework::Acyclic;
using Repository = CAR::Repository
<
VisitorFramework::EmptyLoggingPolicy, // logs nothing
BaseKind::Abstract, // no default methods
typelist // the types you want to visit
>;
switch between cyclic and acyclic by exchanging namespace CAR =
.
switch between different types of DefaultPolicies by choosing the one you want
switch between different BaseKind
by choosing BaseKind::Abstract
or BaseKind::Default
You can also specifiy a comma separated list of types as an argument instead of typelist
.
see also SwitchCyclicAcyclicRepository.h