CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmLinkItemGraphVisitor.h
blob0d6676ad6483de83b86a0d35c1cd1624ca2b9966
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <utility>
10 #include "cmLinkItem.h"
12 class cmGeneratorTarget;
14 /** \class cmLinkItemGraphVisitor
15 * \brief Visits a graph of linked items.
17 * Allows to visit items and dependency links (direct and indirect) between
18 * those items.
19 * This abstract class takes care of the graph traversal, making sure that:
20 * - it terminates even in the presence of cycles;
21 * - it visits every object once (and only once);
22 * - it visits the objects in the same order every time.
24 * Children classes only have to implement OnItem() etc. to handle whatever
25 * logic they care about.
27 class cmLinkItemGraphVisitor
29 public:
30 virtual ~cmLinkItemGraphVisitor() = default;
32 virtual void VisitGraph(std::string const& name) = 0;
34 void VisitItem(cmLinkItem const& item);
36 protected:
37 enum class DependencyType
39 LinkInterface,
40 LinkPublic,
41 LinkPrivate,
42 Object,
43 Utility
46 virtual void OnItem(cmLinkItem const& item) = 0;
48 virtual void OnDirectLink(cmLinkItem const& depender,
49 cmLinkItem const& dependee, DependencyType dt) = 0;
51 virtual void OnIndirectLink(cmLinkItem const& depender,
52 cmLinkItem const& dependee) = 0;
54 private:
55 std::set<std::string> VisitedItems;
57 std::set<std::pair<std::string, std::string>> VisitedLinks;
59 void VisitLinks(cmLinkItem const& item, cmLinkItem const& rootItem);
60 void VisitLinks(cmLinkItem const& item, cmLinkItem const& rootItem,
61 std::string const& config);
63 using Dependency = std::pair<DependencyType, cmLinkItem>;
64 using DependencyMap = std::map<std::string, Dependency>;
66 bool ItemVisited(cmLinkItem const& item);
67 bool LinkVisited(cmLinkItem const& depender, cmLinkItem const& dependee);
69 static void GetDependencies(cmGeneratorTarget const& target,
70 std::string const& config,
71 DependencyMap& dependencies);