KSGSBool.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "KSGSBool.h"
  2. #include "KSGSTyp.h"
  3. #include "../Error/Error.h"
  4. #include "KSGSInt.h"
  5. #include "KSGSDouble.h"
  6. #include "KSGSText.h"
  7. using namespace KSGScript;
  8. // Inhalt der KSGSBoolKlasse Klasse aus KSGSBool.h
  9. // Konstruktor
  10. KSGSBoolKlasse::KSGSBoolKlasse( KSGScriptProcessor *zObj, bool std )
  11. : KSGSKlasseInstanz( KSGS_BOOL, 0, 0, zObj )
  12. {
  13. val = std;
  14. }
  15. // Destruktor
  16. KSGSBoolKlasse::~KSGSBoolKlasse()
  17. {
  18. }
  19. // nicht constant
  20. KSGSVariable *KSGSBoolKlasse::doOperator( int id, KSGSVariable *rechts )
  21. {
  22. if( !rechts && id != KSGS_O_NICHT && id != KSGS_O_MINUS1 && id != KSGS_O_PLUS1 )
  23. {
  24. if( rechts )
  25. rechts->release();
  26. error( 3, {}, obj );
  27. return 0;
  28. }
  29. KSGSVariable *ret = 0;
  30. switch( id )
  31. {
  32. case KSGS_O_SET:
  33. val = rechts->getBool();
  34. ret = (KSGSVariable *)getThis();
  35. break;
  36. case KSGS_O_PLUSSET:
  37. val = ( val + rechts->getBool() ) != 0;
  38. ret = (KSGSVariable *)getThis();
  39. break;
  40. case KSGS_O_MINUSSET:
  41. val = ( val - rechts->getBool() ) != 0;
  42. ret = (KSGSVariable *)getThis();
  43. break;
  44. case KSGS_O_MAHLSET:
  45. val = ( val * rechts->getBool() ) != 0;
  46. ret = (KSGSVariable *)getThis();
  47. break;
  48. case KSGS_O_UNDSET:
  49. val &= rechts->getBool();
  50. ret = (KSGSVariable *)getThis();
  51. break;
  52. case KSGS_O_ODERSET:
  53. val |= rechts->getBool();
  54. ret = (KSGSVariable *)getThis();
  55. break;
  56. case KSGS_O_GLEICH:
  57. ret = new KSGSBoolKlasse( obj, val == rechts->getBool() );
  58. break;
  59. case KSGS_O_KLEINERGLEICH:
  60. ret = new KSGSBoolKlasse( obj, val <= rechts->getBool() );
  61. break;
  62. case KSGS_O_GRÖßERGLEICH:
  63. ret = new KSGSBoolKlasse( obj, val >= rechts->getBool() );
  64. break;
  65. case KSGS_O_UNGLEICH:
  66. ret = new KSGSBoolKlasse( obj, val != rechts->getBool() );
  67. break;
  68. case KSGS_O_KLEINER:
  69. ret = new KSGSBoolKlasse( obj, val < rechts->getBool() );
  70. break;
  71. case KSGS_O_GRÖßER:
  72. ret = new KSGSBoolKlasse( obj, val > rechts->getBool() );
  73. break;
  74. case KSGS_O_ODER:
  75. ret = new KSGSBoolKlasse( obj, val || rechts->getBool() );
  76. break;
  77. case KSGS_O_UND:
  78. ret = new KSGSBoolKlasse( obj, val && rechts->getBool() );
  79. break;
  80. case KSGS_O_BITODER:
  81. ret = new KSGSBoolKlasse( obj, val | rechts->getBool() );
  82. break;
  83. case KSGS_O_BITUND:
  84. ret = new KSGSBoolKlasse( obj, val & rechts->getBool() );
  85. break;
  86. case KSGS_O_PLUS:
  87. ret = new KSGSBoolKlasse( obj, ( val + rechts->getBool() ) != 0 );
  88. break;
  89. case KSGS_O_MINUS:
  90. ret = new KSGSBoolKlasse( obj, ( val - rechts->getBool() ) != 0 );
  91. break;
  92. case KSGS_O_MAHL:
  93. ret = new KSGSBoolKlasse( obj, ( val * rechts->getBool() ) != 0 );
  94. break;
  95. case KSGS_O_PLUS1:
  96. ret = new KSGSBoolKlasse( obj, val++ != 0 );
  97. break;
  98. case KSGS_O_MINUS1:
  99. ret = new KSGSBoolKlasse( obj, ( val - 1 ) != 0 );
  100. break;
  101. case KSGS_O_NICHT:
  102. ret = new KSGSBoolKlasse( obj, !val );
  103. break;
  104. }
  105. if( !ret )
  106. error( 21, {}, obj );
  107. if( rechts )
  108. rechts->release();
  109. return ret;
  110. }
  111. // constant
  112. bool KSGSBoolKlasse::getVal() const
  113. {
  114. return val;
  115. }
  116. KSGSVariable *KSGSBoolKlasse::umwandelnIn( int typ ) const
  117. {
  118. switch( typ )
  119. {
  120. case KSGS_INT:
  121. return new KSGSIntKlasse( obj, val );
  122. case KSGS_DOUBLE:
  123. return new KSGSDoubleKlasse( obj, val );
  124. case KSGS_TEXT:
  125. return new KSGSTextKlasse( obj, Text() += (int)val );
  126. }
  127. error( 16, {}, obj );
  128. return 0;
  129. }