*/
bool InsertErrno(MsgType type, const char* Function,
const char* Description, va_list &args,
- int const errsv, size_t &msgSize);
+ int const errsv, size_t &msgSize) APT_COLD;
/** \brief 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
+ * to stderr in addition 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
*
*
* \return \b true if an error is included in the list, \b false otherwise
*/
- inline bool PendingError() const {return PendingFlag;};
+ inline bool PendingError() const APT_PURE {return PendingFlag;};
/** \brief 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 happened set the parameter
- * flag to \b false.
+ * Can be used to check if the current stack level doesn't include
+ * anything equal or more severe than a given threshold, defaulting
+ * to warning level for historic reasons.
*
- * \param threshold minimim level considered
+ * \param threshold minimum level considered
*
- * \return \b true if an the list is empty, \b false otherwise
+ * \return \b true if the list is empty, \b false otherwise
*/
- bool empty(MsgType const &threshold = WARNING) const;
+ bool empty(MsgType const &threshold = WARNING) const APT_PURE;
/** \brief returns and removes the first (or last) message in the list
*
/** \brief outputs the list of messages to the given stream
*
- * Note that all messages are discarded, also the notices
- * displayed or not.
+ * Note that all messages are discarded, even undisplayed ones.
*
* \param[out] out output stream to write the messages in
- * \param threshold minimim level considered
- * \param mergeStack
+ * \param threshold minimum level considered
+ * \param mergeStack if true recursively dumps the entire stack
*/
void DumpErrors(std::ostream &out, MsgType const &threshold = WARNING,
bool const &mergeStack = true);
void MergeWithStack();
/** \brief return the deep of the stack */
- size_t StackCount() const {
+ size_t StackCount() const APT_PURE {
return Stacks.size();
}
Item(char const *Text, MsgType const &Type) :
Text(Text), Type(Type) {};
- friend std::ostream& operator<< (std::ostream &out, Item i) {
+ APT_HIDDEN friend std::ostream& operator<< (std::ostream &out, Item i) {
switch(i.Type) {
case FATAL:
- case ERROR: out << "E"; break;
- case WARNING: out << "W"; break;
- case NOTICE: out << "N"; break;
- case DEBUG: out << "D"; break;
+ case ERROR: out << 'E'; break;
+ case WARNING: out << 'W'; break;
+ case NOTICE: out << 'N'; break;
+ case DEBUG: out << 'D'; break;
+ }
+ out << ": ";
+ std::string::size_type line_start = 0;
+ std::string::size_type line_end;
+ while ((line_end = i.Text.find_first_of("\n\r", line_start)) != std::string::npos) {
+ if (line_start != 0)
+ out << std::endl << " ";
+ out << i.Text.substr(line_start, line_end - line_start);
+ line_start = i.Text.find_first_not_of("\n\r", line_end + 1);
+ if (line_start == std::string::npos)
+ break;
}
- return out << ": " << i.Text;
+ if (line_start == 0)
+ out << i.Text;
+ else if (line_start != std::string::npos)
+ out << std::endl << " " << i.Text.substr(line_start);
+ return out;
}
};
bool PendingFlag;
struct MsgStack {
- std::list<Item> const Messages;
+ std::list<Item> Messages;
bool const PendingFlag;
MsgStack(std::list<Item> const &Messages, bool const &Pending) :