2#include <Core/RaCore.hpp>
4#include <Core/Containers/DynamicVisitorBase.hpp>
5#include <Core/Containers/VariableSet.hpp>
6#include <Core/Utils/Log.hpp>
7#include <Core/Utils/StdExperimentalTypeTraits.hpp>
8#include <Core/Utils/StdOptional.hpp>
9#include <Core/Utils/TypesUtils.hpp>
14#include <unordered_map>
40 void operator()(
const std::string& name, std::any&& in, std::any&& userParam )
const override;
54 template <
typename T,
typename F>
55 bool addOperator( F&& f );
69 template <
typename T,
typename F>
70 void addOrReplaceOperator( F&& f );
77 bool removeOperator();
86 template <
typename T,
typename F>
88 std::enable_if_t<std::is_invocable<F, const std::string&, T&, std::any&&>::value,
bool>;
89 template <
typename T,
typename F>
91 std::enable_if_t<std::is_invocable<F, const std::string&, T&>::value,
bool>;
95 template <
typename T,
typename F, WithParam<T, F> = true>
96 auto makeVisitorOperator( F& f ) -> OperatorsStorageType::value_type;
97 template <
typename T,
typename F, WithoutParam<T, F> = true>
98 auto makeVisitorOperator( F& f ) -> OperatorsStorageType::value_type;
104template <
typename T,
typename F>
106 auto [it, inserted] = m_visitorOperator.
insert( makeVisitorOperator<T, F>( f ) );
112 return m_visitorOperator.
find( VariableSet::getVariableVisitTypeIndex<T>() ) !=
113 m_visitorOperator.
end();
116template <
typename T,
typename F>
118 auto op = makeVisitorOperator<T, F>( f );
119 m_visitorOperator.insert_or_assign( op.first, op.second );
125 auto res = m_visitorOperator.
erase( VariableSet::getVariableVisitTypeIndex<T>() ) > 0;
129template <
typename T,
typename F, DynamicVisitor::WithParam<T, F>>
130auto DynamicVisitor::makeVisitorOperator( F& f ) -> OperatorsStorageType::value_type {
132 VariableSet::getVariableVisitTypeIndex<T>(),
134 [&f](
const std::string& name, std::any& a, std::any&& userParam ) {
135 auto rp = std::any_cast<std::reference_wrapper<T>>( a );
140template <
typename T,
typename F, DynamicVisitor::WithoutParam<T, F>>
141auto DynamicVisitor::makeVisitorOperator( F& f ) -> OperatorsStorageType::value_type {
143 VariableSet::getVariableVisitTypeIndex<T>(),
145 [&f](
const std::string& name, std::any& a, std::any&& ) {
146 auto rp = std::any_cast<std::reference_wrapper<T>>( a );
Base class for dynamically configurable visitors Users can implement this interface to build custom v...
Base class for visitors with configurable per-type callbacks. Visiting will be prepared at running ti...
bool addOperator(F &&f)
Add a visiting operator.
~DynamicVisitor() override=default
allows the class to be derived
void addOrReplaceOperator(F &&f)
Add or replace a visiting operator.
bool removeOperator()
Remove a visiting operator.
bool hasOperator()
Test the existence of an operator associated with a type.
hepler function to manage enum as underlying types in VariableSet