43#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_VISITOR_H
44#define LASS_GUARDIAN_OF_INCLUSION_UTIL_VISITOR_H
53class BadVisit:
public ExceptionMixin<BadVisit>
56 BadVisit(std::string msg, std::string loc): ExceptionMixin<BadVisit>(std::move(msg), std::move(loc)) {}
57 ~BadVisit() noexcept {}
65 virtual ~VisitorBase();
76 void preVisit(T& visitable)
78 doPreVisit(visitable);
80 void postVisit(T& visitable)
82 doPostVisit(visitable);
87 virtual void doPreVisit(T& visitable) = 0;
88 virtual void doPostVisit(T& ) {}
93struct ThrowOnUnknownVisit
95 template <
typename T>
static void onUnknownPreVisit(VisitorBase& , T& )
97 LASS_THROW_EX(BadVisit,
"unkown previsit on type '" <<
typeid(T).name() <<
"'.");
99 template <
typename T>
static void onUnknownPostVisit(VisitorBase& , T& )
101 LASS_THROW_EX(BadVisit,
"unkown postvisit on type '" <<
typeid(T).name() <<
"'.");
106struct IgnoreUnknownVisit
108 template <
typename T>
static void onUnknownPreVisit(VisitorBase& , T& ) {}
109 template <
typename T>
static void onUnknownPostVisit(VisitorBase& , T& ) {}
114template <
typename CatchAll = ThrowOnUnknownVisit>
118 virtual ~VisitableBase() {}
120 void accept(VisitorBase& visitor) { doAccept(visitor); }
122 template <
typename T>
123 static void preAccept(VisitorBase& visitor, T& visitable)
125 if (Visitor<T>* p =
dynamic_cast<Visitor<T>*
>(&visitor))
127 p->preVisit(visitable);
131 CatchAll::onUnknownPreVisit(visitor, visitable);
135 template <
typename T>
136 static void postAccept(VisitorBase& visitor, T& visitable)
138 if (Visitor<T>* p =
dynamic_cast<Visitor<T>*
>(&visitor))
140 p->postVisit(visitable);
144 CatchAll::onUnknownPostVisit(visitor, visitable);
150 virtual void doAccept(VisitorBase& visitor) = 0;
153#define LASS_UTIL_VISITOR_DO_ACCEPT\
154 void doAccept(::lass::util::VisitorBase& visitor) override\
156 preAccept(visitor, *this);\
157 postAccept(visitor, *this);\
#define LASS_DLL
DLL interface: import or export symbols?
general utility, debug facilities, ...
Library for Assembled Shared Sources.