28#ifndef BERTINI_DETAIL_VISITABLE_HPP
29#define BERTINI_DETAIL_VISITABLE_HPP
45 template<
class VisitedT,
typename RetT>
51 std::cout <<
"unknown visitor: " << a <<
" of type " <<
typeid(VisitedT).name() <<
". Make sure you've added it in all three places! two in the class definition (type inheritance listing as visiting, and virtual function declaration), and one in cpp source (function definition)." << std::endl;
57 template<
class VisitedT,
typename RetT>
63 std::stringstream err_msg;
64 err_msg <<
"unknown visitor: " << a <<
" of type " <<
typeid(VisitedT).name() <<
". Make sure you've added it in all three places! two in the class definition (type inheritance listing as visiting, and virtual function declaration), and one in cpp source (function definition)." << std::endl;
65 throw std::runtime_error(err_msg.str());
71 template<
class VisitedT,
typename RetT>
110 if (
auto p =
dynamic_cast<Visitor<T>*
>(&guest))
111 return p->Visit(visited);
113 return CatchAll<T,RetT>::OnUnknownVisitor(visited, guest);
121 #define BERTINI_DEFAULT_VISITABLE() \
122 virtual VisitReturnType Accept(VisitorBase& guest) override \
123 { return AcceptBase(*this, guest); }
The base class for visitable types.
Definition visitable.hpp:87
virtual VisitReturnType Accept(VisitorBase &)=0
Accept a visitor (dispatch to the visitor's Visit for this concrete type).
virtual ~VisitableBase()=default
static VisitReturnType AcceptBase(T &visited, VisitorBase &guest)
Abstract method for how to accept a visitor.
Definition visitable.hpp:108
RetT VisitReturnType
The type returned when a visitor accepts this object.
Definition visitable.hpp:89
A strawman class for implementing the visitor pattern.
Definition visitor.hpp:42
The first non-trivial visitor class.
Definition visitor.hpp:58
Contains the detail/events base types.
Definition visitable.hpp:36
RaiseExceptionWithTypeNamesInMessage< VisitedT, RetT > DefaultCatchAll
The default policy for what to do when a visitable is visited by an unknown visitor.
Definition visitable.hpp:72
Definition algorithm_builder.hpp:36
A policy for what to do when a visited type is encoutered by a visitor it doesn't know.
Definition visitable.hpp:47
static RetT OnUnknownVisitor(VisitedT &a, VisitorBase &)
Default behaviour on an unknown visitor: warn and return a default-constructed value.
Definition visitable.hpp:49
A policy that throws (with the offending type names) when an unknown visitor is encountered.
Definition visitable.hpp:59
static RetT OnUnknownVisitor(VisitedT &a, VisitorBase &)
Behaviour on an unknown visitor: throw a std::runtime_error naming the visited type.
Definition visitable.hpp:61
Contains the visitor base types.