Commit b5ebb96d authored by Jonas Seidel's avatar Jonas Seidel

more verbose print output stream functions (".dump") for Graphtheory obj

parent bfd6600e
......@@ -115,3 +115,7 @@ std::ostream& operator<<(std::ostream& os, const Attribute& attr){
}
std::istream& operator>>(std::istream& is, Attribute& attr){ attr = Attribute(is); return is;}
void Attribute::dump(){
std::cout << *this;
}
......@@ -35,6 +35,9 @@ public:
friend std::ostream& operator<<(std::ostream& os, const Attribute& attr);
friend std::istream& operator>>(std::istream& os, Attribute& attr);
// _debug_helpers
void dump();
};
std::ostream& operator<<(std::ostream& os, const Attribute& attr);
......
......@@ -70,3 +70,15 @@ std::ostream& operator<<(std::ostream& os, Edge& e){
return os;
}
void Edge::dump(){
std::cout << "\033[0;32m";
std::cout << "Edge " << this->description() << "; " << this << " ( ";
for(std::pair<std::string, Attribute> pair : this->attributes()){
std::cout << pair.first << " = ";
pair.second.dump();
std::cout << ", ";
}
std::cout << ") {" << this->from()->description() << ", " << this->to()->description() << "}";
std::cout << "\033[0m";
}
......@@ -104,6 +104,9 @@ public:
~Edge(){
this->disconnect();
}
// _debug_helpers
void dump();
};
std::ostream& operator<<(std::ostream& os, Edge& e);
......
......@@ -31,6 +31,7 @@ class Graph{
std::set<Node*> _nodes;
std::map<std::string, Attribute> _template_node_attributes;
std::map<std::string, Attribute> _template_edge_attributes;
public:
Graph(std::map<std::string, Attribute> default_values_edge_attributes = {}, std::map<std::string, Attribute> default_values_node_attributes = {});
Graph(Graph& graph);
......@@ -142,6 +143,9 @@ public:
// _special_members_and_operators:
void operator=(const Graph& graph);
void operator=(Graph&& graph);
// _debug_helpers (Graph.ipp)
void dump();
};
std::ostream& operator<<(std::ostream& os, Graph& g);
......
......@@ -94,6 +94,27 @@ std::ostream& operator<<(std::ostream& os, Graph& g){
os << "} }";
}
return os;
// TODO implement defaults output
}
std::istream& operator>>(std::istream& is, Graph& g){g = Graph(is); return is;}
void Graph::dump(){
std::cout << "\033[0;31m";
std::cout << "Graph " << this << " { Nodes { \n";
for(Node* n : this->nodes()){
n->dump();
std::cout << "\n";
}
std::cout << "\033[0;31m";
std::cout << "} Edges {" << "\n";
for(Edge* e : this->edges()){
e->dump();
std::cout << "\n";
}
std::cout << "\033[0;31m";
std::cout << "} }";
std::cout << "\033[0m";
}
......@@ -71,7 +71,7 @@ std::ostream& operator<<(std::ostream& os, Node& n){
for(std::pair<std::string, Attribute> pair : n.attributes()){
os << pair.first << " = " << pair.second << " ";
}
os << ") {\n \tEdges {\n";
for(Edge* e : n.incident()){
os << *e << "\n";
......@@ -82,3 +82,21 @@ std::ostream& operator<<(std::ostream& os, Node& n){
}
std::istream& operator>>(std::istream& is, Node& n) { n = Node(is); return is;}
void Node::dump(){
std::cout << "\033[0;36m";
std::cout << "Node " << this->description() << "; " << this << " ( ";
for(std::pair<std::string, Attribute> pair : this->attributes()){
std::cout << pair.first << " = ";
pair.second.dump();
std::cout << ", ";
}
std::cout << ") {\n \tEdges {\n";
for(Edge* e : this->incident()){
e->dump();
std::cout << "\n";
}
std::cout << "\033[0;36m";
std::cout << "} }";
std::cout << "\033[0m";
}
......@@ -90,6 +90,9 @@ public:
bool is_source() const;
~Node();
// _debug_helpers
void dump();
};
std::ostream& operator<<(std::ostream& os, Node& n);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment