libapt-pkg-dev  v0.9.7.5ubuntu5.4
Debian+Ubuntu APT Package Management
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlobalError Class Reference

#include <error.h>

Collaboration diagram for GlobalError:

Classes

struct  Item
 
struct  MsgStack
 

Public Types

enum  MsgType {
  FATAL = 40,
  ERROR = 30,
  WARNING = 20,
  NOTICE = 10,
  DEBUG = 0
}
 a message can have one of following severity More...
 

Public Member Functions

 GlobalError ()
 
bool Debug (const char *Description,...) __like_printf(2) __cold
 add a debug message to the list More...
 
bool DebugE (const char *Function, const char *Description,...) __like_printf(3) __cold
 add a debug message with errno to the list More...
 
void Discard ()
 clears the list of messages More...
 
void DumpErrors (std::ostream &out, MsgType const &threshold=WARNING, bool const &mergeStack=true)
 outputs the list of messages to the given stream More...
 
void DumpErrors (MsgType const &threshold)
 dumps the list of messages to std::cerr More...
 
void DumpErrors ()
 dumps the messages of type WARNING or higher to std::cerr More...
 
bool empty (MsgType const &trashhold=WARNING) const
 is the list empty? More...
 
bool Errno (const char *Function, const char *Description,...) __like_printf(3) __cold
 add an Error message with errno to the list More...
 
bool Error (const char *Description,...) __like_printf(2) __cold
 add an Error message to the list More...
 
bool Fatal (const char *Description,...) __like_printf(2) __cold
 add an fatal error message to the list More...
 
bool FatalE (const char *Function, const char *Description,...) __like_printf(3) __cold
 add a fatal error message with errno to the list More...
 
bool Insert (MsgType const &type, const char *Description,...) __like_printf(3) __cold
 adds an error message with the given type More...
 
bool InsertErrno (MsgType const &type, const char *Function, const char *Description,...) __like_printf(4) __cold
 adds an errno message with the given type More...
 
void MergeWithStack ()
 merge current and stack together More...
 
bool Notice (const char *Description,...) __like_printf(2) __cold
 add a notice message to the list More...
 
bool NoticeE (const char *Function, const char *Description,...) __like_printf(3) __cold
 add a notice message with errno to the list More...
 
bool PendingError () const
 is an error in the list? More...
 
bool PopMessage (std::string &Text)
 returns and removes the first (or last) message in the list More...
 
void PushToStack ()
 put the current Messages into the stack More...
 
void RevertToStack ()
 throw away all current messages More...
 
size_t StackCount () const
 return the deep of the stack More...
 
bool Warning (const char *Description,...) __like_printf(2) __cold
 add a warning message to the list More...
 
bool WarningE (const char *Function, const char *Description,...) __like_printf(3) __cold
 add a warning message with errno to the list More...
 

Private Member Functions

bool Insert (MsgType type, const char *Description, va_list &args, size_t &msgSize)
 
bool InsertErrno (MsgType type, const char *Function, const char *Description, va_list &args, int const errsv, size_t &msgSize)
 

Private Attributes

std::list< ItemMessages
 
bool PendingFlag
 
std::list< MsgStackStacks
 

Member Enumeration Documentation

a message can have one of following severity

Enumerator
FATAL 

Message will be printed instantly as it is likely that this error will lead to a complete crash.

ERROR 

An error does hinder the correct execution and should be corrected.

WARNING 

indicates problem that can lead to errors later on

NOTICE 

deprecation warnings, old fallback behavior, …

DEBUG 

for developers only in areas it is hard to print something directly

Constructor & Destructor Documentation

GlobalError::GlobalError ( )

Member Function Documentation

bool GlobalError::Debug ( const char *  Description,
  ... 
)

add a debug message to the list

Parameters
DescriptionFormat string for the message
Returns
false
bool GlobalError::DebugE ( const char *  Function,
const char *  Description,
  ... 
)

add a debug message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false
void GlobalError::Discard ( )

clears the list of messages

void GlobalError::DumpErrors ( std::ostream &  out,
MsgType const &  threshold = WARNING,
bool const &  mergeStack = true 
)

outputs the list of messages to the given stream

Note that all messages are discarded, also the notices displayed or not.

Parameters
[out]outoutput stream to write the messages in
thresholdminimim level considered
mergeStack
void GlobalError::DumpErrors ( MsgType const &  threshold)
inline

