summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2010-06-25 19:16:12 +0200
committerDavid Kalnischkies <kalnischkies@gmail.com>2010-06-25 19:16:12 +0200
commitc4ba7c44ff03d67ff982bbab26dc48d796041e02 (patch)
tree500071e2c7fa262c2a1e054e23a25a7470d192a4 /apt-pkg
parent98ee7cd35cf205c52b3698ee91cec76d704a3937 (diff)
add a simple stack handling to be able to delay error handling
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/error.cc32
-rw-r--r--apt-pkg/contrib/error.h35
2 files changed, 65 insertions, 2 deletions
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index 837d9e615..8cee21c9c 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -181,7 +181,13 @@ bool GlobalError::PopMessage(std::string &Text) {
}
/*}}}*/
// GlobalError::DumpErrors - Dump all of the errors/warns to cerr /*{{{*/
-void GlobalError::DumpErrors(std::ostream &out, MsgType const &trashhold) {
+void GlobalError::DumpErrors(std::ostream &out, MsgType const &trashhold,
+ bool const &mergeStack) {
+ 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());
+
for (std::list<Item>::const_iterator m = Messages.begin();
m != Messages.end(); m++)
if (m->Type >= trashhold)
@@ -211,3 +217,27 @@ bool GlobalError::empty(MsgType const &trashhold) const {
return true;
}
/*}}}*/
+// GlobalError::PushToStack /*{{{*/
+void GlobalError::PushToStack() {
+ MsgStack pack(Messages, PendingFlag);
+ Stacks.push_back(pack);
+ Discard();
+}
+ /*}}}*/
+// GlobalError::RevertToStack /*{{{*/
+void GlobalError::RevertToStack() {
+ Discard();
+ MsgStack pack = Stacks.back();
+ Messages = pack.Messages;
+ PendingFlag = pack.PendingFlag;
+ Stacks.pop_back();
+}
+ /*}}}*/
+// GlobalError::MergeWithStack /*{{{*/
+void GlobalError::MergeWithStack() {
+ MsgStack pack = Stacks.back();
+ Messages.insert(Messages.begin(), pack.Messages.begin(), pack.Messages.end());
+ PendingFlag = PendingFlag || pack.PendingFlag;
+ Stacks.pop_back();
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h
index fc7b38f1b..73735162d 100644
--- a/apt-pkg/contrib/error.h
+++ b/apt-pkg/contrib/error.h
@@ -206,7 +206,8 @@ public: /*{{{*/
* \param[out] out output stream to write the messages in
* \param WithoutNotice output notices or not
*/
- void DumpErrors(std::ostream &out, MsgType const &trashhold = WARNING);
+ void DumpErrors(std::ostream &out, MsgType const &trashhold = WARNING,
+ bool const &mergeStack = true);
/** \brief dumps the list of messages to std::cerr
*
@@ -219,6 +220,28 @@ public: /*{{{*/
DumpErrors(std::cerr, trashhold);
}
+ /** \brief 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 PushToStack();
+
+ /** \brief throw away all current messages */
+ void RevertToStack();
+
+ /** \brief merge current and stack together */
+ void MergeWithStack();
+
+ /** \brief return the deep of the stack */
+ size_t StackCount() const {
+ return Stacks.size();
+ }
+
GlobalError();
/*}}}*/
private: /*{{{*/
@@ -244,6 +267,16 @@ private: /*{{{*/
std::list<Item> Messages;
bool PendingFlag;
+ struct MsgStack {
+ std::list<Item> const Messages;
+ bool const PendingFlag;
+
+ MsgStack(std::list<Item> const &Messages, bool const &Pending) :
+ Messages(Messages), PendingFlag(Pending) {};
+ };
+
+ std::list<MsgStack> Stacks;
+
bool InsertErrno(MsgType type, const char* Function,
const char* Description, va_list const &args);
bool Insert(MsgType type, const char* Description,