diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b8f2b820..79b2b51de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.9) # set the project name and version -project(CXXGraph VERSION 0.0.8) +project(CXXGraph VERSION 0.0.9) configure_file(CXXGraphConfig.h.in ${PROJECT_SOURCE_DIR}/include/CXXGraphConfig.h) diff --git a/docs/Doxyfile b/docs/Doxyfile index a8c84978d..cb77d9cd7 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "CXXGraph" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.0.6 +PROJECT_NUMBER = 0.0.9 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a @@ -58,7 +58,7 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = +OUTPUT_DIRECTORY = # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and diff --git a/include/Graph.hpp b/include/Graph.hpp index 915942f18..c08bcc940 100644 --- a/include/Graph.hpp +++ b/include/Graph.hpp @@ -466,15 +466,16 @@ namespace CXXGRAPH private: std::set *> edgeSet; void addElementToAdjMatrix(AdjacencyMatrix &adjMatrix, const Node *nodeFrom, const Node *nodeTo, const Edge *edge) const; - int writeToStandardFile(std::string OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const; + int writeToStandardFile_csv(const std::string &workingDir, const std::string &OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const; public: - typedef enum E_OutputFormat + /// Specify the Input/Output format of the Graph for Import/Export functions + typedef enum E_InputOutputFormat { - STANDARD, + STANDARD_CSV, ///< A standard csv format OUT_1, OUT_2 - } OutputFormat; + } InputOutputFormat; Graph() = default; Graph(const std::set *> &edgeSet); @@ -553,13 +554,14 @@ namespace CXXGRAPH * This function write the graph in an output file * * @param format The Output format of the file + * @param workingDir The path to the directory in which will be placed the output file * @param OFileName The Output File Name ( ) * @param compress Indicates if the output will be compressed * @param writeNodeFeat Indicates if export also Node Features * @param writeEdgeWeight Indicates if export also Edge Weights * @return 0 if all OK, else return a negative value */ - int writeToFile(OutputFormat format = OutputFormat::STANDARD, std::string OFileName = "graph.csv", bool compress = false, bool writeNodeFeat = false, bool writeEdgeWeight = false) const; + int writeToFile(InputOutputFormat format = InputOutputFormat::STANDARD_CSV, const std::string &workingDir = ".", const std::string &OFileName = "graph", bool compress = false, bool writeNodeFeat = false, bool writeEdgeWeight = false) const; friend std::ostream &operator<<<>(std::ostream &os, const Graph &graph); friend std::ostream &operator<<<>(std::ostream &os, const AdjacencyMatrix &adj); @@ -637,10 +639,11 @@ namespace CXXGRAPH } template - int Graph::writeToStandardFile(std::string OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const + int Graph::writeToStandardFile_csv(const std::string &workingDir, const std::string &OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const { std::ofstream ofileGraph; - ofileGraph.open(OFileName); + std::string completePathToFileGraph = workingDir + "/" + OFileName + ".csv"; + ofileGraph.open(completePathToFileGraph); auto printOutGraph = [&ofileGraph](const Edge *e) { ofileGraph << e->getId() << "," << e->getNodePair().first->getId() << "," << e->getNodePair().second->getId() << std::endl; }; std::for_each(edgeSet.cbegin(), edgeSet.cend(), printOutGraph); @@ -649,7 +652,9 @@ namespace CXXGRAPH if (writeNodeFeat) { std::ofstream ofileNodeFeat; - ofileNodeFeat.open("NodeFeat_" + OFileName); + std::string completePathToFileNodeFeat = workingDir + "/" + OFileName + "_NodeFeat" + ".csv"; + ofileNodeFeat.open(completePathToFileNodeFeat); auto printOutNodeFeat = [&ofileNodeFeat](const Node *node) { ofileNodeFeat << node->getId() << "," << node->getData() << std::endl; }; auto nodeSet = getNodeSet(); @@ -660,7 +665,9 @@ namespace CXXGRAPH if (writeEdgeWeight) { std::ofstream ofileEdgeWeight; - ofileEdgeWeight.open("EdgeWeight_" + OFileName); + std::string completePathToFileEdgeWeight = workingDir + "/" + OFileName + "_EdgeWeight" + ".csv"; + ofileEdgeWeight.open(completePathToFileEdgeWeight); auto printOutEdgeWeight = [&ofileEdgeWeight](const Edge *e) { ofileEdgeWeight << e->getId() << "," << (e->isWeighted().has_value() && e->isWeighted().value() ? (dynamic_cast(e))->getWeight() : 0.0) << std::endl; }; @@ -1055,11 +1062,11 @@ namespace CXXGRAPH } template - int Graph::writeToFile(OutputFormat format, std::string OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const + int Graph::writeToFile(InputOutputFormat format, const std::string &workingDir, const std::string &OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const { - if (format == OutputFormat::STANDARD) + if (format == InputOutputFormat::STANDARD_CSV) { - return writeToStandardFile(OFileName, compress, writeNodeFeat, writeEdgeWeight); + return writeToStandardFile_csv(workingDir, OFileName, compress, writeNodeFeat, writeEdgeWeight); } else { diff --git a/test/RWOutputTest.cpp b/test/RWOutputTest.cpp index 90f93244e..0714d5fde 100644 --- a/test/RWOutputTest.cpp +++ b/test/RWOutputTest.cpp @@ -42,7 +42,7 @@ TEST(RWOutputTest, test_2) edgeSet.insert(&edge2); edgeSet.insert(&edge3); CXXGRAPH::Graph graph(edgeSet); - int res = graph.writeToFile(CXXGRAPH::Graph::OutputFormat::STANDARD); + int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV); ASSERT_EQ(res, 0); ASSERT_TRUE(exists_test("graph.csv")); ASSERT_FALSE(exists_test("NodeFeat_graph.csv")); @@ -63,7 +63,7 @@ TEST(RWOutputTest, test_3) edgeSet.insert(&edge2); edgeSet.insert(&edge3); CXXGRAPH::Graph graph(edgeSet); - int res = graph.writeToFile(CXXGRAPH::Graph::OutputFormat::STANDARD, "test_3.csv"); + int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_3"); ASSERT_EQ(res, 0); ASSERT_TRUE(exists_test("test_3.csv")); ASSERT_FALSE(exists_test("NodeFeat_test_3.csv")); @@ -81,7 +81,7 @@ TEST(RWOutputTest, test_4) edgeSet.insert(&edge2); edgeSet.insert(&edge3); CXXGRAPH::Graph graph(edgeSet); - int res = graph.writeToFile(CXXGRAPH::Graph::OutputFormat::OUT_1, "test_4.csv"); + int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::OUT_1, "test_4"); ASSERT_EQ(res, -1); ASSERT_FALSE(exists_test("test_4.csv")); ASSERT_FALSE(exists_test("NodeFeat_test_4.csv")); @@ -99,7 +99,7 @@ TEST(RWOutputTest, test_5) edgeSet.insert(&edge2); edgeSet.insert(&edge3); CXXGRAPH::Graph graph(edgeSet); - int res = graph.writeToFile(CXXGRAPH::Graph::OutputFormat::STANDARD, "test_5.csv", false, true, true); + int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_5", false, true, true); ASSERT_EQ(res, 0); ASSERT_TRUE(exists_test("test_5.csv")); ASSERT_TRUE(exists_test("NodeFeat_test_5.csv")); @@ -117,7 +117,7 @@ TEST(RWOutputTest, test_6) edgeSet.insert(&edge2); edgeSet.insert(&edge3); CXXGRAPH::Graph graph(edgeSet); - int res = graph.writeToFile(CXXGRAPH::Graph::OutputFormat::STANDARD, "test_6.csv", false, false, true); + int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_6", false, false, true); ASSERT_EQ(res, 0); ASSERT_TRUE(exists_test("test_6.csv")); ASSERT_FALSE(exists_test("NodeFeat_test_6.csv")); @@ -135,7 +135,7 @@ TEST(RWOutputTest, test_7) edgeSet.insert(&edge2); edgeSet.insert(&edge3); CXXGRAPH::Graph graph(edgeSet); - int res = graph.writeToFile(CXXGRAPH::Graph::OutputFormat::STANDARD, "test_7.csv", false, true, false); + int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_7", false, true, false); ASSERT_EQ(res, 0); ASSERT_TRUE(exists_test("test_7.csv")); ASSERT_TRUE(exists_test("NodeFeat_test_7.csv"));