From 30e841d5b6f082bce1f98c6df198aeea28a2d95b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 17 Mar 2011 23:14:52 +0000 Subject: Tweaks to the variant class make it much cooler, and there's a test/tool called format, it's a proof of concept of a text formatter. I think it's gonna' rock. --- src/variant.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/variant.cpp') diff --git a/src/variant.cpp b/src/variant.cpp index fd0511f..f7c87ad 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -7,6 +7,8 @@ #include "bu/variant.h" +#include "bu/membuf.h" + namespace Bu { Formatter &operator<<( Formatter &f, const String &s ); @@ -49,16 +51,17 @@ Bu::Variant::~Variant() } } -bool Bu::Variant::isSet() const +Bu::String Bu::Variant::toString() const { - return pCore != NULL; + Bu::MemBuf mb; + Bu::Formatter f( mb ); + f << *this; + return mb.getString(); } -Bu::String Bu::Variant::toString() const +bool Bu::Variant::isSet() const { - if( !pCore ) - return "***NO DATA***"; - return pCore->toString(); + return pCore != NULL; } const std::type_info &Bu::Variant::getType() const @@ -87,18 +90,10 @@ Bu::Variant &Bu::Variant::operator=( const Bu::Variant &rhs ) Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v ) { - return f << v.toString(); -} - -template<> Bu::String Bu::VariantType::toString() const -{ - Bu::String s; - s.format("%d", data ); - return s; -} + if( !v.pCore ) + return f << "(null)"; -template<> Bu::String Bu::VariantType::toString() const -{ - return data?"true":"false"; + v.pCore->format( f ); + return f; } -- cgit v1.2.3