Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Logging.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #include <ogdf/basic/Graph.h>
35 
36 #include <functional>
37 #include <iterator>
38 #include <ostream>
39 #include <string>
40 #include <utility>
41 
42 namespace ogdf {
43 class ClusterGraph;
44 } // namespace ogdf
45 
46 #define OGDF_CONTAINER_PRINTER(NAME) \
47  template<typename Container> \
48  struct NAME { \
49  const Container& container; \
50  explicit NAME(const Container& _container) : container(_container) { } \
51  template<typename ContainerT> \
52  friend std::ostream& operator<<(std::ostream& os, const NAME<ContainerT>& inst); \
53  }
54 
56 namespace ogdf::sync_plan::internal {
57 OGDF_EXPORT std::string to_string(const std::function<std::ostream&(std::ostream&)>& func);
58 
59 OGDF_EXPORT std::ostream& operator<<(std::ostream& os,
60  const std::function<std::ostream&(std::ostream&)>& func);
61 
62 template<typename T1, typename T2>
63 std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& pair) {
64  return os << "(" << pair.first << ", " << pair.second << ")";
65 }
66 
67 OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const ogdf::Graph& G);
68 
69 OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const ogdf::ClusterGraph& CG);
70 
71 OGDF_CONTAINER_PRINTER(printContainer);
72 
73 OGDF_CONTAINER_PRINTER(printIncidentEdges);
74 
75 OGDF_CONTAINER_PRINTER(printEdges);
76 
77 OGDF_CONTAINER_PRINTER(printBijection);
78 
79 OGDF_CONTAINER_PRINTER(printFrozenBijection);
80 
81 template<typename Container>
82 std::ostream& operator<<(std::ostream& os, const printContainer<Container>& inst) {
83  bool first = true;
84  for (const auto& entry : inst.container) {
85  os << (first ? "" : ", ") << entry;
86  first = false;
87  }
88  return os;
89 }
90 
91 template<typename Container>
92 std::ostream& operator<<(std::ostream& os, const printIncidentEdges<Container>& inst) {
93  for (ogdf::adjEntry adj : inst.container) {
94  os << "e" << adj->theEdge()->index() << " (" << (adj->isSource() ? ">" : "<") << "n"
95  << adj->twinNode()->index() << "), ";
96  }
97  return os;
98 }
99 
100 template<>
101 std::ostream& operator<<(std::ostream& os, const printIncidentEdges<PipeBij>& inst);
102 
103 template<typename Container>
104 std::ostream& operator<<(std::ostream& os, const printEdges<Container>& inst) {
105  for (ogdf::adjEntry adj : inst.container) {
106  os << "e" << adj->theEdge()->index() << " (n" << adj->theNode()->index()
107  << (adj->isSource() ? "->" : "<-") << "n" << adj->twinNode()->index() << "), ";
108  }
109  return os;
110 }
111 
112 template<>
113 std::ostream& operator<<(std::ostream& os, const printEdges<PipeBij>& inst);
114 
115 template<typename Container>
116 std::ostream& operator<<(std::ostream& os, const printBijection<Container>& inst) {
117  bool first = true;
118  for (const std::pair<ogdf::adjEntry, ogdf::adjEntry>& pair : inst.container) {
119  if (first) {
120  first = false;
121  } else {
122  os << " ";
123  }
124  os << "(";
125  if (pair.first == nullptr) {
126  os << "NULL";
127  } else {
128  os << "n" << pair.first->twinNode()->index() << (pair.first->isSource() ? "<" : ">")
129  << " e" << pair.first->theEdge()->index();
130  }
131  os << " = ";
132  if (pair.second == nullptr) {
133  os << "NULL";
134  } else {
135  os << "e" << pair.second->theEdge()->index() << " "
136  << (pair.second->isSource() ? ">" : "<") << "n" << pair.second->twinNode()->index();
137  }
138  os << ")";
139  }
140  return os;
141 }
142 
143 template<typename Container>
144 std::ostream& operator<<(std::ostream& os, const printFrozenBijection<Container>& inst) {
145  bool first = true;
146  for (const auto& pair : inst.container) {
147  os << (first ? "" : " ") << "(e" << pair.first << " = e" << pair.second << ")";
148  first = false;
149  }
150  return os;
151 }
152 
153 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
Graph.h
Includes declaration of graph class.
ogdf::sync_plan::internal::OGDF_CONTAINER_PRINTER
OGDF_CONTAINER_PRINTER(printContainer)
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:159
ogdf::NodeElement::index
int index() const
Returns the (unique) node index.
Definition: Graph_d.h:267
Bijection.h
Utilities for working with the bijections between the edges incident to the two endpoints of a Pipe.
ogdf::EdgeElement::index
int index() const
Returns the index of the edge.
Definition: Graph_d.h:388
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::AdjElement::isSource
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Definition: Graph_d.h:472
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:153
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::AdjElement::twinNode
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:168
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:339
ogdf::sync_plan::internal::to_string
std::string to_string(const std::function< std::ostream &(std::ostream &)> &func)
ogdf::sync_plan::internal::operator<<
std::ostream & operator<<(std::ostream &os, const std::function< std::ostream &(std::ostream &)> &func)
ogdf::sync_plan::internal
all operators will only be found when using sync_plan::internal, so no namespace pollution
Definition: SyncPlan.h:81