##################################################################### */
/*}}}*/
// Include Files /*{{{*/
+#include <config.h>
+
#include <apt-pkg/error.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <list>
#include <iostream>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
#include <string>
#include <cstring>
+#include <algorithm>
-#include "config.h"
- /*}}}*/
+ /*}}}*/
// Global Error Object /*{{{*/
/* If the implementation supports posix threads then the accessor function
va_list args; \
size_t msgSize = 400; \
int const errsv = errno; \
- while (true) { \
+ bool retry; \
+ do { \
va_start(args,Description); \
- if (InsertErrno(TYPE, Function, Description, args, errsv, msgSize) == false) \
- break; \
+ retry = InsertErrno(TYPE, Function, Description, args, errsv, msgSize); \
va_end(args); \
- } \
+ } while (retry); \
return false; \
}
GEMessage(FatalE, FATAL)
va_list args;
size_t msgSize = 400;
int const errsv = errno;
- while (true) {
+ bool retry;
+ do {
va_start(args,Description);
- if (InsertErrno(type, Function, Description, args, errsv, msgSize) == false)
- break;
+ retry = InsertErrno(type, Function, Description, args, errsv, msgSize);
va_end(args);
- }
+ } while (retry);
return false;
}
/*}}}*/
msgSize = n + 1;
else
msgSize *= 2;
+ free(S);
return true;
}
bool GlobalError::NAME (const char *Description,...) { \
va_list args; \
size_t msgSize = 400; \
- while (true) { \
+ bool retry; \
+ do { \
va_start(args,Description); \
- if (Insert(TYPE, Description, args, msgSize) == false) \
- break; \
+ retry = Insert(TYPE, Description, args, msgSize); \
va_end(args); \
- } \
+ } while (retry); \
return false; \
}
GEMessage(Fatal, FATAL)
{
va_list args;
size_t msgSize = 400;
- while (true) {
+ bool retry;
+ do {
va_start(args,Description);
- if (Insert(type, Description, args, msgSize) == false)
- break;
+ retry = Insert(type, Description, args, msgSize);
va_end(args);
- }
+ } while (retry);
return false;
}
/*}}}*/
msgSize = n + 1;
else
msgSize *= 2;
+ free(S);
return true;
}
// check if another error message is pending
for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); m++)
+ m != Messages.end(); ++m)
if (m->Type == ERROR || m->Type == FATAL)
return Ret;
if (mergeStack == true)
for (std::list<MsgStack>::const_reverse_iterator s = Stacks.rbegin();
s != Stacks.rend(); ++s)
- Messages.insert(Messages.begin(), s->Messages.begin(), s->Messages.end());
+ std::copy(s->Messages.begin(), s->Messages.end(), std::front_inserter(Messages));
+
+ std::for_each(Messages.begin(), Messages.end(), [&threshold, &out](Item const &m) {
+ if (m.Type >= threshold)
+ out << m << std::endl;
+ });
- for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); m++)
- if (m->Type >= threshold)
- out << (*m) << std::endl;
Discard();
}
/*}}}*/
void GlobalError::Discard() {
Messages.clear();
PendingFlag = false;
-};
+}
/*}}}*/
// GlobalError::empty - does our error list include anything? /*{{{*/
-bool GlobalError::empty(MsgType const &trashhold) const {
+bool GlobalError::empty(MsgType const &threshold) const {
if (PendingFlag == true)
return false;
if (Messages.empty() == true)
return true;
- for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); m++)
- if (m->Type >= trashhold)
- return false;
-
- return true;
+ return std::find_if(Messages.begin(), Messages.end(), [&threshold](Item const &m) {
+ return m.Type >= threshold;
+ }) == Messages.end();
}
/*}}}*/
// GlobalError::PushToStack /*{{{*/
void GlobalError::PushToStack() {
- MsgStack pack(Messages, PendingFlag);
- Stacks.push_back(pack);
+ Stacks.emplace_back(Messages, PendingFlag);
Discard();
}
/*}}}*/
// GlobalError::MergeWithStack /*{{{*/
void GlobalError::MergeWithStack() {
MsgStack pack = Stacks.back();
- Messages.insert(Messages.begin(), pack.Messages.begin(), pack.Messages.end());
+ Messages.splice(Messages.begin(), pack.Messages);
PendingFlag = PendingFlag || pack.PendingFlag;
Stacks.pop_back();
}