summaryrefslogtreecommitdiff
path: root/src/variant.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-17 23:14:52 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-17 23:14:52 +0000
commit30e841d5b6f082bce1f98c6df198aeea28a2d95b (patch)
tree68727dcfae385733e4acebcb52bdde6486ebee88 /src/variant.cpp
parent4f96052772c46ceba8ca074e4206646661462533 (diff)
downloadlibbu++-30e841d5b6f082bce1f98c6df198aeea28a2d95b.tar.gz
libbu++-30e841d5b6f082bce1f98c6df198aeea28a2d95b.tar.bz2
libbu++-30e841d5b6f082bce1f98c6df198aeea28a2d95b.tar.xz
libbu++-30e841d5b6f082bce1f98c6df198aeea28a2d95b.zip
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.
Diffstat (limited to 'src/variant.cpp')
-rw-r--r--src/variant.cpp31
1 files changed, 13 insertions, 18 deletions
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 @@
7 7
8#include "bu/variant.h" 8#include "bu/variant.h"
9 9
10#include "bu/membuf.h"
11
10namespace Bu 12namespace Bu
11{ 13{
12 Formatter &operator<<( Formatter &f, const String &s ); 14 Formatter &operator<<( Formatter &f, const String &s );
@@ -49,16 +51,17 @@ Bu::Variant::~Variant()
49 } 51 }
50} 52}
51 53
52bool Bu::Variant::isSet() const 54Bu::String Bu::Variant::toString() const
53{ 55{
54 return pCore != NULL; 56 Bu::MemBuf mb;
57 Bu::Formatter f( mb );
58 f << *this;
59 return mb.getString();
55} 60}
56 61
57Bu::String Bu::Variant::toString() const 62bool Bu::Variant::isSet() const
58{ 63{
59 if( !pCore ) 64 return pCore != NULL;
60 return "***NO DATA***";
61 return pCore->toString();
62} 65}
63 66
64const std::type_info &Bu::Variant::getType() const 67const std::type_info &Bu::Variant::getType() const
@@ -87,18 +90,10 @@ Bu::Variant &Bu::Variant::operator=( const Bu::Variant &rhs )
87 90
88Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v ) 91Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v )
89{ 92{
90 return f << v.toString(); 93 if( !v.pCore )
91} 94 return f << "(null)";
92
93template<> Bu::String Bu::VariantType<int>::toString() const
94{
95 Bu::String s;
96 s.format("%d", data );
97 return s;
98}
99 95
100template<> Bu::String Bu::VariantType<bool>::toString() const 96 v.pCore->format( f );
101{ 97 return f;
102 return data?"true":"false";
103} 98}
104 99