KSGSDouble.cpp 4.4 KB

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