| 1 |
/* |
| 2 |
* This file is part of the API Extractor project. |
| 3 |
* |
| 4 |
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 5 |
* |
| 6 |
* Contact: PySide team <contact@pyside.org> |
| 7 |
* |
| 8 |
* This program is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU General Public License |
| 10 |
* version 2 as published by the Free Software Foundation. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 |
* 02110-1301 USA |
| 21 |
* |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef GRAPH_H |
| 25 |
#define GRAPH_H |
| 26 |
|
| 27 |
#include <QLinkedList> |
| 28 |
#include <QHash> |
| 29 |
#include <QString> |
| 30 |
#include "apiextractormacros.h" |
| 31 |
|
| 32 |
/// A graph that can have their nodes topologically sorted. |
| 33 |
class APIEXTRACTOR_API Graph |
| 34 |
{ |
| 35 |
public: |
| 36 |
/// Create a new graph with \p numNodes nodes. |
| 37 |
Graph(int numNodes); |
| 38 |
~Graph(); |
| 39 |
|
| 40 |
/// Returns the numbed of nodes in this graph. |
| 41 |
int nodeCount() const; |
| 42 |
/// Returns true if the graph contains the edge from -> to |
| 43 |
bool containsEdge(int from, int to); |
| 44 |
/// Adds an edge to this graph. |
| 45 |
void addEdge(int from, int to); |
| 46 |
/// Removes an edge out of this graph. |
| 47 |
void removeEdge(int from, int to); |
| 48 |
/// Print this graph to stdout. |
| 49 |
void dump() const; |
| 50 |
/** |
| 51 |
* Dumps a dot graph to a file named \p filename. |
| 52 |
* \param nodeNames map used to translate node ids to human readable text. |
| 53 |
* \param fileName file name where the output should be written. |
| 54 |
*/ |
| 55 |
void dumpDot(const QHash<int, QString>& nodeNames, const QString& fileName) const; |
| 56 |
|
| 57 |
/** |
| 58 |
* Topologically sort this graph. |
| 59 |
* \return A collection with all nodes topologically sorted or an empty collection if a ciclic dependency was found. |
| 60 |
*/ |
| 61 |
QLinkedList<int> topologicalSort() const; |
| 62 |
private: |
| 63 |
|
| 64 |
struct GraphPrivate; |
| 65 |
GraphPrivate* m_d; |
| 66 |
}; |
| 67 |
|
| 68 |
#endif |