dumps the list of messages to std::cerr

Note that all messages are discarded, also the notices displayed or not.

Parameters
thresholdminimum level printed

References DumpErrors().

Here is the call graph for this function:

void GlobalError::DumpErrors ( )
inline

dumps the messages of type WARNING or higher to std::cerr

Note that all messages are discarded, displayed or not.

References WARNING.

Referenced by DumpErrors().

Here is the caller graph for this function:

bool GlobalError::empty ( MsgType const &  trashhold = WARNING) const

is the list empty?

The default checks if the list is empty or contains only notices, if you want to check if also no notices happend set the parameter flag to false.

Parameters
WithoutNoticedoes notices count, default is true, so no
Returns
true if an the list is empty, false otherwise
bool GlobalError::Errno ( const char *  Function,
const char *  Description,
  ... 
)

add an Error message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false
bool GlobalError::Error ( const char *  Description,
  ... 
)

add an Error message to the list

Parameters
DescriptionFormat string for the error message.
Returns
false
bool GlobalError::Fatal ( const char *  Description,
  ... 
)

add an fatal error message to the list

Most of the stuff we consider as "error" is also "fatal" for the user as the application will not have the expected result, but a fatal message here means that it gets printed directly to stderr in addiction to adding it to the list as the error leads sometimes to crashes and a maybe duplicated message is better than "Segfault" as the only displayed text

Parameters
DescriptionFormat string for the fatal error message.
Returns
false
bool GlobalError::FatalE ( const char *  Function,
const char *  Description,
  ... 
)

add a fatal error message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false
bool GlobalError::Insert ( MsgType const &  type,
const char *  Description,
  ... 
)

adds an error message with the given type

Parameters
typeof the error message
Descriptionof the error
bool GlobalError::Insert ( MsgType  type,
const char *  Description,
va_list &  args,
size_t &  msgSize 
)
private
bool GlobalError::InsertErrno ( MsgType const &  type,
const char *  Function,
const char *  Description,
  ... 
)

adds an errno message with the given type

Parameters
typeof the error message
Functionwhich failed
Descriptionof the error
bool GlobalError::InsertErrno ( MsgType  type,
const char *  Function,
const char *  Description,
va_list &  args,
int const  errsv,
size_t &  msgSize 
)
private
void GlobalError::MergeWithStack ( )

merge current and stack together

bool GlobalError::Notice ( const char *  Description,
  ... 
)

add a notice message to the list

A notice should be considered less severe than an error or a warning and can be ignored by the client without further problems for some times, but he should consider fixing the problem. This error type can be used for e.g. deprecation warnings of options.

Parameters
DescriptionFormat string for the message
Returns
false
bool GlobalError::NoticeE ( const char *  Function,
const char *  Description,
  ... 
)

add a notice message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false
bool GlobalError::PendingError ( ) const
inline

is an error in the list?

Returns
true if an error is included in the list, false otherwise

References PendingFlag.

bool GlobalError::PopMessage ( std::string &  Text)

returns and removes the first (or last) message in the list

Parameters
[out]Textmessage of the first/last item
Returns
true if the message was an error, false otherwise
void GlobalError::PushToStack ( )

put the current Messages into the stack

All "old" messages will be pushed into a stack to them later back, but for now the Message query will be empty and performs as no messages were present before.

The stack can be as deep as you want - all stack operations will only operate on the last element in the stack.

void GlobalError::RevertToStack ( )

throw away all current messages

size_t GlobalError::StackCount ( ) const
inline

return the deep of the stack

References Stacks.

bool GlobalError::Warning ( const char *  Description,
  ... 
)

add a warning message to the list

A warning should be considered less severe than an error and may be ignored by the client.

Parameters
DescriptionFormat string for the message
Returns
false
bool GlobalError::WarningE ( const char *  Function,
const char *  Description,
  ... 
)

add a warning message with errno to the list

A warning should be considered less severe than an error and may be ignored by the client.

Parameters
FunctionName of the function generates the warning.
DescriptionFormat string for the warning message.
Returns
false

Member Data Documentation

std::list<Item> GlobalError::Messages
private
bool GlobalError::PendingFlag
private

Referenced by PendingError().

std::list<MsgStack> GlobalError::Stacks
private

Referenced by StackCount().


The documentation for this class was generated from the following file: