aboutsummaryrefslogtreecommitdiff
path: root/src/stable/variant.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/variant.h')
-rw-r--r--src/stable/variant.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/stable/variant.h b/src/stable/variant.h
index af06815..7189d7a 100644
--- a/src/stable/variant.h
+++ b/src/stable/variant.h
@@ -35,6 +35,7 @@ namespace Bu
35 virtual const std::type_info &getType() const=0; 35 virtual const std::type_info &getType() const=0;
36 virtual VariantTypeRoot *clone() const=0; 36 virtual VariantTypeRoot *clone() const=0;
37 virtual void format( Bu::Formatter &f ) const=0; 37 virtual void format( Bu::Formatter &f ) const=0;
38 virtual const void *rawData() const=0;
38 }; 39 };
39 40
40 template<class t> 41 template<class t>
@@ -75,6 +76,11 @@ namespace Bu
75 { 76 {
76 f << data; 77 f << data;
77 } 78 }
79
80 virtual const void *rawData() const
81 {
82 return &data;
83 }
78 84
79 virtual const std::type_info &getType() const 85 virtual const std::type_info &getType() const
80 { 86 {
@@ -173,6 +179,21 @@ namespace Bu
173 } 179 }
174 return dynamic_cast<VariantType<t> *>(pCore)->getData(); 180 return dynamic_cast<VariantType<t> *>(pCore)->getData();
175 } 181 }
182
183 template<class t>
184 t &cast() const
185 {
186 if( !pCore )
187 {
188 throw Bu::ExceptionBase("No data!");
189 }
190
191 t *p = dynamic_cast<t *>(pCore->rawData());
192 if( p == NULL )
193 throw Bu::ExceptionBase("Invalid type conversion.");
194
195 return *p;
196 }
176 197
177 template<class t> 198 template<class t>
178 void set( const t &val ) 199 void set( const t &val )