Browse Source

Added OnBadRehash() event.

release/0.19
JustinAJ 10 years ago
parent
commit
8273d519ae
  1. 8
      Jupiter/Rehash.cpp
  2. 10
      Jupiter/Rehash.h

8
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<Jupiter::Rehashable>::Node *n = rehashables.getNode(0);
Jupiter::DLList<Jupiter::Rehashable>::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;
}

10
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.
*/

Loading…
Cancel
Save