From 65e0153c2113d2a684bc7e8cea06c54d5d69aa4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bro=C5=BE?= <brozjan5@fit.cvut.cz>
Date: Sat, 21 May 2016 21:33:06 +0200
Subject: [PATCH] reprezentace grafu 2

---
 alib2data/src/graph/GraphTypes.cpp           | 62 ++++++++++++++++++++
 alib2data/src/graph/GraphTypes.h             | 33 +++++++++++
 alib2str/src/graph/GraphFromStringParser.cpp |  4 +-
 alib2str/src/graph/GraphToStringComposer.cpp |  8 +--
 4 files changed, 101 insertions(+), 6 deletions(-)
 create mode 100644 alib2data/src/graph/GraphTypes.cpp
 create mode 100644 alib2data/src/graph/GraphTypes.h

diff --git a/alib2data/src/graph/GraphTypes.cpp b/alib2data/src/graph/GraphTypes.cpp
new file mode 100644
index 0000000000..76a319f6a8
--- /dev/null
+++ b/alib2data/src/graph/GraphTypes.cpp
@@ -0,0 +1,62 @@
+/*
+ * GraphTypes.cpp
+ *
+ *  Created on: Mar 16, 2016
+ *      Author: Jan Broz
+ */
+
+#include "GraphTypes.h"
+
+namespace graph {
+
+std::string typeToString( GRAPH_TYPE t )
+{
+	switch (t) {
+	 case GRAPH_TYPE::UNDIRECTED:
+		return "Undirected";
+	 case GRAPH_TYPE::DIRECTED:
+		return "Directed";
+	 default:
+		return "Undirected";
+	}
+}
+
+GRAPH_TYPE typeFromString( const std::string & str )
+{
+	if (str == "Undirected")
+		return GRAPH_TYPE::UNDIRECTED;
+	else if (str == "Directed")
+		return GRAPH_TYPE::DIRECTED;
+	else
+		return GRAPH_TYPE::UNDIRECTED;
+}
+
+std::string representationToString( REPRESENTATION r )
+{
+	// !! add graph types/representations
+	switch (r) {
+	 case REPRESENTATION::ADJACENCY_LIST:
+		return "AdjacencyList";
+	 case REPRESENTATION::ADJACENCY_MATRIX:
+		return "AdjacencyMatrix";
+	 case REPRESENTATION::INCIDENCE_MATRIX:
+		return "IncidenceMatrix";
+	 default:
+		return "AdjacencyList";
+	}
+}
+
+REPRESENTATION representationFromString( const std::string & str )
+{
+	// !! add graph types/representations
+	if (str == "AdjacencyList")
+		return REPRESENTATION::ADJACENCY_LIST;
+	else if (str == "AdjacencyMatrix")
+		return REPRESENTATION::ADJACENCY_MATRIX;
+	else if (str == "IncidenceMatrix")
+		return REPRESENTATION::INCIDENCE_MATRIX;
+	else
+		return REPRESENTATION::ADJACENCY_LIST;
+}
+
+} // namespace graph
diff --git a/alib2data/src/graph/GraphTypes.h b/alib2data/src/graph/GraphTypes.h
new file mode 100644
index 0000000000..26729f5613
--- /dev/null
+++ b/alib2data/src/graph/GraphTypes.h
@@ -0,0 +1,33 @@
+/*
+ * GraphTypes.h
+ *
+ *  Created on: Mar 16, 2016
+ *      Author: Jan Broz
+ */
+
+#ifndef GRAPH_TYPES_H_
+#define GRAPH_TYPES_H_
+
+#include <string>
+
+namespace graph {
+
+enum class GRAPH_TYPE {
+	UNDIRECTED,
+	DIRECTED
+};
+std::string typeToString( GRAPH_TYPE t );
+GRAPH_TYPE typeFromString( const std::string & str );
+
+// !! add graph types/representations
+enum class REPRESENTATION {
+	ADJACENCY_LIST,
+	ADJACENCY_MATRIX,
+	INCIDENCE_MATRIX
+};
+std::string representationToString( REPRESENTATION r );
+REPRESENTATION representationFromString( const std::string & str );
+
+} // namespace graph
+
+#endif // GRAPH_TYPES_H_
diff --git a/alib2str/src/graph/GraphFromStringParser.cpp b/alib2str/src/graph/GraphFromStringParser.cpp
index 572c7036b8..b27259062e 100644
--- a/alib2str/src/graph/GraphFromStringParser.cpp
+++ b/alib2str/src/graph/GraphFromStringParser.cpp
@@ -33,14 +33,14 @@ Graph GraphFromStringParser::parseGraph(std::istream &input) const
 		parseDelimiter(input); // :
 		Graph graph{parseDirectedGraph<AdjacencyMatrixDirectedGraph>(input)};
 		if (lexer.next(input).type != GraphFromStringLexer::TokenType::RPAR) {
-			throw exception::AlibException("Invalid input. Expected RPAR");
+			throw exception::CommonException("Invalid input. Expected RPAR");
 		}
 		return graph;
 	} else if (str == "AdjacencyListUndirectedGraph") {
 		parseDelimiter(input); // :
 		Graph graph{parseUndirectedGraph<AdjacencyListUndirectedGraph>(input)};
 		if (lexer.next(input).type != GraphFromStringLexer::TokenType::RPAR) {
-			throw exception::AlibException("Invalid input. Expected RPAR");
+			throw exception::CommonException("Invalid input. Expected RPAR");
 		}
 		return graph;
 	} else if (str == "AdjacencyMatrixUndirectedGraph") {
diff --git a/alib2str/src/graph/GraphToStringComposer.cpp b/alib2str/src/graph/GraphToStringComposer.cpp
index 8c294a56f8..84228906b0 100644
--- a/alib2str/src/graph/GraphToStringComposer.cpp
+++ b/alib2str/src/graph/GraphToStringComposer.cpp
@@ -56,22 +56,22 @@ void GraphToStringComposer::compose(std::ostream& out, const UndirectedGraph &gr
 void composeALDG(std::ostream & out, const AdjacencyListDirectedGraph & graph) {
 	GraphToStringComposer::compose(out, graph);
 }
-GraphToStringComposer::RegistratorWrapper<void, AdjacencyListDirectedGraph> GraphToStringComposerALDG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyListDirectedGraph>(GraphToStringComposer::getInstance(), composeALDG);
+GraphToStringComposer::RegistratorWrapper<void, AdjacencyListDirectedGraph> GraphToStringComposerALDG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyListDirectedGraph>(composeALDG);
 
 void composeAMDG(std::ostream & out, const AdjacencyMatrixDirectedGraph & graph) {
 	GraphToStringComposer::compose(out, graph);
 }
-GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixDirectedGraph> GraphToStringComposerAMDG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixDirectedGraph>(GraphToStringComposer::getInstance(), composeAMDG);
+GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixDirectedGraph> GraphToStringComposerAMDG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixDirectedGraph>(composeAMDG);
 
 void composeALUG(std::ostream & out, const AdjacencyListUndirectedGraph & graph) {
 	GraphToStringComposer::compose(out, graph);
 }
-GraphToStringComposer::RegistratorWrapper<void, AdjacencyListUndirectedGraph> GraphToStringComposerALUG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyListUndirectedGraph>(GraphToStringComposer::getInstance(), composeALUG);
+GraphToStringComposer::RegistratorWrapper<void, AdjacencyListUndirectedGraph> GraphToStringComposerALUG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyListUndirectedGraph>(composeALUG);
 
 void composeAMUG(std::ostream & out, const AdjacencyMatrixUndirectedGraph & graph) {
 	GraphToStringComposer::compose(out, graph);
 }
-GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixUndirectedGraph> GraphToStringComposerAMUG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixUndirectedGraph>(GraphToStringComposer::getInstance(), composeAMUG);
+GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixUndirectedGraph> GraphToStringComposerAMUG = GraphToStringComposer::RegistratorWrapper<void, AdjacencyMatrixUndirectedGraph>(composeAMUG);
 
 
 
-- 
GitLab