1 
2 /*
3 * NIST Utils Class Library
4 * clutils/errordesc.cc
5 * February, 1993
6 * David Sauder
7 * K. C. Morris
8 
9 * Development of this software was funded by the United States Government,
10 * and is not subject to copyright.
11 */
12 
13 #include <errordesc.h>
14 #include <Str.h>
15 #include <sc_memmgr.h>
16 
17 DebugLevel ErrorDescriptor::_debug_level = DEBUG_OFF;
18 ostream  * ErrorDescriptor::_out = 0;
19 
20 void
PrintContents(ostream & out) const21 ErrorDescriptor::PrintContents( ostream & out ) const {
22     out << "Severity: " << severityString() << endl;
23     if( !_userMsg.empty() ) {
24         out << "User message in parens:" << endl << "(";
25         out << UserMsg() << ")" << endl;
26     }
27     if( !_detailMsg.empty() ) {
28         out << "Detailed message in parens:" << endl << "(";
29         out << DetailMsg() << ")" << endl;
30     }
31 }
32 
severityString() const33 std::string ErrorDescriptor::severityString() const {
34     std::string s;
35     switch( severity() ) {
36         case SEVERITY_NULL : {
37             s.assign( "SEVERITY_NULL" );
38             break;
39         }
40         case SEVERITY_USERMSG : {
41             s.assign( "SEVERITY_USERMSG" );
42             break;
43         }
44         case SEVERITY_INCOMPLETE : {
45             s.assign( "SEVERITY_INCOMPLETE" );
46             break;
47         }
48         case SEVERITY_WARNING : {
49             s.assign( "SEVERITY_WARNING" );
50             break;
51         }
52         case SEVERITY_INPUT_ERROR : {
53             s.assign( "SEVERITY_INPUT_ERROR" );
54             break;
55         }
56         case SEVERITY_BUG : {
57             s.assign( "SEVERITY_BUG" );
58             break;
59         }
60         case SEVERITY_EXIT : {
61             s.assign( "SEVERITY_EXIT" );
62             break;
63         }
64         case SEVERITY_DUMP : {
65             s.assign( "SEVERITY_DUMP" );
66             break;
67         }
68         case SEVERITY_MAX : {
69             s.assign( "SEVERITY_MAX" );
70             break;
71         }
72     }
73     return s;
74 }
75 
76 
77 Severity
GetCorrSeverity(const char * s)78 ErrorDescriptor::GetCorrSeverity( const char * s ) {
79     if( s && s[0] != 0 ) {
80         std::string s2;
81         StrToUpper( s, s2 );
82         if( !s2.compare( "SEVERITY_NULL" ) ) {
83             return SEVERITY_NULL;
84         }
85         if( !s2.compare( "SEVERITY_USERMSG" ) ) {
86             return SEVERITY_USERMSG;
87         }
88         if( !s2.compare( "SEVERITY_INCOMPLETE" ) ) {
89             return SEVERITY_INCOMPLETE;
90         }
91         if( !s2.compare( "SEVERITY_WARNING" ) ) {
92             return SEVERITY_WARNING;
93         }
94         if( !s2.compare( "SEVERITY_INPUT_ERROR" ) ) {
95             return SEVERITY_INPUT_ERROR;
96         }
97         if( !s2.compare( "SEVERITY_BUG" ) ) {
98             return SEVERITY_BUG;
99         }
100         if( !s2.compare( "SEVERITY_EXIT" ) ) {
101             return SEVERITY_EXIT;
102         }
103         if( !s2.compare( "SEVERITY_DUMP" ) ) {
104             return SEVERITY_DUMP;
105         }
106         if( !s2.compare( "SEVERITY_MAX" ) ) {
107             return SEVERITY_MAX;
108         }
109     }
110     cerr << "Internal error:  " << __FILE__ <<  __LINE__
111          << "\n" << _POC_ "\n";
112     cerr << "Calling ErrorDescriptor::GetCorrSeverity() with null string\n";
113     return SEVERITY_BUG;
114 }
115 
ErrorDescriptor(Severity s,DebugLevel d)116 ErrorDescriptor::ErrorDescriptor( Severity s,  DebugLevel d ) : _severity( s ) {
117     if( d  != DEBUG_OFF ) {
118         _debug_level = d;
119     }
120 }
121 
~ErrorDescriptor(void)122 ErrorDescriptor::~ErrorDescriptor( void ) {
123 }
124 
UserMsg(const char * msg)125 void ErrorDescriptor::UserMsg( const char * msg ) {
126     _userMsg.assign( msg );
127 }
128 
PrependToUserMsg(const char * msg)129 void ErrorDescriptor::PrependToUserMsg( const char * msg ) {
130     _userMsg.insert( 0, msg );
131 }
132 
AppendToUserMsg(const char c)133 void ErrorDescriptor::AppendToUserMsg( const char c ) {
134     _userMsg.append( &c );
135 }
136 
AppendToUserMsg(const char * msg)137 void ErrorDescriptor::AppendToUserMsg( const char * msg ) {
138     _userMsg.append( msg );
139 }
140 
DetailMsg(const char * msg)141 void ErrorDescriptor::DetailMsg( const char * msg ) {
142     _detailMsg.assign( msg );
143 }
144 
PrependToDetailMsg(const char * msg)145 void ErrorDescriptor::PrependToDetailMsg( const char * msg ) {
146     _detailMsg.insert( 0, msg );
147 }
148 
AppendToDetailMsg(const char c)149 void ErrorDescriptor::AppendToDetailMsg( const char c ) {
150     _detailMsg.append( &c );
151 }
152 
AppendToDetailMsg(const char * msg)153 void ErrorDescriptor::AppendToDetailMsg( const char * msg ) {
154     _detailMsg.append( msg );
155 }
156