summaryrefslogtreecommitdiff
path: root/src/variable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/variable.cpp')
-rw-r--r--src/variable.cpp146
1 files changed, 141 insertions, 5 deletions
diff --git a/src/variable.cpp b/src/variable.cpp
index 2ea8334..68a1778 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -417,7 +417,7 @@ Variable &Variable::operator-=( const Variable &rhs )
417 break; 417 break;
418 418
419 default: 419 default:
420 throw VariableException("Int += invalid..."); 420 throw VariableException("Int -= invalid...");
421 } 421 }
422 break; 422 break;
423 423
@@ -445,10 +445,146 @@ Variable &Variable::operator-=( const Variable &rhs )
445 return *this; 445 return *this;
446} 446}
447 447
448/* 448Variable &Variable::operator*=( const Variable &rhs )
449Variable &Variable::operator*=( const Variable &rhs ); 449{
450Variable &Variable::operator/=( const Variable &rhs ); 450 switch( eType )
451*/ 451 {
452 case tNull:
453 throw VariableException("You cannot multiply nulls.");
454
455 case tBool:
456 throw VariableException("You cannot multiply bools.");
457
458 case tInt:
459 switch( rhs.eType )
460 {
461 case tInt:
462 iValue *= rhs.iValue;
463 break;
464
465 case tFloat:
466 {
467 double dTmp = iValue;
468 eType = tFloat;
469 fValue = dTmp * rhs.fValue;
470 }
471 break;
472
473 default:
474 throw VariableException("Int *= invalid...");
475 }
476 break;
477
478 case tFloat:
479 switch( rhs.eType )
480 {
481 case tInt:
482 fValue *= rhs.iValue;
483 break;
484
485 case tFloat:
486 fValue *= rhs.fValue;
487 break;
488
489 default:
490 throw VariableException("Int *= invalid...");
491 }
492 break;
493
494 case tString:
495 throw VariableException("You cannot multiply strings.");
496 break;
497
498 case tSituation:
499 throw VariableException("You cannot multiply situations.");
500 break;
501
502 case tVariable:
503 throw VariableException("You cannot multiply variable names.");
504 break;
505
506 case tList:
507 throw VariableException("You cannot multiply lists.");
508 break;
509
510 case tDictionary:
511 throw VariableException("You cannot multiply dictionaries.");
512 break;
513 }
514
515 return *this;
516}
517
518Variable &Variable::operator/=( const Variable &rhs )
519{
520 switch( eType )
521 {
522 case tNull:
523 throw VariableException("You cannot divide nulls.");
524
525 case tBool:
526 throw VariableException("You cannot divide bools.");
527
528 case tInt:
529 switch( rhs.eType )
530 {
531 case tInt:
532 iValue /= rhs.iValue;
533 break;
534
535 case tFloat:
536 {
537 double dTmp = iValue;
538 eType = tFloat;
539 fValue = dTmp / rhs.fValue;
540 }
541 break;
542
543 default:
544 throw VariableException("Int /= invalid...");
545 }
546 break;
547
548 case tFloat:
549 switch( rhs.eType )
550 {
551 case tInt:
552 fValue /= rhs.iValue;
553 break;
554
555 case tFloat:
556 fValue /= rhs.fValue;
557 break;
558
559 default:
560 throw VariableException("Int /= invalid...");
561 }
562 break;
563
564 case tString:
565 throw VariableException("You cannot divide strings.");
566 break;
567
568 case tSituation:
569 throw VariableException("You cannot divide situations.");
570 break;
571
572 case tVariable:
573 throw VariableException("You cannot divide variable names.");
574 break;
575
576 case tList:
577 throw VariableException("You cannot divide lists.");
578 break;
579
580 case tDictionary:
581 throw VariableException("You cannot divide dictionaries.");
582 break;
583 }
584
585 return *this;
586}
587
452Variable Variable::operator+( const Variable &rhs ) const 588Variable Variable::operator+( const Variable &rhs ) const
453{ 589{
454 if( eType != rhs.eType ) 590 if( eType != rhs.eType )