From 8273d519ae8615019152e30410c3b27c65ba40cb Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Mon, 20 Oct 2014 16:32:14 -0400 Subject: [PATCH] Added OnBadRehash() event. --- Jupiter/Rehash.cpp | 8 +++++++- Jupiter/Rehash.h | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Jupiter/Rehash.cpp b/Jupiter/Rehash.cpp index fc5af2f..dbc2c46 100644 --- a/Jupiter/Rehash.cpp +++ b/Jupiter/Rehash.cpp @@ -20,6 +20,7 @@ class RehashFunction : public Jupiter::Rehashable public: int(*function)(void); int OnRehash() { return function(); }; + bool OnBadRehash(bool removed) { return removed; }; RehashFunction(int(*func)(void)) { RehashFunction::function = func; }; }; @@ -60,6 +61,7 @@ unsigned int Jupiter::rehash() unsigned int total = 0; int r; Jupiter::DLList::Node *n = rehashables.getNode(0); + Jupiter::DLList::Node *d; while (n != nullptr) { r = n->data->OnRehash(); @@ -68,10 +70,14 @@ unsigned int Jupiter::rehash() total++; if (r < 0) { + d = n; n = n->next; - delete rehashables.remove(n->previous); + if (d->data->OnBadRehash(true)) + delete rehashables.remove(d); + else rehashables.remove(d); continue; } + rehashables.remove(n)->OnBadRehash(false); } n = n->next; } diff --git a/Jupiter/Rehash.h b/Jupiter/Rehash.h index ad7cb3d..7254c75 100644 --- a/Jupiter/Rehash.h +++ b/Jupiter/Rehash.h @@ -37,10 +37,18 @@ namespace Jupiter /** * @brief Rehashes an object's status. * - * @return 0 if no error occurs, a postive integer if an error occurs, or a negative integer if an error occurs and the object should be deleted. + * @return 0 if no error occurs, a postive integer if an error occurs, or a negative integer if an error occurs and the object should be removed. */ virtual int OnRehash() = 0; + /** + * @brief Fires when a non-zero value is returned by an object during a call to rehash(). + * + * @param removed True if the object was removed from the rehashable objects list, false otherwise. + * @return True if the object should be deleted, false otherwise. + */ + virtual bool OnBadRehash(bool removed) = 0; + /** * @brief Default constructor for the Rehashable class. */