#pragma once #include #include #include "task.hpp" namespace build_system { struct IncorrectBuildGraph {}; struct Rule { size_t target; size_t dependency; }; struct Target { size_t id; Task task; std::vector dependences; }; class BuildGraph { private: // manage DFS, topsort, etc. safe class TraversalManager { private: class View; public: TraversalManager(const BuildGraph& build_graph) : build_graph_(build_graph), epoch_(kNeverVisited + 1) {} void initArray() { visited_ = std::vector(build_graph_.graph_.size(), kNeverVisited); } View getView(); private: void nextEpoch() { ++epoch_; } void DFS(size_t vertex, std::vector& current_visited); private: static const size_t kCurrentWayEpoch; static const size_t kNeverVisited; const BuildGraph &build_graph_; std::vector visited_; size_t epoch_; }; public: BuildGraph(const std::vector& rules, std::vector&& tasks); void isCorrectOrThrow(size_t target) const; bool isCorrect(size_t target) const; std::vector getRequiredTargetsOrder(size_t target) const; private: std::vector graph_; mutable TraversalManager traversal_manager_; }; } // namespace build_system