From c195bed1499e4584336f1ab57cd0b8cc70cd6c96 Mon Sep 17 00:00:00 2001 From: Valentin Noel Date: Mon, 12 Aug 2013 18:27:26 +0200 Subject: [PATCH] add getJsonString and getXmlString to Export class issue #30 --- libraries/report/src/Export/Export.cpp | 19 +++++++++++++++++-- libraries/report/src/Export/Export.hpp | 6 ++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libraries/report/src/Export/Export.cpp b/libraries/report/src/Export/Export.cpp index c97188d..817755f 100644 --- a/libraries/report/src/Export/Export.cpp +++ b/libraries/report/src/Export/Export.cpp @@ -11,15 +11,30 @@ Export::Export( const bpt::ptree& report ) { } -void Export::writeJson( const std::string& filename ) +void Export::writeJsonFile( const std::string& filename ) { write_json( filename, _report ); } -void Export::writeXml( const std::string& filename, bool compact ) + +void Export::writeXmlFile( const std::string& filename, bool compact ) { bpt::xml_writer_settings< char > settings( '\t', compact ? 0 : 1 ); write_xml( filename, _report, std::locale(), settings ); } +std::string Export::getJsonString() // @ todo : add compacity option +{ + std::ostringstream jsonStream; + write_json( jsonStream, _report ); + return jsonStream.str(); +} + +std::string Export::getXmlString() // @ todo : add compacity option +{ + std::ostringstream xmlStream; + write_xml( xmlStream, _report ); + return xmlStream.str(); +} + } diff --git a/libraries/report/src/Export/Export.hpp b/libraries/report/src/Export/Export.hpp index 5afb0af..d2f9eb3 100644 --- a/libraries/report/src/Export/Export.hpp +++ b/libraries/report/src/Export/Export.hpp @@ -13,8 +13,10 @@ class Export public: Export( const bpt::ptree& report ); - void writeJson( const std::string& filename ); - void writeXml ( const std::string& filename, bool compact = false ); + void writeJsonFile( const std::string& filename ); + void writeXmlFile ( const std::string& filename, bool compact = false ); + std::string getJsonString(); + std::string getXmlString(); private: bpt::ptree _report;