aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2019-04-18 19:09:04 -0700
committerMike Buland <mbuland@penny-arcade.com>2019-04-18 19:09:04 -0700
commit62753c815b5ec34ebfae37a3c89187a01cc17160 (patch)
treed6f85d4af7d54c88a7486a3207c33a168ae09bd8
parentd81e824732c33e2d5ce31fbc58571561a8d9b21f (diff)
downloadlibbu++-62753c815b5ec34ebfae37a3c89187a01cc17160.tar.gz
libbu++-62753c815b5ec34ebfae37a3c89187a01cc17160.tar.bz2
libbu++-62753c815b5ec34ebfae37a3c89187a01cc17160.tar.xz
libbu++-62753c815b5ec34ebfae37a3c89187a01cc17160.zip
Minor quality of life additions to string and variant.
More coming to string. I need to figure some things out in variant.
-rw-r--r--src/stable/string.cpp19
-rw-r--r--src/stable/string.h4
-rw-r--r--src/stable/variant.h21
3 files changed, 44 insertions, 0 deletions
diff --git a/src/stable/string.cpp b/src/stable/string.cpp
index ce679fe..3029584 100644
--- a/src/stable/string.cpp
+++ b/src/stable/string.cpp
@@ -964,6 +964,25 @@ Bu::String Bu::String::toUpper() const
964 return sRet; 964 return sRet;
965} 965}
966 966
967int16_t Bu::String::toInt16( int iRadix ) const
968{
969 flatten();
970 return strtol( core->pFirst->pData, NULL, iRadix );
971}
972
973int32_t Bu::String::toInt32( int iRadix ) const
974{
975 flatten();
976 return strtol( core->pFirst->pData, NULL, iRadix );
977}
978
979int64_t Bu::String::toInt64( int iRadix ) const
980{
981 flatten();
982 return strtoll( core->pFirst->pData, NULL, iRadix );
983}
984
985
967Bu::String::const_iterator Bu::String::find( const char cChar, 986Bu::String::const_iterator Bu::String::find( const char cChar,
968 Bu::String::const_iterator iStart ) const 987 Bu::String::const_iterator iStart ) const
969{ 988{
diff --git a/src/stable/string.h b/src/stable/string.h
index 131f621..af147a7 100644
--- a/src/stable/string.h
+++ b/src/stable/string.h
@@ -879,6 +879,10 @@ namespace Bu
879 */ 879 */
880 String toUpper() const; 880 String toUpper() const;
881 881
882 int16_t toInt16( int iRadix=10 ) const;
883 int32_t toInt32( int iRadix=10 ) const;
884 int64_t toInt64( int iRadix=10 ) const;
885
882 const_iterator find( const char cChar, 886 const_iterator find( const char cChar,
883 const_iterator iStart=const_iterator() ) const; 887 const_iterator iStart=const_iterator() ) const;
884 888
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 )