-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy patherrordesc.h
More file actions
144 lines (125 loc) · 4.06 KB
/
errordesc.h
File metadata and controls
144 lines (125 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef ERRORDESC_H
#define ERRORDESC_H
/*
* NIST Utils Class Library
* clutils/errordesc.h
* April 1997
* David Sauder
* K. C. Morris
* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
#include <sc_export.h>
#include <string>
#include <iostream>
using namespace std;
#define _POC_ " report problem to scl-dev at groups.google.com"
typedef enum Severity {
SEVERITY_MAX = -5,
SEVERITY_DUMP = -4,
SEVERITY_EXIT = -3, // fatal
SEVERITY_BUG = -2, // non-recoverable error -- probably bug
SEVERITY_INPUT_ERROR = -1, // non-recoverable error
SEVERITY_WARNING = 0, // recoverable error
SEVERITY_INCOMPLETE = 1, // incomplete data
SEVERITY_USERMSG = 2, // possibly an error
SEVERITY_NULL = 3 // no error or message
} Severity;
#define DEBUG_OFF 0
#define DEBUG_USR 1
#define DEBUG_ALL 2
typedef int DebugLevel;
/******************************************************************
** Class: ErrorDescriptor
** Data Members:
** severity level of error
** user message
** detailed message
** Description:
** the error is a detailed error message + a severity level
** also keeps a user message separately
** detailed message gets sent to ostream
** uses std::string class to keep the user messages
** keeps severity of error
** created with or without error
** Status:
******************************************************************/
class SC_UTILS_EXPORT ErrorDescriptor {
private:
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4251 )
#endif
std::string _userMsg, _detailMsg;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
protected:
Severity _severity;
static DebugLevel _debug_level;
static ostream * _out; // note this will not be persistent
public:
ErrorDescriptor( Severity s = SEVERITY_NULL,
DebugLevel d = DEBUG_OFF );
~ErrorDescriptor( void );
void PrintContents( ostream & out = cout ) const;
void ClearErrorMsg() {
_severity = SEVERITY_NULL;
_userMsg.clear();
_detailMsg.clear();
}
// return the enum value of _severity
Severity severity() const {
return _severity;
}
Severity severity( Severity s ) {
return ( _severity = s );
}
std::string severityString() const;
Severity GetCorrSeverity( const char * s );
Severity GreaterSeverity( Severity s ) {
return ( ( s < _severity ) ? _severity = s : _severity );
}
std::string UserMsg() const {
return _userMsg;
}
void UserMsg( const char * msg );
void UserMsg( const std::string msg ) {
_userMsg.assign( msg );
}
void AppendToUserMsg( const char * msg );
void AppendToUserMsg( const char c );
void AppendToUserMsg( const std::string & msg ) {
_userMsg.append( msg );
}
void PrependToUserMsg( const char * msg );
std::string DetailMsg() const {
return _detailMsg;
}
void DetailMsg( const std::string msg ) {
_detailMsg.assign( msg );
}
void DetailMsg( const char * msg );
void AppendToDetailMsg( const char * msg );
void AppendToDetailMsg( const std::string & msg ) {
_detailMsg.append( msg );
}
void PrependToDetailMsg( const char * msg );
void AppendToDetailMsg( const char c );
Severity AppendFromErrorArg( ErrorDescriptor * err ) {
GreaterSeverity( err->severity() );
AppendToDetailMsg( err->DetailMsg() );
AppendToUserMsg( err->UserMsg() );
return severity();
}
DebugLevel debug_level() const {
return _debug_level;
}
void debug_level( DebugLevel d ) {
_debug_level = d;
}
void SetOutput( ostream * o ) {
_out = o;
}
} ;
#endif