The Gaudi Framework  master (37c0b60a)
ToolVisitor.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <GaudiKernel/IAlgTool.h>
14 #include <functional>
15 #include <regex>
16 #include <type_traits>
17 
20 class ToolVisitor {
21  struct IVisitor {
22  virtual ~IVisitor() = default;
23  virtual void visit( IAlgTool* ) const = 0;
24  };
25 
26 public:
39  template <typename Callable, typename = std::enable_if_t<std::is_invocable_r_v<void, Callable, IAlgTool*>>>
40  static void visit( const std::vector<IAlgTool*>& tools, Callable& callable,
41  const std::regex& reject_filter = s_noFilter ) {
42  class Visitor final : public IVisitor {
43  Callable* m_func;
44 
45  public:
46  Visitor( Callable* f ) : m_func{ f } {}
47  void visit( IAlgTool* alg_tool ) const override { std::invoke( *m_func, alg_tool ); }
48  };
49  recursiveVisit( tools, Visitor{ &callable }, reject_filter );
50  }
51 
52 private:
53  static void recursiveVisit( const std::vector<IAlgTool*>& tools, IVisitor const& visitor,
54  const std::regex& reject_filter );
55  static const std::regex s_noFilter;
56 };
IAlgTool
Definition: IAlgTool.h:33
std::vector< IAlgTool * >
IAlgTool.h
std::regex