From 48efde755bb96ca339dd0dcc654df04434b32b81 Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Wed, 8 Aug 2018 13:22:54 +0200 Subject: [PATCH] DFT: export to JSON as string --- src/storm-dft-cli/storm-dft.cpp | 2 +- src/storm-dft/api/storm-dft.cpp | 16 ++++++++++++++-- src/storm-dft/api/storm-dft.h | 10 +++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/storm-dft-cli/storm-dft.cpp b/src/storm-dft-cli/storm-dft.cpp index 261193ff3..0e38d7757 100644 --- a/src/storm-dft-cli/storm-dft.cpp +++ b/src/storm-dft-cli/storm-dft.cpp @@ -46,7 +46,7 @@ void processOptions() { if (dftIOSettings.isExportToJson()) { // Export to json - storm::api::exportDFTToJson(*dft, dftIOSettings.getExportJsonFilename()); + storm::api::exportDFTToJsonFile(*dft, dftIOSettings.getExportJsonFilename()); return; } diff --git a/src/storm-dft/api/storm-dft.cpp b/src/storm-dft/api/storm-dft.cpp index 72105a763..c2431d8e9 100644 --- a/src/storm-dft/api/storm-dft.cpp +++ b/src/storm-dft/api/storm-dft.cpp @@ -4,12 +4,24 @@ namespace storm { namespace api { template<> - void exportDFTToJson(storm::storage::DFT const& dft, std::string const& file) { + void exportDFTToJsonFile(storm::storage::DFT const& dft, std::string const& file) { storm::storage::DftJsonExporter::toFile(dft, file); } template<> - void exportDFTToJson(storm::storage::DFT const& dft, std::string const& file) { + void exportDFTToJsonFile(storm::storage::DFT const& dft, std::string const& file) { + STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Export to JSON not supported for this data type."); + } + + template<> + std::string exportDFTToJsonString(storm::storage::DFT const& dft) { + std::stringstream stream; + storm::storage::DftJsonExporter::toStream(dft, stream); + return stream.str(); + } + + template<> + std::string exportDFTToJsonString(storm::storage::DFT const& dft) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Export to JSON not supported for this data type."); } diff --git a/src/storm-dft/api/storm-dft.h b/src/storm-dft/api/storm-dft.h index 79831edbc..ec4e7166a 100644 --- a/src/storm-dft/api/storm-dft.h +++ b/src/storm-dft/api/storm-dft.h @@ -107,7 +107,15 @@ namespace storm { * @param file File. */ template - void exportDFTToJson(storm::storage::DFT const& dft, std::string const& file); + void exportDFTToJsonFile(storm::storage::DFT const& dft, std::string const& file); + + /*! + * Export DFT to JSON string. + * + * @param dft DFT. + */ + template + std::string exportDFTToJsonString(storm::storage::DFT const& dft); /*! * Export DFT to SMT encoding.