KSGSBool.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 = dynamic_cast<KSGSVariable *>( getThis() );
  35. break;
  36. case KSGS_O_PLUSSET:
  37. val = ( val + rechts->getBool() ) != 0;
  38. ret = dynamic_cast<KSGSVariable *>( getThis() );
  39. break;
  40. case KSGS_O_MINUSSET:
  41. val = ( val - rechts->getBool() ) != 0;
  42. ret = dynamic_cast<KSGSVariable *>( getThis() );
  43. break;
  44. case KSGS_O_MAHLSET:
  45. val = ( val * rechts->getBool() ) != 0;
  46. ret = dynamic_cast<KSGSVariable *>( getThis() );
  47. break;
  48. case KSGS_O_UNDSET:
  49. val &= rechts->getBool();
  50. ret = dynamic_cast<KSGSVariable *>( getThis() );
  51. break;
  52. case KSGS_O_ODERSET:
  53. val |= rechts->getBool();
  54. ret = dynamic_cast<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_GREATERGLEICH:
  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_GREATER:
  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. val = 1;
  98. break;
  99. case KSGS_O_MINUS1:
  100. ret = new KSGSBoolKlasse( obj, ( val - 1 ) != 0 );
  101. break;
  102. case KSGS_O_NICHT:
  103. ret = new KSGSBoolKlasse( obj, !val );
  104. break;
  105. }
  106. if( !ret )
  107. error( 21, {}, obj );
  108. if( rechts )
  109. rechts->release();
  110. return ret;
  111. }
  112. // constant
  113. bool KSGSBoolKlasse::getVal() const
  114. {
  115. return val;
  116. }
  117. KSGSVariable *KSGSBoolKlasse::umwandelnIn( int typ ) const
  118. {
  119. switch( typ )
  120. {
  121. case KSGS_INT:
  122. return new KSGSIntKlasse( obj, val );
  123. case KSGS_DOUBLE:
  124. return new KSGSDoubleKlasse( obj, val );
  125. case KSGS_TEXT:
  126. return new KSGSTextKlasse( obj, Text() += (int)val );
  127. }
  128. error( 16, {}, obj );
  129. return 0;
  130. }