DependenciesGraph.h (1477B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "winget/ManifestCommon.h" 5 6 namespace AppInstaller::Manifest 7 { 8 struct DependencyGraph 9 { 10 // this constructor was intended for use during installation flow (we already have installer dependencies and there's no need to search the source again) 11 DependencyGraph(const Dependency& root, const DependencyList& rootDependencies, 12 std::function<const DependencyList(const Dependency&)> infoFunction); 13 14 DependencyGraph(const Dependency& root, std::function<const DependencyList(const Dependency&)> infoFunction); 15 16 void BuildGraph(); 17 18 void AddNode(const Dependency& node); 19 20 void AddAdjacent(const Dependency& node, const Dependency& adjacent); 21 22 bool HasNode(const Dependency& dependency); 23 24 bool HasLoop(); 25 26 void CheckForLoopsAndGetOrder(); 27 28 std::vector<Dependency> GetInstallationOrder(); 29 30 private: 31 // TODO make this function iterative 32 bool HasLoopDFS(std::set<Dependency> visited, const Dependency& node); 33 34 const Dependency& m_root; 35 std::map<Dependency, std::set<Dependency>> m_adjacents; 36 std::function<const DependencyList(const Dependency&)> getDependencies; 37 bool m_HasLoop = false; 38 bool m_rootDependencyEvaluated = false; 39 std::vector<Dependency> m_installationOrder; 40 std::vector<Dependency> m_toCheck; 41 }; 42 }