47 static void sort(
typename std::vector<T> & vector);
53 static void sortDFS(
typename std::vector<T> & vector);
58 template <
typename T,
typename T2>
73 if (vector.size() <= 1)
82 std::multimap<std::string, T> suppliers_map;
83 for (
auto & v : vector)
89 for (
const auto & supplied_item : v->getSuppliedItems())
90 suppliers_map.emplace(supplied_item, v);
94 for (
auto & v : vector)
95 for (
const auto & requested_item : v->getRequestedItems())
97 const auto & [begin_it, end_it] = suppliers_map.equal_range(requested_item);
98 for (
const auto & [supplier_name, supplier_object] :
as_range(begin_it, end_it))
104 if (supplier_object != v)
105 graph.
addEdge(supplier_object, v);
109 const auto & sorted = graph.
dfs();
112 mooseAssert(sorted.size() == std::set<T>(vector.begin(), vector.end()).size(),
"Size mismatch");
117 template <
typename T,
typename T2>
120 const std::string & header)
122 std::ostringstream oss;
124 oss << header <<
":\n";
126 std::vector<std::string> names(cycle.size());
128 names[i] = static_cast<T>(cycle[i])->name();
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
static void sortDFS(typename std::vector< T > &vector)
Given a vector, sort using the depth-first search.
virtual const std::set< std::string > & getRequestedItems()=0
Return a set containing the names of items requested by the object.
void addEdge(const T &a, const T &b)
Add an edge between nodes 'a' and 'b'.
void libmesh_ignore(const Args &...)
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
DependencyResolverInterface()
Constructor.
virtual const std::set< std::string > & getSuppliedItems()=0
Return a set containing the names of items owned by the object.
static void sort(typename std::vector< T > &vector)
Given a vector, sort using the getRequested/SuppliedItems sets.
void addNode(const T &a)
Add a node 'a' to the graph.
const std::vector< T > & getCyclicDependencies() const
Interface for sorting dependent vectors of objects.
const std::vector< T > & dfs()
Do depth-first search from root nodes to obtain order in which graph nodes should be "executed"...
static void cyclicDependencyError(CyclicDependencyException< T2 > &e, const std::string &header)
A helper method for cyclic errors.
Class that represents the dependecy as a graph.
auto index_range(const T &sizable)
std::string join(const T &strings, const std::string &delimiter)
Python like join function for strings.