From 62753c815b5ec34ebfae37a3c89187a01cc17160 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 18 Apr 2019 19:09:04 -0700 Subject: Minor quality of life additions to string and variant. More coming to string. I need to figure some things out in variant. --- src/stable/variant.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/stable/variant.h') 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 virtual const std::type_info &getType() const=0; virtual VariantTypeRoot *clone() const=0; virtual void format( Bu::Formatter &f ) const=0; + virtual const void *rawData() const=0; }; template @@ -75,6 +76,11 @@ namespace Bu { f << data; } + + virtual const void *rawData() const + { + return &data; + } virtual const std::type_info &getType() const { @@ -173,6 +179,21 @@ namespace Bu } return dynamic_cast *>(pCore)->getData(); } + + template + t &cast() const + { + if( !pCore ) + { + throw Bu::ExceptionBase("No data!"); + } + + t *p = dynamic_cast(pCore->rawData()); + if( p == NULL ) + throw Bu::ExceptionBase("Invalid type conversion."); + + return *p; + } template void set( const t &val ) -- cgit v1.2.3