ATLAS Offline Software
Loading...
Searching...
No Matches
Message.cxx
Go to the documentation of this file.
1//
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6// Please feel free to contact me (krumnack@iastate.edu) for bug
7// reports, feature suggestions, praise and complaints.
8
9
10//
11// includes
12//
13
15
16#include <cstdlib>
17#include <cstring>
18#include <iostream>
19#include <sstream>
23
24//
25// method implementations
26//
27
28namespace RCU
29{
30 Message ::
31 Message ()
32 : package (0), file (0), line (0), type (MESSAGE_UNSPECIFIED),
33 message (0)
34 {
35 }
36
37
38
39 void Message ::
40 send () const
41 {
42 MessageType mytype = type;
43 if (mytype < 0 || mytype > MESSAGE_UNSPECIFIED)
44 mytype = MESSAGE_UNSPECIFIED;
45
46 std::ostringstream str;
47
48 if (package != 0)
49 {
50 str << package << ":";
51 }
52 if (file != 0)
53 {
54 if (strncmp (file, "../", 3) == 0)
55 str << (file+3) << ":";
56 else
57 str << file << ":";
58 }
59 if (line != 0)
60 str << line << ":";
61
62 if (mytype != MESSAGE_UNSPECIFIED)
63 {
64 static const char * const type_names[MESSAGE_UNSPECIFIED] =
65 {"message", "warning", "error", "exception", "abort"};
66 str << type_names[mytype] << ":";
67 }
68
69 if (!str.str().empty())
70 str << " ";
71 if (message != 0)
72 str << message;
73 else
74 str << "(null)";
75
76 const char *envname = 0;
77 if (mytype == MESSAGE_ABORT)
78 envname = "ROOTCOREUTILS_ABORT";
79 else if (mytype == MESSAGE_EXCEPTION)
80 envname = "ROOTCOREUTILS_EXCEPTION";
81 if (envname)
82 {
83 const char *abort_type = getenv (envname);
84 const MessageType def_type = MESSAGE_EXCEPTION;
85
86 if (abort_type == 0)
87 {
88 mytype = def_type;
89 } else if (strcmp (abort_type, "abort") == 0)
90 {
91 mytype = MESSAGE_ABORT;
92 } else if (strcmp (abort_type, "exception") == 0)
93 {
94 mytype = MESSAGE_EXCEPTION;
95 } else
96 {
97 mytype = def_type;
98
99 RCU_WARN_MSG (std::string ("unknown value for ROOTCOREUTILS_ABORT ") + abort_type);
100 }
101 }
102
103 std::cout << str.str() << std::endl;
104 if (mytype == MESSAGE_EXCEPTION)
105 throw ExceptionMsg (file, line, str.str());
106 if (mytype == MESSAGE_ABORT)
107 std::abort ();
108 }
109}
#define RCU_WARN_MSG(message)
Definition PrintMsg.h:52
This module defines a variety of assert style macros.
Definition Assert.cxx:26
MessageType
Definition MessageType.h:24
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:38
@ MESSAGE_UNSPECIFIED
description: unspecified message type
Definition MessageType.h:41
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:35
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