diff options
Diffstat (limited to 'src/variant.cpp')
-rw-r--r-- | src/variant.cpp | 31 |
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 | |||
10 | namespace Bu | 12 | namespace 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 | ||
52 | bool Bu::Variant::isSet() const | 54 | Bu::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 | ||
57 | Bu::String Bu::Variant::toString() const | 62 | bool 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 | ||
64 | const std::type_info &Bu::Variant::getType() const | 67 | const std::type_info &Bu::Variant::getType() const |
@@ -87,18 +90,10 @@ Bu::Variant &Bu::Variant::operator=( const Bu::Variant &rhs ) | |||
87 | 90 | ||
88 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v ) | 91 | Bu::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 | |||
93 | template<> Bu::String Bu::VariantType<int>::toString() const | ||
94 | { | ||
95 | Bu::String s; | ||
96 | s.format("%d", data ); | ||
97 | return s; | ||
98 | } | ||
99 | 95 | ||
100 | template<> 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 | ||