ATLAS Offline Software
MessagePrinterOverlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
17 #include <cstdlib>
18 
19 //
20 // method implementations
21 //
22 
23 namespace asg
24 {
26  MessagePrinterOverlay (IMessagePrinter *val_printer) noexcept
27  : m_saved (getCurrent()), m_current (val_printer)
28  {
29  using namespace msgAsgMessaging;
30 
31  if (val_printer == nullptr)
32  {
33  ANA_MSG_FATAL ("nullptr passed illegally");
34  std::abort ();
35  }
36  getCurrent() = val_printer;
37  }
38 
39 
40 
42  ~MessagePrinterOverlay () noexcept
43  {
44  using namespace msgAsgMessaging;
45 
46  if (getCurrent() != m_current)
47  {
48  ANA_MSG_FATAL ("the overlay message printer changed underhand this should never happen");
49  std::abort ();
50  }
51  getCurrent() = m_saved;
52  }
53 
54 
55 
56  IMessagePrinter& MessagePrinterOverlay ::
57  current () noexcept
58  {
59  return *getCurrent();
60  }
61 
62 
63 
64  IMessagePrinter*& MessagePrinterOverlay ::
65  getCurrent () noexcept
66  {
67  static MessagePrinter defaultPrinter;
68  static IMessagePrinter *pointer = &defaultPrinter;
69  return pointer;
70  }
71 }
asg
Definition: DataHandleTestTool.h:28
asg::MessagePrinterOverlay::MessagePrinterOverlay
MessagePrinterOverlay(MessagePrinterOverlay &)=delete
MessagePrinter.h
asg::MessagePrinterOverlay::getCurrent
static IMessagePrinter *& getCurrent() noexcept
get a reference to the pointer to the current IMessagePrinter
Definition: MessagePrinterOverlay.cxx:65
MessagePrinterOverlay.h
asg::MessagePrinterOverlay::m_saved
IMessagePrinter * m_saved
the stored message printer we need to restore
Definition: MessagePrinterOverlay.h:73
asg::MessagePrinterOverlay::current
static IMessagePrinter & current() noexcept
get the current IMessagePrinter
Definition: MessagePrinterOverlay.cxx:57
asg::MessagePrinterOverlay::~MessagePrinterOverlay
~MessagePrinterOverlay() noexcept
remove the currently overlaid printer
Definition: MessagePrinterOverlay.cxx:42
ANA_MSG_FATAL
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:296
asg::MessagePrinterOverlay::m_current
IMessagePrinter * m_current
the current message printer we should have when we restore
Definition: MessagePrinterOverlay.h:77
MessageCheckLocal.h