diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-24 09:21:05 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-25 13:02:06 +0200 |
commit | dcb3aa5dedc63332864eeb49d5ba3bb1c28bb26b (patch) | |
tree | 489a06d6acdf86a25f911c20782dd28c34d26161 | |
parent | ae23c335e0988111e58feef75df1d50b697359aa (diff) |
libshiboken: Extract a template base class for the dependency graph
Task-number: PYSIDE-2404
Task-number: PYSIDE-2675
Pick-to: 6.7
Change-Id: I4121275e3a89a60cdac38a02bf1cf41619270946
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r-- | sources/shiboken6/libshiboken/bindingmanager.cpp | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp index 84424a78a..60460c6ab 100644 --- a/sources/shiboken6/libshiboken/bindingmanager.cpp +++ b/sources/shiboken6/libshiboken/bindingmanager.cpp @@ -26,28 +26,44 @@ namespace Shiboken using WrapperMap = std::unordered_map<const void *, SbkObject *>; -class Graph +template <class NodeType> +class BaseGraph { public: - using NodeList = std::vector<PyTypeObject *>; - using NodeSet = std::unordered_set<const PyTypeObject *>; + using NodeList = std::vector<NodeType>; + using NodeSet = std::unordered_set<NodeType>; - using Edges = std::unordered_map<PyTypeObject *, NodeList>; + using Edges = std::unordered_map<NodeType, NodeList>; Edges m_edges; - Graph() = default; + BaseGraph() = default; - void addEdge(PyTypeObject *from, PyTypeObject *to) + void addEdge(NodeType from, NodeType to) { m_edges[from].push_back(to); } + NodeSet nodeSet() const + { + NodeSet result; + for (const auto &p : m_edges) { + result.insert(p.first); + for (const auto node2 : p.second) + result.insert(node2); + } + return result; + } +}; + +class Graph : public BaseGraph<PyTypeObject *> +{ +public: + Graph() = default; + BindingManager::TypeCptrPair identifyType(void *cptr, PyTypeObject *type, PyTypeObject *baseType) const; bool dumpTypeGraph(const char *fileName) const; - NodeSet nodeSet() const; - }; BindingManager::TypeCptrPair Graph::identifyType(void *cptr, PyTypeObject *type, PyTypeObject *baseType) const @@ -84,17 +100,6 @@ static void formatDotNode(const char *nameC, std::ostream &file) file << " ]\n"; } -Graph::NodeSet Graph::nodeSet() const -{ - NodeSet result; - for (const auto &p : m_edges) { - result.insert(p.first); - for (const PyTypeObject *node2 : p.second) - result.insert(node2); - } - return result; -} - bool Graph::dumpTypeGraph(const char *fileName) const { std::ofstream file(fileName); |