aboutsummaryrefslogtreecommitdiff
path: root/src/variant.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/variant.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/variant.cpp b/src/variant.cpp
new file mode 100644
index 0000000..95eea88
--- /dev/null
+++ b/src/variant.cpp
@@ -0,0 +1,77 @@
1#include "bu/variant.h"
2
3namespace Bu
4{
5 Formatter &operator<<( Formatter &f, const FString &s );
6};
7
8Bu::VariantTypeRoot::VariantTypeRoot()
9{
10}
11
12Bu::VariantTypeRoot::~VariantTypeRoot()
13{
14}
15
16Bu::Variant::Variant() :
17 pCore( NULL )
18{
19}
20
21Bu::Variant::~Variant()
22{
23}
24
25bool Bu::Variant::isSet()
26{
27 return pCore != NULL;
28}
29
30Bu::FString Bu::Variant::toString() const
31{
32 if( !pCore )
33 return "***NO DATA***";
34 return pCore->toString();
35}
36
37const std::type_info &Bu::Variant::getType() const
38{
39 if( !pCore )
40 {
41 throw Bu::ExceptionBase("No data!");
42 }
43 return pCore->getType();
44}
45
46Bu::Variant &Bu::Variant::operator=( const Bu::Variant &rhs )
47{
48 if( pCore )
49 {
50 delete pCore;
51 pCore = NULL;
52 }
53 if( rhs.pCore )
54 {
55 pCore = rhs.pCore->clone();
56 }
57
58 return *this;
59}
60
61Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v )
62{
63 return f << v.toString();
64}
65
66template<> Bu::FString Bu::VariantType<int>::toString() const
67{
68 Bu::FString s;
69 s.format("%d", data );
70 return s;
71}
72
73template<> Bu::FString Bu::VariantType<bool>::toString() const
74{
75 return data?"true":"false";
76}
77