diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/Main.cpp | 25 | ||||
-rw-r--r-- | src/core/managed/Manager.cpp | 5 |
2 files changed, 26 insertions, 4 deletions
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<std::string>(&outputPath), "The output file name. Per default the input file name will be used.")( "format,F", po::value<std::string>(&format)->required(), - "The output format that shall be produced."); + "The output format that shall be produced." +#ifdef MANAGER_GRAPHVIZ_EXPORT + )( + "graphviz,G", po::value<std::string>(&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] <my input file> // 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<Node> 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 <iostream> #include <fstream> +#include <core/common/Exceptions.hpp> #include <core/common/Rtti.hpp> #include <core/common/Property.hpp> #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; |