GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
StreamOverload.hpp
Go to the documentation of this file.
1 #ifndef GL_STREAM_OVERLOAD_HPP
2 #define GL_STREAM_OVERLOAD_HPP
3 
4 #include "../structures/Graph.hpp"
5 #include "../structures/Color.hpp"
6 
21 template <class SCALAR, class STORAGE>
22 std::ostream& operator<< (std::ostream& os, const gl::Graph<SCALAR, STORAGE, gl::Directed>& rhs) {
24  os << "----- " << rhs.getGraphLabel() << " -----" << std::endl
25  << "Total Nodes: " << rhs.numNodes() << std::endl
26  << "Total Edges: " << rhs.numEdges() << std::endl
27  << "Directed "
28  << (GL_IS_MATRIX ? "Matrix" : (GL_IS_LIST ? "List" : "Unknown storage type"))
29  << std::endl;
30  for (auto it = rhs.edge_cbegin(); it != rhs.edge_cend(); ++it) {
31  os << it->source() << "--(" << it->weight()
32  << ")->" << it->dest() << std::endl;
33  }
34  std::cout << std::endl;
35  return os;
36 }
37 
41 template <class SCALAR, class STORAGE>
42 std::ostream& operator<< (std::ostream& os, const gl::Graph<SCALAR, STORAGE, gl::Undirected>& rhs) {
44  os << "----- " << rhs.getGraphLabel() << " -----" << std::endl
45  << "Total Nodes: " << rhs.numNodes() << std::endl
46  << "Total Edges: " << rhs.numEdges() << std::endl
47  << "Undirected "
48  << (GL_IS_MATRIX ? "Matrix" : (GL_IS_LIST ? "List" : "Unknown storage type"))
49  << std::endl;
50  for (auto it = rhs.edge_cbegin(); it != rhs.edge_cend(); ++it) {
51  if (it->source() <= it->dest()) {
52  os << it->source() << "<-(" << it->weight()
53  << ")->" << it->dest() << std::endl;
54  }
55  }
56  std::cout << std::endl;
57  return os;
58 }
60 
71 template <class val_t>
72 std::ostream& operator<< (std::ostream& os, const gl::Distance<val_t>& dist)
73 {
74  os << dist.getDistance();
75  return os;
76 }
77 
78 
82 template <class idx_t>
83 std::ostream& operator<< (std::ostream & os, const std::list<idx_t>& rhs)
84 {
85  os << "[ ";
86  for (const auto& it : rhs) {
87  os << it << " ";
88  }
89  os << "]\n";
90  return os;
91 }
92 
96 template <class idx_t>
97 std::ostream& operator<< (std::ostream& os, const std::vector<idx_t>& rhs) {
98  os << "[ ";
99  for (const auto& it : rhs) {
100  os << it << " ";
101  }
102  os << "]\n";
103  return os;
104 }
105 
109 template <class idx_t>
110 std::ostream& operator<< (std::ostream& os, const std::deque<idx_t>& rhs)
111 {
112  os << "[ ";
113  for (const auto& it : rhs) {
114  os << it << " ";
115  }
116  os << "]\n";
117  return os;
118 }
119 
124 template <class idx_t>
125 std::ostream& operator<< (std::ostream& os, std::stack<idx_t> rhs)
126 {
127  os << "[ ";
128  while (!rhs.empty()) {
129  os << rhs.top() << " ";
130  rhs.pop();
131  }
132 
133  os << "]\n";
134  return os;
135 }
137 
143 std::ostream& operator<< (std::ostream& os, const gl::Color& rhs)
144 {
145  os << "[Hex: #" << std::setw(8) << std::right
146  << std::hex << +rhs.hex() << std::setfill('0');
147  os << ";(RGB: " << std::dec
148  << +rhs.r() << ","
149  << +rhs.g() << ","
150  << +rhs.b() << "), Opacity: "
151  << +rhs.a() << "%]";
152  return os;
153 }
159 template<class SCALAR>
160 std::ostream& operator<< (std::ostream& os, const gl::Edge<SCALAR>& rhs)
161 {
162  os << "[" <<rhs.source()
163  << "--(" << rhs.weight()
164  << ")->" << rhs.dest()
165  << "; #" << rhs.color().RGBA()
166  << "]";
167  return os;
168 }
169 
170 #endif // GL_STREAM_OVERLOAD_HPP
Stores an RGBA Color.
Definition: Color.hpp:21
gl::index_type idx_t
Index type.
Definition: Graph.hpp:44
std::ostream & operator<<(std::ostream &os, const gl::Graph< SCALAR, STORAGE, gl::Directed > &rhs)
Prints all info of a directed graph.
Definition: StreamOverload.hpp:22
int hex() const
Gets the hexadecimal value of the RGBA color.
Definition: Color.hpp:160
color_val_t b() const
Gets the blue value of the RGBA color.
Definition: Color.hpp:175
color_val_t g() const
Gets the green value of the RGBA color.
Definition: Color.hpp:171
color_val_t a() const
Gets the alpha/opacity value of the RGBA color.
Definition: Color.hpp:179
color_val_t r() const
Gets the red value of the RGBA color.
Definition: Color.hpp:167