aboutsummaryrefslogtreecommitdiff
path: root/src/variant.h
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.h
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.h')
-rw-r--r--src/variant.h20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/variant.h b/src/variant.h
index 2b88efe..a4f09af 100644
--- a/src/variant.h
+++ b/src/variant.h
@@ -10,7 +10,6 @@
10 10
11#include <bu/string.h> 11#include <bu/string.h>
12#include <typeinfo> 12#include <typeinfo>
13#include <bu/membuf.h>
14#include <bu/formatter.h> 13#include <bu/formatter.h>
15 14
16namespace Bu 15namespace Bu
@@ -26,9 +25,9 @@ namespace Bu
26 VariantTypeRoot(); 25 VariantTypeRoot();
27 virtual ~VariantTypeRoot(); 26 virtual ~VariantTypeRoot();
28 27
29 virtual Bu::String toString() const=0;
30 virtual const std::type_info &getType() const=0; 28 virtual const std::type_info &getType() const=0;
31 virtual VariantTypeRoot *clone() const=0; 29 virtual VariantTypeRoot *clone() const=0;
30 virtual void format( Bu::Formatter &f ) const=0;
32 }; 31 };
33 32
34 template<class t> 33 template<class t>
@@ -65,12 +64,9 @@ namespace Bu
65 return data; 64 return data;
66 } 65 }
67 66
68 virtual Bu::String toString() const 67 virtual void format( Formatter &f ) const
69 { 68 {
70 MemBuf mb;
71 Formatter f( mb );
72 f << data; 69 f << data;
73 return mb.getString();
74 } 70 }
75 71
76 virtual const std::type_info &getType() const 72 virtual const std::type_info &getType() const
@@ -111,6 +107,7 @@ namespace Bu
111 */ 107 */
112 class Variant 108 class Variant
113 { 109 {
110 friend Bu::Formatter &operator<<( Bu::Formatter &f, const Variant &v );
114 public: 111 public:
115 Variant(); 112 Variant();
116 Variant( const Variant &v ); 113 Variant( const Variant &v );
@@ -123,8 +120,8 @@ namespace Bu
123 } 120 }
124 virtual ~Variant(); 121 virtual ~Variant();
125 122
126 bool isSet() const;
127 Bu::String toString() const; 123 Bu::String toString() const;
124 bool isSet() const;
128 const std::type_info &getType() const; 125 const std::type_info &getType() const;
129 126
130 Variant &operator=( const Variant &rhs ); 127 Variant &operator=( const Variant &rhs );
@@ -219,17 +216,14 @@ namespace Bu
219 private: 216 private:
220 VariantTypeRoot *pCore; 217 VariantTypeRoot *pCore;
221 }; 218 };
222 219/*
223 template<class t> 220 template<class t>
224 Bu::Formatter &operator<<( Bu::Formatter &f, const VariantType<t> &vt ) 221 Bu::Formatter &operator<<( Bu::Formatter &f, const VariantType<t> &vt )
225 { 222 {
226 return f << vt.toString(); 223 return f << vt.getData;
227 } 224 }*/
228 225
229 Bu::Formatter &operator<<( Bu::Formatter &f, const Variant &v ); 226 Bu::Formatter &operator<<( Bu::Formatter &f, const Variant &v );
230
231 template<> Bu::String VariantType<int>::toString() const;
232 template<> Bu::String VariantType<bool>::toString() const;
233}; 227};
234 228
235#endif 229#endif