1//===- Digraph.h ----------------------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#ifndef MCLD_ADT_GRAPHLITE_DIGRAPH_H
10#define MCLD_ADT_GRAPHLITE_DIGRAPH_H
11#include <mcld/ADT/Uncopyable.h>
12#include <mcld/ADT/GraphLite/GraphBasicTypes.h>
13#include <stdint.h>
14
15namespace mcld {
16namespace graph {
17
18/** \class Digraph
19 *  \brief Digraph provides the common interface of all directed graphs.
20 */
21class Digraph : private Uncopyable
22{
23public:
24  typedef DirectedTag direction_tag;
25
26  class Node
27  {
28    friend class Digraph;
29  public:
30    Node() {}
31
32    bool operator==(const Node& pOther) const { return m_ID == pOther.m_ID; }
33    bool operator!=(const Node& pOther) const { return m_ID != pOther.m_ID; }
34
35  protected:
36    intptr_t m_ID;
37  };
38
39  class Arc
40  {
41    friend class Digraph;
42  public:
43    Arc();
44
45    bool operator==(const Node& pOther) const;
46    bool operator!=(const Node& pOther) const;
47
48    Node source() const;
49    Node target() const;
50
51  protected:
52    Arc(Digraph& pParent);
53
54  protected:
55    intptr_t m_ID;
56    Digraph* m_Parent;
57  };
58
59public:
60  Digraph();
61
62  Node addNode();
63
64  Arc addArc(const Node& pSource, const Node& pTarget);
65
66  void erase(const Node& pNode);
67
68  void erase(const Arc& pArc);
69
70  void clear();
71
72  unsigned int numOfNodes() const;
73
74  unsigned int numOfArcs() const;
75
76};
77
78} // namespace of graph
79} // namespace of mcld
80
81#endif
82
83