From 45957bb0a61eb41bd9196ff2b4c180cd31efc2b0 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Tue, 6 Aug 2013 12:19:33 +0100 Subject: [PATCH] Issue #39 work. Added some helper functions for computing plugin overlaps. --- src/backend/metadata.cpp | 61 ++++++++++++++++++++++++++++++++++++++++ src/backend/metadata.h | 5 ++++ 2 files changed, 66 insertions(+) diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index 1c7af0cf..a439934e 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -518,6 +518,37 @@ namespace boss { return formIDs; } + bool Plugin::DoFormIDsOverlap(const Plugin& plugin) const { + //Basically std::set_intersection except with an early exit instead of an append to results. + + set otherFormIDs = plugin.FormIDs(); + + set::const_iterator i = formIDs.begin(), + j = otherFormIDs.begin(), + iend = formIDs.end(), + jend = otherFormIDs.end(); + + while (i != iend && j != jend) { + if (*i < *j) + ++i; + else if (*j < *i) + ++j; + else + return true; + } + + return false; + } + + size_t Plugin::NumOverrideFormIDs() const { + size_t num = 0; + for (set::const_iterator it = formIDs.begin(), endIt=formIDs.end(); it != endIt; ++it) { + if (!boost::iequals(it->Plugin(), name)) + ++num; + } + return num; + } + std::set Plugin::OverlapFormIDs(const Plugin& plugin) const { set otherFormIDs = plugin.FormIDs(); set overlap; @@ -698,4 +729,34 @@ namespace boss { else return false; } + + //The map maps each plugin name to a vector of names of plugins that overlap with it and should load before it. + void CalcPluginOverlaps(const std::list& plugins, std::map< std::string, std::vector >& overlapMap) { + for (list::const_iterator it=plugins.begin(), + endit=plugins.end(); + it != endit; + ++it) { + list::const_iterator jt = it; + ++jt; + for (jt, endit; jt != endit; ++jt) { + if (it->DoFormIDsOverlap(*jt)) { + std::string key; + std::string value; + if (it->NumOverrideFormIDs() >= jt->NumOverrideFormIDs()) { + key = jt->Name(); + value = it->Name(); + } else { + key = it->Name(); + value = jt->Name(); + } + map< string, vector >::iterator mapIt = overlapMap.find(key); + if (mapIt == overlapMap.end()) { + overlapMap.insert(pair >(key, vector(1, value))); + } else { + mapIt->second.push_back(value); + } + } + } + } + } } diff --git a/src/backend/metadata.h b/src/backend/metadata.h index 351b12b1..ddbc4617 100644 --- a/src/backend/metadata.h +++ b/src/backend/metadata.h @@ -174,6 +174,8 @@ namespace boss { bool operator != (const Plugin& rhs) const; //Load ordering functions. + bool DoFormIDsOverlap(const Plugin& plugin) const; + size_t NumOverrideFormIDs() const; std::set OverlapFormIDs(const Plugin& plugin) const; std::set OverrideFormIDs() const; bool MustLoadAfter(const Plugin& plugin) const; //Checks masters, reqs and loadAfter. @@ -209,6 +211,9 @@ namespace boss { bool load_order_sort(const Plugin& lhs, const Plugin& rhs); bool IsPlugin(const std::string& file); + + //The map maps each plugin name to a vector of names of plugins that overlap with it and should load before it. + void CalcPluginOverlaps(const std::list& plugins, std::map< std::string, std::vector >& overlapMap); } #endif