From 89fabafa15b1fac3f8a5cdd553955e6e015ef4e5 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Fri, 11 Dec 2020 23:44:44 +0000 Subject: [PATCH] simgear/props/props_io.*: added class for inline calling of writeProperties(). E.g. allows: SG_LOG(SG_VIEW, SG_ALERT, "returning:\n" << writePropertiesInline(config, true /*write_all*/)); --- simgear/props/props_io.cxx | 18 ++++++++++++++++++ simgear/props/props_io.hxx | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/simgear/props/props_io.cxx b/simgear/props/props_io.cxx index 69500977..71e389f8 100644 --- a/simgear/props/props_io.cxx +++ b/simgear/props/props_io.cxx @@ -689,6 +689,24 @@ writeProperties (ostream &output, const SGPropertyNode * start_node, output << "" << endl; } +writePropertiesInline::writePropertiesInline( + const SGPropertyNode * start_node, + bool write_all, + SGPropertyNode::Attribute archive_flag + ) +: +m_start_node(start_node), +m_write_all(write_all), +m_archive_flag(archive_flag) +{ +} + +std::ostream& operator<< (std::ostream& out, const writePropertiesInline& wpm) +{ + writeProperties(out, wpm.m_start_node, wpm.m_write_all, wpm.m_archive_flag); + return out; +} + void writeProperties (const SGPath &path, const SGPropertyNode * start_node, diff --git a/simgear/props/props_io.hxx b/simgear/props/props_io.hxx index 17c28df3..79c23534 100644 --- a/simgear/props/props_io.hxx +++ b/simgear/props/props_io.hxx @@ -49,6 +49,23 @@ void writeProperties (std::ostream &output, const SGPropertyNode * start_node, bool write_all = false, SGPropertyNode::Attribute archive_flag = SGPropertyNode::ARCHIVE); +/** + * Convenience manipulator for calling writeProperties(), e.g.: + * std::cerr << "node is:\n" << writePropertiesStream(node, true) << "\n"; + */ +struct writePropertiesInline +{ + writePropertiesInline( + const SGPropertyNode * start_node, + bool write_all = false, + SGPropertyNode::Attribute archive_flag = SGPropertyNode::ARCHIVE + ); + const SGPropertyNode * m_start_node; + bool m_write_all; + SGPropertyNode::Attribute m_archive_flag; +}; + +std::ostream& operator<< (std::ostream& out, const writePropertiesInline& wpm); /** * Write properties to an XML file.