diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/variant.cpp | |
parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip |
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/variant.cpp')
-rw-r--r-- | src/stable/variant.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/stable/variant.cpp b/src/stable/variant.cpp new file mode 100644 index 0000000..5cdaa5b --- /dev/null +++ b/src/stable/variant.cpp | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/variant.h" | ||
9 | #include "bu/formatter.h" | ||
10 | #include "bu/membuf.h" | ||
11 | |||
12 | namespace Bu | ||
13 | { | ||
14 | Formatter &operator<<( Formatter &f, const String &s ); | ||
15 | }; | ||
16 | |||
17 | Bu::VariantTypeRoot::VariantTypeRoot() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | Bu::VariantTypeRoot::~VariantTypeRoot() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | Bu::Variant::Variant() : | ||
26 | pCore( NULL ) | ||
27 | { | ||
28 | } | ||
29 | |||
30 | Bu::Variant::Variant( const Variant &v ) : | ||
31 | pCore( NULL ) | ||
32 | { | ||
33 | if( v.pCore ) | ||
34 | { | ||
35 | pCore = v.pCore->clone(); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | Bu::Variant::Variant( const char *t ) : | ||
40 | pCore( NULL ) | ||
41 | { | ||
42 | set( Bu::String( t ) ); | ||
43 | } | ||
44 | |||
45 | Bu::Variant::~Variant() | ||
46 | { | ||
47 | if( pCore ) | ||
48 | { | ||
49 | delete pCore; | ||
50 | pCore = NULL; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | Bu::String Bu::Variant::toString() const | ||
55 | { | ||
56 | Bu::MemBuf mb; | ||
57 | Bu::Formatter f( mb ); | ||
58 | f << *this; | ||
59 | return mb.getString(); | ||
60 | } | ||
61 | |||
62 | bool Bu::Variant::isSet() const | ||
63 | { | ||
64 | return pCore != NULL; | ||
65 | } | ||
66 | |||
67 | const std::type_info &Bu::Variant::getType() const | ||
68 | { | ||
69 | if( !pCore ) | ||
70 | { | ||
71 | throw Bu::ExceptionBase("No data!"); | ||
72 | } | ||
73 | return pCore->getType(); | ||
74 | } | ||
75 | |||
76 | Bu::Variant &Bu::Variant::operator=( const Bu::Variant &rhs ) | ||
77 | { | ||
78 | if( pCore ) | ||
79 | { | ||
80 | delete pCore; | ||
81 | pCore = NULL; | ||
82 | } | ||
83 | if( rhs.pCore ) | ||
84 | { | ||
85 | pCore = rhs.pCore->clone(); | ||
86 | } | ||
87 | |||
88 | return *this; | ||
89 | } | ||
90 | |||
91 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v ) | ||
92 | { | ||
93 | if( !v.pCore ) | ||
94 | return f << "(null)"; | ||
95 | |||
96 | v.pCore->format( f ); | ||
97 | return f; | ||
98 | } | ||
99 | |||