From 80e5c01f09667ebdc2ad9f950c0e83b8a0b64a41 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 17 Feb 2015 23:37:53 +0100 Subject: Implement possiblility of Graphviz export when in debug mode (for demo purposes) --- src/cli/Main.cpp | 25 +++++++++++++++++++++++-- src/core/managed/Manager.cpp | 5 +++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp index 7ec7cf9..88ec6b9 100644 --- a/src/cli/Main.cpp +++ b/src/cli/Main.cpp @@ -106,6 +106,10 @@ int main(int argc, char **argv) std::string inputPath; std::string outputPath; std::string format; +#ifdef MANAGER_GRAPHVIZ_EXPORT + std::string graphvizPath; +#endif + /* * This is a rather strange access mechanism: add_options() returns an * easy_init object that has overloaded the () operator to accept new @@ -121,7 +125,13 @@ int main(int argc, char **argv) "output,o", po::value(&outputPath), "The output file name. Per default the input file name will be used.")( "format,F", po::value(&format)->required(), - "The output format that shall be produced."); + "The output format that shall be produced." +#ifdef MANAGER_GRAPHVIZ_EXPORT + )( + "graphviz,G", po::value(&graphvizPath), + "If set, dumps the internal object graph to the given graphviz dot file" +#endif + ); // "input" should be a positional option, such that we can write: // ./ousia [some options] // without having to use -i or I @@ -240,6 +250,17 @@ int main(int argc, char **argv) // now all preparation is done and we can parse the input document. Rooted docNode = context.import(inputPath, "", "", {&RttiTypes::Document}); + +#ifdef MANAGER_GRAPHVIZ_EXPORT + if (!graphvizPath.empty()) { + try { + manager.exportGraphviz(graphvizPath.c_str()); + } catch (LoggableException ex){ + logger.log(ex); + } + } +#endif + if (logger.hasError() || docNode == nullptr) { logger.fatalError("Errors occured while parsing the document"); return ERROR_IN_DOCUMENT; @@ -254,4 +275,4 @@ int main(int argc, char **argv) } return SUCCESS; -} \ No newline at end of file +} diff --git a/src/core/managed/Manager.cpp b/src/core/managed/Manager.cpp index 694587f..238b446 100644 --- a/src/core/managed/Manager.cpp +++ b/src/core/managed/Manager.cpp @@ -25,6 +25,7 @@ defined(MANAGER_DEBUG_HIDDEN_ROOTED) #include #include +#include #include #include #endif @@ -601,9 +602,9 @@ enum class EdgeType { NORMAL, DATA, AGGREGATE }; void Manager::exportGraphviz(const char *filename) { - std::fstream fs(filename, std::ios_base::out); + std::ofstream fs(filename); if (!fs.good()) { - throw "Error while opening output file."; + throw LoggableException(std::string("Error while opening target file: ") + filename); } fs << "digraph G {" << std::endl; -- cgit v1.2.3