From b560f5a474f7df669fa72529aa878660bfdb1ee8 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 4 Nov 2013 00:00:22 -0800 Subject: [PATCH] Add ostream support for PropertyStream items --- beast/utility/PropertyStream.h | 18 +++++++++++++++++- beast/utility/impl/PropertyStream.cpp | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/beast/utility/PropertyStream.h b/beast/utility/PropertyStream.h index 2871499718..8fc938f98d 100644 --- a/beast/utility/PropertyStream.h +++ b/beast/utility/PropertyStream.h @@ -90,6 +90,7 @@ private: // // Item // +//------------------------------------------------------------------------------ class PropertyStream::Item : public List ::Node { @@ -106,24 +107,37 @@ private: // // Proxy // +//------------------------------------------------------------------------------ class PropertyStream::Proxy { private: - Map const* m_map; + Map const* m_map; std::string m_key; + std::ostringstream mutable m_ostream; public: Proxy (Map const& map, std::string const& key); + Proxy (Proxy const& other); + ~Proxy (); template Proxy& operator= (Value value); + + std::ostream& operator<< (std::ostream& manip (std::ostream&)) const; + + template + std::ostream& operator<< (T const& t) const + { + return m_ostream << t; + } }; //------------------------------------------------------------------------------ // // Map // +//------------------------------------------------------------------------------ class PropertyStream::Map : public Uncopyable { @@ -181,6 +195,7 @@ PropertyStream::Proxy& PropertyStream::Proxy::operator= (Value value) // // Set // +//------------------------------------------------------------------------------ class PropertyStream::Set : public Uncopyable { @@ -205,6 +220,7 @@ public: // // Source // +//------------------------------------------------------------------------------ /** Subclasses can be called to write to a stream and have children. */ class PropertyStream::Source : public Uncopyable diff --git a/beast/utility/impl/PropertyStream.cpp b/beast/utility/impl/PropertyStream.cpp index 17282c7939..24491ae981 100644 --- a/beast/utility/impl/PropertyStream.cpp +++ b/beast/utility/impl/PropertyStream.cpp @@ -62,6 +62,25 @@ PropertyStream::Proxy::Proxy ( { } +PropertyStream::Proxy::Proxy (Proxy const& other) + : m_map (other.m_map) + , m_key (other.m_key) +{ +} + +PropertyStream::Proxy::~Proxy () +{ + std::string const s (m_ostream.str()); + if (! s.empty()) + m_map->add (m_key, s); +} + +std::ostream& PropertyStream::Proxy::operator<< ( + std::ostream& manip (std::ostream&)) const +{ + return m_ostream << manip; +} + //------------------------------------------------------------------------------ // // Map