diff options
Diffstat (limited to '')
-rw-r--r-- | src/variant.cpp | 77 |
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 | |||
3 | namespace Bu | ||
4 | { | ||
5 | Formatter &operator<<( Formatter &f, const FString &s ); | ||
6 | }; | ||
7 | |||
8 | Bu::VariantTypeRoot::VariantTypeRoot() | ||
9 | { | ||
10 | } | ||
11 | |||
12 | Bu::VariantTypeRoot::~VariantTypeRoot() | ||
13 | { | ||
14 | } | ||
15 | |||
16 | Bu::Variant::Variant() : | ||
17 | pCore( NULL ) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | Bu::Variant::~Variant() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | bool Bu::Variant::isSet() | ||
26 | { | ||
27 | return pCore != NULL; | ||
28 | } | ||
29 | |||
30 | Bu::FString Bu::Variant::toString() const | ||
31 | { | ||
32 | if( !pCore ) | ||
33 | return "***NO DATA***"; | ||
34 | return pCore->toString(); | ||
35 | } | ||
36 | |||
37 | const 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 | |||
46 | Bu::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 | |||
61 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v ) | ||
62 | { | ||
63 | return f << v.toString(); | ||
64 | } | ||
65 | |||
66 | template<> Bu::FString Bu::VariantType<int>::toString() const | ||
67 | { | ||
68 | Bu::FString s; | ||
69 | s.format("%d", data ); | ||
70 | return s; | ||
71 | } | ||
72 | |||
73 | template<> Bu::FString Bu::VariantType<bool>::toString() const | ||
74 | { | ||
75 | return data?"true":"false"; | ||
76 | } | ||
77 | |||