diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/variable.cpp | 17 | ||||
-rw-r--r-- | src/variable.h | 5 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/variable.cpp b/src/variable.cpp index a3fb4a2..965e1af 100644 --- a/src/variable.cpp +++ b/src/variable.cpp | |||
@@ -453,6 +453,16 @@ Variable Variable::operator+( const Variable &rhs ) const | |||
453 | { | 453 | { |
454 | if( eType != rhs.eType ) | 454 | if( eType != rhs.eType ) |
455 | { | 455 | { |
456 | Type eNew = bestType( eType, rhs.eType ); | ||
457 | |||
458 | if( eType != eNew ) | ||
459 | { | ||
460 | return to( eNew ) + rhs; | ||
461 | } | ||
462 | else | ||
463 | { | ||
464 | return *this + rhs.to( eNew ); | ||
465 | } | ||
456 | throw VariableException("Adding between dissimilar types is not yet supported."); | 466 | throw VariableException("Adding between dissimilar types is not yet supported."); |
457 | } | 467 | } |
458 | else | 468 | else |
@@ -868,6 +878,13 @@ void Variable::deinitType() | |||
868 | iValue = 0; | 878 | iValue = 0; |
869 | } | 879 | } |
870 | 880 | ||
881 | Variable::Type Variable::bestType( Variable::Type t1, Variable::Type t2 ) const | ||
882 | { | ||
883 | Type tBest = Bu::max( t1, t2 ); | ||
884 | |||
885 | return tBest; | ||
886 | } | ||
887 | |||
871 | template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k ) | 888 | template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k ) |
872 | { | 889 | { |
873 | switch( k.getType() ) | 890 | switch( k.getType() ) |
diff --git a/src/variable.h b/src/variable.h index 8741b28..2eedcbb 100644 --- a/src/variable.h +++ b/src/variable.h | |||
@@ -28,12 +28,12 @@ public: | |||
28 | tBool, | 28 | tBool, |
29 | tInt, | 29 | tInt, |
30 | tFloat, | 30 | tFloat, |
31 | tString, | ||
32 | tSituation, | 31 | tSituation, |
33 | tVariable, | 32 | tVariable, |
34 | tVarPtr, | 33 | tVarPtr, |
35 | tList, | 34 | tList, |
36 | tDictionary | 35 | tDictionary, |
36 | tString, | ||
37 | }; | 37 | }; |
38 | 38 | ||
39 | public: | 39 | public: |
@@ -90,6 +90,7 @@ public: | |||
90 | private: | 90 | private: |
91 | void initType(); | 91 | void initType(); |
92 | void deinitType(); | 92 | void deinitType(); |
93 | Type bestType( Type t1, Type t2 ) const; | ||
93 | 94 | ||
94 | private: | 95 | private: |
95 | Type eType; | 96 | Type eType; |