Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Path.h
Go to the documentation of this file.
1
31#pragma once
32
33#ifdef OGDF_INCLUDE_CGAL
34
36
37namespace ogdf {
38namespace internal {
39namespace gcm {
40namespace graph {
41
42class Path {
43private:
44 using Graph = OGDFGraphWrapper;
45 using Node = typename Graph::Node;
46 using Edge = typename Graph::Edge;
47 std::vector<Node> m_nodes;
48 std::vector<Edge> m_edges;
49
50public:
51 inline const std::vector<Node>& nodes() const { return m_nodes; }
52
53 inline const std::vector<Edge>& edges() const { return m_edges; }
54
55 inline bool is_reversed(unsigned int edge_i) const {
56 return m_edges[edge_i]->source() != m_nodes[edge_i];
57 }
58
59 void push_back(const Node& src, const Edge& e) {
60 OGDF_ASSERT(m_nodes.empty() || e->isIncident(m_nodes.back()));
61 OGDF_ASSERT(m_nodes.empty() || m_nodes.back() == src);
62 m_edges.push_back(e);
63 if (!m_nodes.empty()) {
64 m_nodes.push_back(e->opposite(m_nodes.back()));
65 } else {
66 m_nodes.push_back(src);
67 m_nodes.push_back(e->opposite(src));
68 }
69 }
70
71 void clear() {
72 m_nodes.clear();
73 m_edges.clear();
74 }
75
76 inline bool empty() const { return m_nodes.empty(); }
77
78 void reverse() {
79 std::reverse(m_nodes.begin(), m_nodes.end());
80 std::reverse(m_edges.begin(), m_edges.end());
81 }
82
83 void print() {
84 if (!empty()) {
85 for (unsigned int i = 0; i < m_edges.size(); ++i) {
86 std::cout << m_nodes[i] << ", " << m_edges[i] << "->";
87 }
88 std::cout << m_nodes.back() << std::endl;
89 } else {
90 std::cout << "path is empty" << std::endl;
91 }
92 }
93};
94
95
96}
97}
98}
99}
100
101#endif
Reverse< T > reverse(T &container)
Provides iterators for container to make it easily iterable in reverse.
Definition Reverse.h:74
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition Array.h:967