summaryrefslogtreecommitdiff
path: root/src/variant.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-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