+ for (size_t n = I_BEGIN + 1; n != I_END; ++n)
+ SetPriority(mod, (Implementation)n, s);
+
+ return true;
+}
+
+bool ModuleManager::SetPriority(Module* mod, Implementation i, PriorityState s, Module** modules, size_t sz)
+{
+ /** To change the priority of a module, we first find its position in the vector,
+ * then we find the position of the other modules in the vector that this module
+ * wants to be before/after. We pick off either the first or last of these depending
+ * on which they want, and we make sure our module is *at least* before or after
+ * the first or last of this subset, depending again on the type of priority.
+ */
+ size_t swap_pos = 0;
+ size_t source = 0;
+ bool swap = true;
+ bool found = false;
+
+ /* Locate our module. This is O(n) but it only occurs on module load so we're
+ * not too bothered about it
+ */
+ for (size_t x = 0; x != EventHandlers[i].size(); ++x)
+ {
+ if (EventHandlers[i][x] == mod)
+ {
+ source = x;
+ found = true;
+ break;
+ }
+ }
+
+ /* Eh? this module doesnt exist, probably trying to set priority on an event
+ * theyre not attached to.
+ */
+ if (!found)
+ return false;
+
+ switch (s)
+ {
+ /* Dummy value */
+ case PRIO_DONTCARE:
+ swap = false;
+ break;
+ /* Module wants to be first, sod everything else */
+ case PRIO_FIRST:
+ swap_pos = 0;
+ break;
+ /* Module is submissive and wants to be last... awww. */
+ case PRIO_LAST:
+ if (EventHandlers[i].empty())
+ swap_pos = 0;
+ else
+ swap_pos = EventHandlers[i].size() - 1;
+ break;
+ /* Place this module after a set of other modules */
+ case PRIO_AFTER:
+ {
+ /* Find the latest possible position */
+ swap_pos = 0;
+ swap = false;
+ for (size_t x = 0; x != EventHandlers[i].size(); ++x)
+ {
+ for (size_t n = 0; n < sz; ++n)
+ {
+ if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x >= swap_pos) && (source <= swap_pos))
+ {
+ swap_pos = x;
+ swap = true;
+ }
+ }
+ }
+ }
+ break;
+ /* Place this module before a set of other modules */
+ case PRIO_BEFORE:
+ {
+ swap_pos = EventHandlers[i].size() - 1;
+ swap = false;
+ for (size_t x = 0; x != EventHandlers[i].size(); ++x)
+ {
+ for (size_t n = 0; n < sz; ++n)
+ {
+ if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x <= swap_pos) && (source >= swap_pos))
+ {
+ swap = true;
+ swap_pos = x;
+ }
+ }
+ }
+ }
+ break;
+ }
+
+ /* Do we need to swap? */
+ if (swap && (swap_pos != source))
+ std::swap(EventHandlers[i][swap_pos], EventHandlers[i][source]);
+
+ return true;
+}
+
+std::string& ModuleManager::LastError()
+{
+ return LastModuleError;