From 70076bb00bdedb57405ed2ef27e2fec172e2f38a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 30 Dec 2011 23:07:59 -0700 Subject: Well, +=, -= on dictionaries/lists works now. --- src/variable.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'src/variable.cpp') diff --git a/src/variable.cpp b/src/variable.cpp index 1100c84..0ce9793 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -363,8 +363,77 @@ Variable &Variable::operator+=( const Variable &rhs ) return *this; } +Variable &Variable::operator-=( const Variable &rhs ) +{ + switch( eType ) + { + case tNull: + throw VariableException("You cannot subtract nulls."); + + case tBool: + throw VariableException("You cannot subtract bools."); + + case tInt: + switch( rhs.eType ) + { + case tInt: + iValue -= rhs.iValue; + break; + + case tFloat: + { + double dTmp = iValue; + eType = tFloat; + fValue = dTmp - rhs.fValue; + } + break; + + default: + throw VariableException("Int -= invalid..."); + } + break; + + case tFloat: + switch( rhs.eType ) + { + case tInt: + fValue -= rhs.iValue; + break; + + case tFloat: + fValue -= rhs.fValue; + break; + + default: + throw VariableException("Int += invalid..."); + } + break; + + case tString: + throw VariableException("You cannot subtract strings."); + break; + + case tSituation: + throw VariableException("You cannot subtract situations."); + break; + + case tVariable: + throw VariableException("You cannot subtract variable names."); + break; + + case tList: + (*lValue).erase( rhs ); + break; + + case tDictionary: + (*hValue).erase( rhs ); + break; + } + + return *this; +} + /* -Variable &Variable::operator-=( const Variable &rhs ); Variable &Variable::operator*=( const Variable &rhs ); Variable &Variable::operator/=( const Variable &rhs ); */ -- cgit v1.2.3