Variablen.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "Variablen.h"
  2. #include "Gegenstand.h"
  3. Variable::Variable( VariableTyp typ )
  4. {
  5. this->typ = typ;
  6. ref = 1;
  7. }
  8. Variable::~Variable()
  9. {}
  10. VariableTyp Variable::getVariableTyp() const
  11. {
  12. return typ;
  13. }
  14. Variable *Variable::getThis()
  15. {
  16. ref++;
  17. return this;
  18. }
  19. Variable *Variable::release()
  20. {
  21. if( !--ref )
  22. delete this;
  23. return 0;
  24. }
  25. bool isTrue( Variable *v )
  26. {
  27. if( !v )
  28. return 0;
  29. switch( v->getVariableTyp() )
  30. {
  31. case NICHTS:
  32. return 0;
  33. case INTEGER:
  34. return ( (Integer *)v )->getValue() != 0;
  35. case BOOLEAN:
  36. return ( (Boolean *)v )->getValue();
  37. case STRING:
  38. return ( (String *)v )->getValue().getLength();
  39. case FLOAT:
  40. return ( (Float *)v )->getValue() != 0;
  41. case TASTE:
  42. return ( (Integer *)v )->getValue() != 0;
  43. case GEGENSTAND_TYP:
  44. return ( (GegenstandTypVar *)v )->getValue() != KEIN_GEGENSTAND;
  45. default:
  46. return 1;
  47. }
  48. }
  49. Integer::Integer( int value, bool taste )
  50. : Variable( taste ? TASTE : INTEGER )
  51. {
  52. this->value = value;
  53. }
  54. void Integer::setValue( int value )
  55. {
  56. this->value = value;
  57. }
  58. int Integer::getValue() const
  59. {
  60. return value;
  61. }
  62. Boolean::Boolean( bool value )
  63. : Variable( BOOLEAN )
  64. {
  65. this->value = value;
  66. }
  67. void Boolean::setValue( bool value )
  68. {
  69. this->value = value;
  70. }
  71. bool Boolean::getValue() const
  72. {
  73. return value;
  74. }
  75. String::String( const char *value, bool richtung )
  76. : Variable( richtung ? RICHTUNG : STRING )
  77. {
  78. this->value = value;
  79. }
  80. void String::setValue( Text value )
  81. {
  82. this->value = value;
  83. }
  84. const Text &String::getValue() const
  85. {
  86. return value;
  87. }
  88. Float::Float( float value )
  89. : Variable( FLOAT )
  90. {
  91. this->value = value;
  92. }
  93. void Float::setValue( float value )
  94. {
  95. this->value = value;
  96. }
  97. float Float::getValue() const
  98. {
  99. return value;
  100. }