diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 23:07:59 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 23:07:59 -0700 |
| commit | 70076bb00bdedb57405ed2ef27e2fec172e2f38a (patch) | |
| tree | 4339853d972427b02bb4d51a88bcb665ba61307a /src/variable.cpp | |
| parent | 8bcb83035607371a2326374665e9cc56c662a783 (diff) | |
| download | stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.gz stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.bz2 stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.xz stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.zip | |
Well, +=, -= on dictionaries/lists works now.
Diffstat (limited to 'src/variable.cpp')
| -rw-r--r-- | src/variable.cpp | 71 |
1 files changed, 70 insertions, 1 deletions
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 ) | |||
| 363 | return *this; | 363 | return *this; |
| 364 | } | 364 | } |
| 365 | 365 | ||
| 366 | Variable &Variable::operator-=( const Variable &rhs ) | ||
| 367 | { | ||
| 368 | switch( eType ) | ||
| 369 | { | ||
| 370 | case tNull: | ||
| 371 | throw VariableException("You cannot subtract nulls."); | ||
| 372 | |||
| 373 | case tBool: | ||
| 374 | throw VariableException("You cannot subtract bools."); | ||
| 375 | |||
| 376 | case tInt: | ||
| 377 | switch( rhs.eType ) | ||
| 378 | { | ||
| 379 | case tInt: | ||
| 380 | iValue -= rhs.iValue; | ||
| 381 | break; | ||
| 382 | |||
| 383 | case tFloat: | ||
| 384 | { | ||
| 385 | double dTmp = iValue; | ||
| 386 | eType = tFloat; | ||
| 387 | fValue = dTmp - rhs.fValue; | ||
| 388 | } | ||
| 389 | break; | ||
| 390 | |||
| 391 | default: | ||
| 392 | throw VariableException("Int -= invalid..."); | ||
| 393 | } | ||
| 394 | break; | ||
| 395 | |||
| 396 | case tFloat: | ||
| 397 | switch( rhs.eType ) | ||
| 398 | { | ||
| 399 | case tInt: | ||
| 400 | fValue -= rhs.iValue; | ||
| 401 | break; | ||
| 402 | |||
| 403 | case tFloat: | ||
| 404 | fValue -= rhs.fValue; | ||
| 405 | break; | ||
| 406 | |||
| 407 | default: | ||
| 408 | throw VariableException("Int += invalid..."); | ||
| 409 | } | ||
| 410 | break; | ||
| 411 | |||
| 412 | case tString: | ||
| 413 | throw VariableException("You cannot subtract strings."); | ||
| 414 | break; | ||
| 415 | |||
| 416 | case tSituation: | ||
| 417 | throw VariableException("You cannot subtract situations."); | ||
| 418 | break; | ||
| 419 | |||
| 420 | case tVariable: | ||
| 421 | throw VariableException("You cannot subtract variable names."); | ||
| 422 | break; | ||
| 423 | |||
| 424 | case tList: | ||
| 425 | (*lValue).erase( rhs ); | ||
| 426 | break; | ||
| 427 | |||
| 428 | case tDictionary: | ||
| 429 | (*hValue).erase( rhs ); | ||
| 430 | break; | ||
| 431 | } | ||
| 432 | |||
| 433 | return *this; | ||
| 434 | } | ||
| 435 | |||
| 366 | /* | 436 | /* |
| 367 | Variable &Variable::operator-=( const Variable &rhs ); | ||
| 368 | Variable &Variable::operator*=( const Variable &rhs ); | 437 | Variable &Variable::operator*=( const Variable &rhs ); |
| 369 | Variable &Variable::operator/=( const Variable &rhs ); | 438 | Variable &Variable::operator/=( const Variable &rhs ); |
| 370 | */ | 439 | */ |
