ATLAS Offline Software
Loading...
Searching...
No Matches
AsgToolMacros.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef AsgToolMacros_H
6#define AsgToolMacros_H
7
8// David Adams
9// January 2014
10//
11// CPP macros that turn ASG tools into Athena tools.
12
13#ifndef XAOD_STANDALONE
14
15// System include(s).
16#include <string>
17
18// This is used in the body of the tool interface class declaration, e.g.
19// class MyToolInterface:
20// virtual public IAsgTool {
21// ASG_TOOL_INTERFACE(MyToolInterface)
22// .
23// .
24// .
25// };
26
27// We need to pass both the tool type and the parent pointer down to
28// AthAlgTool, but the intermediate class only takes a single string parameter.
29// Sort of like passing a camel through the eye of a needle, but as MAD
30// magazine observed, nowhere is the size of the needle specified.
31// So, we pack the type, name, name parent pointer into a string:
32// PTR#TYPE/NAME
33// where PTR is a hex string representation of the pointer.
34// We then unpack this in the AsgTools constructor.
35
36namespace asg {
37 std::string ptrToString (const void* p);
38}
39
40#define ASG_TOOL_INTERFACE(CLASSNAME) \
41public: \
42 static const InterfaceID& interfaceID() { \
43 static const InterfaceID myid(#CLASSNAME, 1, 0 ); \
44 return myid; \
45 }
46
47// This is used in the body of the tool class declaration, e.g.
48// class MyTool
49// : public MyToolInterface,
50// : public asg::AsgTool {
51// ASG_TOOL_CLASS(MyTool, MyToolInterface)
52// .
53// .
54// .
55// };
56// Macros are provided for 0, 1 or 2 interfaces.
57// Need work here to make this work for an arbitrary number of interfaces.
58
59// Extra std::string around the ptrToString calls below needed to work around
60// problem with cppcheck 2.0,
61// which gets confused about the return type of ptrToString.
62#define ASG_TOOL_CLASS0(CLASSNAME) \
63public: \
64 CLASSNAME(const std::string& type, const std::string& myname, const IInterface* parent) \
65: CLASSNAME(std::string(asg::ptrToString(parent))+"#"+type+"/"+myname) { \
66 }
67
68#define ASG_TOOL_CLASS(CLASSNAME, INT1) \
69public: \
70 CLASSNAME(const std::string& type, const std::string& myname, const IInterface* parent) \
71: CLASSNAME(std::string(asg::ptrToString(parent))+"#"+type+"/"+myname) { \
72 declareInterface<INT1>(this); \
73 }
74
75#define ASG_TOOL_CLASS1 ASG_TOOL_CLASS
76
77#define ASG_TOOL_CLASS2(CLASSNAME, INT1, INT2) \
78public: \
79 CLASSNAME(const std::string& type, const std::string& myname, const IInterface* parent) \
80: CLASSNAME(std::string(asg::ptrToString(parent))+"#"+type+"/"+myname) { \
81 declareInterface<INT1>(this); \
82 declareInterface<INT2>(this); \
83 }
84
85#define ASG_TOOL_CLASS3(CLASSNAME, INT1, INT2, INT3) \
86public: \
87 CLASSNAME(const std::string& type, const std::string& myname, const IInterface* parent) \
88: CLASSNAME(std::string(asg::ptrToString(parent))+"#"+type+"/"+myname) { \
89 declareInterface<INT1>(this); \
90 declareInterface<INT2>(this); \
91 declareInterface<INT3>(this); \
92 }
93
94#else
95
96#define ASG_TOOL_INTERFACE(CLASSNAME)
97#define ASG_TOOL_CLASS(CLASSNAME, INT1)
98#define ASG_TOOL_CLASS0(CLASSNAME)
99#define ASG_TOOL_CLASS1(CLASSNAME, INT1)
100#define ASG_TOOL_CLASS2(CLASSNAME, INT1, INT2)
101#define ASG_TOOL_CLASS3(CLASSNAME, INT1, INT2, INT3)
102
103#endif
104
105#endif
std::string ptrToString(const void *p)