summaryrefslogtreecommitdiff
path: root/src/stable/variant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/variant.cpp')
-rw-r--r--src/stable/variant.cpp92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/stable/variant.cpp b/src/stable/variant.cpp
index 674ae04..d724fa7 100644
--- a/src/stable/variant.cpp
+++ b/src/stable/variant.cpp
@@ -11,7 +11,7 @@
11 11
12namespace Bu 12namespace Bu
13{ 13{
14 Formatter &operator<<( Formatter &f, const String &s ); 14 Formatter &operator<<( Formatter &f, const String &s );
15}; 15};
16 16
17Bu::VariantTypeRoot::VariantTypeRoot() 17Bu::VariantTypeRoot::VariantTypeRoot()
@@ -23,84 +23,84 @@ Bu::VariantTypeRoot::~VariantTypeRoot()
23} 23}
24 24
25Bu::Variant::Variant() : 25Bu::Variant::Variant() :
26 pCore( NULL ) 26 pCore( NULL )
27{ 27{
28} 28}
29 29
30Bu::Variant::Variant( const Variant &v ) : 30Bu::Variant::Variant( const Variant &v ) :
31 pCore( NULL ) 31 pCore( NULL )
32{ 32{
33 if( v.pCore ) 33 if( v.pCore )
34 { 34 {
35 pCore = v.pCore->clone(); 35 pCore = v.pCore->clone();
36 } 36 }
37} 37}
38 38
39Bu::Variant::Variant( const char *t ) : 39Bu::Variant::Variant( const char *t ) :
40 pCore( NULL ) 40 pCore( NULL )
41{ 41{
42 set( Bu::String( t ) ); 42 set( Bu::String( t ) );
43} 43}
44 44
45Bu::Variant::~Variant() 45Bu::Variant::~Variant()
46{ 46{
47 if( pCore ) 47 if( pCore )
48 { 48 {
49 delete pCore; 49 delete pCore;
50 pCore = NULL; 50 pCore = NULL;
51 } 51 }
52} 52}
53 53
54Bu::String Bu::Variant::toString() const 54Bu::String Bu::Variant::toString() const
55{ 55{
56 if( getType() == typeid( Bu::String ) ) 56 if( getType() == typeid( Bu::String ) )
57 { 57 {
58 return get<Bu::String>(); 58 return get<Bu::String>();
59 } 59 }
60 else 60 else
61 { 61 {
62 Bu::MemBuf mb; 62 Bu::MemBuf mb;
63 Bu::Formatter f( mb ); 63 Bu::Formatter f( mb );
64 f << *this; 64 f << *this;
65 return mb.getString(); 65 return mb.getString();
66 } 66 }
67} 67}
68 68
69bool Bu::Variant::isSet() const 69bool Bu::Variant::isSet() const
70{ 70{
71 return pCore != NULL; 71 return pCore != NULL;
72} 72}
73 73
74const std::type_info &Bu::Variant::getType() const 74const std::type_info &Bu::Variant::getType() const
75{ 75{
76 if( !pCore ) 76 if( !pCore )
77 { 77 {
78 throw Bu::ExceptionBase("No data!"); 78 throw Bu::ExceptionBase("No data!");
79 } 79 }
80 return pCore->getType(); 80 return pCore->getType();
81} 81}
82 82
83Bu::Variant &Bu::Variant::operator=( const Bu::Variant &rhs ) 83Bu::Variant &Bu::Variant::operator=( const Bu::Variant &rhs )
84{ 84{
85 if( pCore ) 85 if( pCore )
86 { 86 {
87 delete pCore; 87 delete pCore;
88 pCore = NULL; 88 pCore = NULL;
89 } 89 }
90 if( rhs.pCore ) 90 if( rhs.pCore )
91 { 91 {
92 pCore = rhs.pCore->clone(); 92 pCore = rhs.pCore->clone();
93 } 93 }
94 94
95 return *this; 95 return *this;
96} 96}
97 97
98Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v ) 98Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Variant &v )
99{ 99{
100 if( !v.pCore ) 100 if( !v.pCore )
101 return f << "(null)"; 101 return f << "(null)";
102 102
103 v.pCore->format( f ); 103 v.pCore->format( f );
104 return f; 104 return f;
105} 105}
106 106