6 #ifndef _ComponentVisitor_H_
7 #define _ComponentVisitor_H_
11 #include <type_traits>
14 #include "GaudiKernel/IAlgTool.h"
15 #include "GaudiKernel/Algorithm.h"
18 class ComponentVisitorBase {
36 template <
class T_Component,
class T_TestVisited = std::set<T_Component*> >
37 class ComponentVisitor :
public ComponentVisitorBase {
39 virtual ~IVisitor() =
default;
40 virtual void visit( T_Component* )
const = 0;
44 static std::vector<T_Component *> *getChilds(T_Component *a_component);
58 template <
typename Callable,
typename = std::enable_if_t<std::is_invocable_r_v<
void, Callable, T_Component*>>>
59 static T_TestVisited visit(
const std::vector<T_Component*>& components,
61 const std::regex& reject_filter = ComponentVisitorBase::s_noFilter,
62 T_TestVisited &&
ignore = T_TestVisited()) {
63 class Visitor
final :
public IVisitor {
64 const Callable* m_func;
67 Visitor( Callable*
f ) : m_func{
f} {}
68 void visit( T_Component* a_component )
const override { std::invoke( *m_func, a_component ); }
70 recursiveVisit( components, Visitor{&callable}, reject_filter,
ignore );
75 static void recursiveVisit(
const std::vector<T_Component*>& components, IVisitor
const& visitor,
77 T_TestVisited &visited);
82 std::pair<bool,bool> insert(
const Gaudi::Algorithm *) {
return std::make_pair(
true,
true); }
85 using ToolVisitor = ComponentVisitor<IAlgTool>;
86 using AlgorithmVisitor = ComponentVisitor<Gaudi::Algorithm, NoVisitTester>;