Add ostream support for PropertyStream items

This commit is contained in:
Vinnie Falco
2013-11-04 00:00:22 -08:00
parent 206169476f
commit b560f5a474
2 changed files with 36 additions and 1 deletions

View File

@@ -90,6 +90,7 @@ private:
// //
// Item // Item
// //
//------------------------------------------------------------------------------
class PropertyStream::Item : public List <Item>::Node class PropertyStream::Item : public List <Item>::Node
{ {
@@ -106,24 +107,37 @@ private:
// //
// Proxy // Proxy
// //
//------------------------------------------------------------------------------
class PropertyStream::Proxy class PropertyStream::Proxy
{ {
private: private:
Map const* m_map; Map const* m_map;
std::string m_key; std::string m_key;
std::ostringstream mutable m_ostream;
public: public:
Proxy (Map const& map, std::string const& key); Proxy (Map const& map, std::string const& key);
Proxy (Proxy const& other);
~Proxy ();
template <typename Value> template <typename Value>
Proxy& operator= (Value value); Proxy& operator= (Value value);
std::ostream& operator<< (std::ostream& manip (std::ostream&)) const;
template <typename T>
std::ostream& operator<< (T const& t) const
{
return m_ostream << t;
}
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
// Map // Map
// //
//------------------------------------------------------------------------------
class PropertyStream::Map : public Uncopyable class PropertyStream::Map : public Uncopyable
{ {
@@ -181,6 +195,7 @@ PropertyStream::Proxy& PropertyStream::Proxy::operator= (Value value)
// //
// Set // Set
// //
//------------------------------------------------------------------------------
class PropertyStream::Set : public Uncopyable class PropertyStream::Set : public Uncopyable
{ {
@@ -205,6 +220,7 @@ public:
// //
// Source // Source
// //
//------------------------------------------------------------------------------
/** Subclasses can be called to write to a stream and have children. */ /** Subclasses can be called to write to a stream and have children. */
class PropertyStream::Source : public Uncopyable class PropertyStream::Source : public Uncopyable

View File

@@ -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 // Map