ATLAS Offline Software
Loading...
Searching...
No Matches
Message.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
13#include <cstdlib>
14#include <cstring>
15#include <iostream>
16#include <sstream>
20
21//
22// method implementations
23//
24
25namespace RCU
26{
27 Message ::
28 Message ()
29 : package (0), file (0), line (0), type (MESSAGE_UNSPECIFIED),
30 message (0)
31 {
32 }
33
34
35
36 void Message ::
37 send () const
38 {
39 MessageType mytype = type;
40 if (mytype < 0 || mytype > MESSAGE_UNSPECIFIED)
41 mytype = MESSAGE_UNSPECIFIED;
42
43 std::ostringstream str;
44
45 if (package != 0)
46 {
47 str << package << ":";
48 }
49 if (file != 0)
50 {
51 if (strncmp (file, "../", 3) == 0)
52 str << (file+3) << ":";
53 else
54 str << file << ":";
55 }
56 if (line != 0)
57 str << line << ":";
58
59 if (mytype != MESSAGE_UNSPECIFIED)
60 {
61 static const char * const type_names[MESSAGE_UNSPECIFIED] =
62 {"message", "warning", "error", "exception", "abort"};
63 str << type_names[mytype] << ":";
64 }
65
66 if (!str.str().empty())
67 str << " ";
68 if (message != 0)
69 str << message;
70 else
71 str << "(null)";
72
73 const char *envname = 0;
74 if (mytype == MESSAGE_ABORT)
75 envname = "ROOTCOREUTILS_ABORT";
76 else if (mytype == MESSAGE_EXCEPTION)
77 envname = "ROOTCOREUTILS_EXCEPTION";
78 if (envname)
79 {
80 const char *abort_type = getenv (envname);
81 const MessageType def_type = MESSAGE_EXCEPTION;
82
83 if (abort_type == 0)
84 {
85 mytype = def_type;
86 } else if (strcmp (abort_type, "abort") == 0)
87 {
88 mytype = MESSAGE_ABORT;
89 } else if (strcmp (abort_type, "exception") == 0)
90 {
91 mytype = MESSAGE_EXCEPTION;
92 } else
93 {
94 mytype = def_type;
95
96 RCU_WARN_MSG (std::string ("unknown value for ROOTCOREUTILS_ABORT ") + abort_type);
97 }
98 }
99
100 std::cout << str.str() << std::endl;
101 if (mytype == MESSAGE_EXCEPTION)
102 throw ExceptionMsg (file, line, str.str());
103 if (mytype == MESSAGE_ABORT)
104 std::abort ();
105 }
106}
#define RCU_WARN_MSG(message)
Definition PrintMsg.h:47
This module defines a variety of assert style macros.
Definition Assert.cxx:23
MessageType
Definition MessageType.h:19
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:33
@ MESSAGE_UNSPECIFIED
description: unspecified message type
Definition MessageType.h:36
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:30
const char * package
description: the location where the message was send
MessageType type
description: the type of this message
const char * message
description: the actual message we are sending or 0 if there isn't one