#include <errorhandler.h>
Public Types | |
enum | ErrCode { NO_ERROR = 0, MESSAGE = 0 << 16, INFO = 1 << 16, WARNING = 2 << 16, ERROR = 3 << 16, SEVERE = 4 << 16, DEBUGOUTPUT = 5 << 16 } |
enum | VerbosityLevel { QUIET = 0, NORMAL = 1, VERBOSE = 2 } |
Public Member Functions | |
virtual void | operator() (int errcode, const std::string &msg) |
void | info (const char *format,...) OPENIMAGEIO_PRINTF_ARGS(2 |
void void | warning (const char *format,...) OPENIMAGEIO_PRINTF_ARGS(2 |
void void void | error (const char *format,...) OPENIMAGEIO_PRINTF_ARGS(2 |
void void void void | severe (const char *format,...) OPENIMAGEIO_PRINTF_ARGS(2 |
void void void void void | message (const char *format,...) OPENIMAGEIO_PRINTF_ARGS(2 |
void void void void void void | debug (const char *format,...) OPENIMAGEIO_PRINTF_ARGS(2 |
void | vWarning (const char *format, va_list argptr) |
void | vError (const char *format, va_list argptr) |
void | vSevere (const char *format, va_list argptr) |
void | vMessage (const char *format, va_list argptr) |
void | vDebug (const char *, va_list) |
void | info (const std::string &msg) |
void | warning (const std::string &msg) |
void | error (const std::string &msg) |
void | severe (const std::string &msg) |
void | message (const std::string &msg) |
void | debug (const std::string &) |
void | verbosity (int v) |
int | verbosity () const |
Static Public Member Functions | |
static ErrorHandler & | default_handler () |
ErrorHandler is a simple class that accepts error messages (classified as errors, severe errors, warnings, info, messages, or debug output) and handles them somehow. By default it just prints the messages to stdout and/or stderr (and supresses some based on a "verbosity" level).
The basic idea is that your library code has no idea whether some application that will use it someday will want errors or other output to be sent to the console, go to a log file, be intercepted by the calling application, or something else. So you punt, by having your library take a pointer to an ErrorHandler, passed in from the calling app (and possibly subclassed to have arbitrarily different behavior from the default console output) and make all error-like output via the ErrorHandler*.
Error categories. We use broad categories in the high order bits. A library may just use these categories, or may create individual error codes as long as they have the right high bits to designate their category (file not found = ERROR + 1, etc.).
void void void void void void OpenImageIO::ErrorHandler::debug | ( | const char * | format, | |
... | ||||
) |
Debugging message with printf-like formatted error message. This will not produce any output if not in DEBUG mode, or if verbosity is QUIET.
static ErrorHandler& OpenImageIO::ErrorHandler::default_handler | ( | ) | [static] |
One built-in handler that can always be counted on to be present and just echoes the error messages to the console (stdout or stderr, depending on the error category).
void void void OpenImageIO::ErrorHandler::error | ( | const char * | format, | |
... | ||||
) |
Error message with printf-like formatted error message. Will print regardless of verbosity.
void OpenImageIO::ErrorHandler::info | ( | const char * | format, | |
... | ||||
) |
Info message with printf-like formatted error message. Will not print unless verbosity >= VERBOSE.
void void void void void OpenImageIO::ErrorHandler::message | ( | const char * | format, | |
... | ||||
) |
Prefix-less message with printf-like formatted error message. Will not print if verbosity is QUIET. Also note that unlike the other routines, message() will NOT append a newline.
virtual void OpenImageIO::ErrorHandler::operator() | ( | int | errcode, | |
const std::string & | msg | |||
) | [virtual] |
The main (or "full detail") method -- takes a code (with high bits being an ErrCode) and writes the message, with a prefix indicating the error category (no prefix for "MESSAGE") and error string.
void void void void OpenImageIO::ErrorHandler::severe | ( | const char * | format, | |
... | ||||
) |
Severe error message with printf-like formatted error message. Will print regardless of verbosity.
int OpenImageIO::ErrorHandler::verbosity | ( | ) | const [inline] |
Return the current verbosity level.
void OpenImageIO::ErrorHandler::verbosity | ( | int | v | ) | [inline] |
Set desired verbosity level.
void void OpenImageIO::ErrorHandler::warning | ( | const char * | format, | |
... | ||||
) |
Warning message with printf-like formatted error message. Will not print unless verbosity >= NORMAL (i.e. will suppress for QUIET).