123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #include "KSGSInt.h"
- #include "KSGSTyp.h"
- #include "../Error/Error.h"
- #include "KSGSBool.h"
- #include "KSGSDouble.h"
- #include "KSGSText.h"
- using namespace KSGScript;
- // Inhalt der KSGSIntKlasse Klasse aus KSGSInt.h
- // Konstruktor
- KSGSIntKlasse::KSGSIntKlasse( KSGScriptObj *zObj, int std )
- : KSGSKlasseInstanz( KSGS_INT, 0, 0, zObj )
- {
- val = std;
- }
- // Destruktor
- KSGSIntKlasse::~KSGSIntKlasse()
- {
- }
- // nicht constant
- void KSGSIntKlasse::set( int i )
- {
- val = i;
- }
- KSGSVariable *KSGSIntKlasse::doOperator( int id, KSGSVariable *rechts )
- {
- if( !rechts && id != KSGS_O_NICHT && id != KSGS_O_MINUS1 && id != KSGS_O_PLUS1 && id != KSGS_O_BITNICHT )
- {
- if( rechts )
- rechts->release();
- error( 3, {}, obj );
- return 0;
- }
- KSGSVariable *ret = 0;
- switch( id )
- {
- case KSGS_O_SET:
- val = rechts->getInt();
- ret = getThis();
- break;
- case KSGS_O_PLUSSET:
- val += rechts->getInt();
- ret = getThis();
- break;
- case KSGS_O_MINUSSET:
- val -= rechts->getInt();
- ret = getThis();
- break;
- case KSGS_O_MAHLSET:
- val = (int)( val * rechts->getDouble() );
- ret = getThis();
- break;
- case KSGS_O_GETEILTSET:
- val = (int)( val / rechts->getDouble() );
- ret = getThis();
- break;
- case KSGS_O_UNDSET:
- val &= rechts->getInt();
- ret = getThis();
- break;
- case KSGS_O_ODERSET:
- val |= rechts->getInt();
- ret = getThis();
- break;
- case KSGS_O_GLEICH:
- ret = new KSGSBoolKlasse( obj, val == rechts->getDouble() );
- break;
- case KSGS_O_KLEINERGLEICH:
- ret = new KSGSBoolKlasse( obj, val <= rechts->getDouble() );
- break;
- case KSGS_O_GRÖßERGLEICH:
- ret = new KSGSBoolKlasse( obj, val >= rechts->getDouble() );
- break;
- case KSGS_O_UNGLEICH:
- ret = new KSGSBoolKlasse( obj, val != rechts->getDouble() );
- break;
- case KSGS_O_KLEINER:
- ret = new KSGSBoolKlasse( obj, val < rechts->getDouble() );
- break;
- case KSGS_O_GRÖßER:
- ret = new KSGSBoolKlasse( obj, val > rechts->getDouble() );
- break;
- case KSGS_O_ODER:
- ret = new KSGSBoolKlasse( obj, val || rechts->getDouble() );
- break;
- case KSGS_O_UND:
- ret = new KSGSBoolKlasse( obj, val && rechts->getDouble() );
- break;
- case KSGS_O_BITODER:
- ret = new KSGSIntKlasse( obj, val | rechts->getInt() );
- break;
- case KSGS_O_BITUND:
- ret = new KSGSIntKlasse( obj, val & rechts->getInt() );
- break;
- case KSGS_O_PLUS:
- ret = new KSGSIntKlasse( obj, val + rechts->getInt() );
- break;
- case KSGS_O_MINUS:
- ret = new KSGSIntKlasse( obj, val - rechts->getInt() );
- break;
- case KSGS_O_MAHL:
- ret = new KSGSIntKlasse( obj, (int)( val * rechts->getDouble() ) );
- break;
- case KSGS_O_GETEILT:
- ret = new KSGSIntKlasse( obj, (int)( val / rechts->getDouble() ) );
- break;
- case KSGS_O_REST:
- ret = new KSGSIntKlasse( obj, val % rechts->getInt() );
- break;
- case KSGS_O_PLUS1:
- ret = new KSGSIntKlasse( obj, val++ );
- break;
- case KSGS_O_MINUS1:
- ret = new KSGSIntKlasse( obj, val-- );
- break;
- case KSGS_O_NICHT:
- ret = new KSGSIntKlasse( obj, !val );
- break;
- case KSGS_O_BITNICHT:
- ret = new KSGSIntKlasse( obj, ~val );
- break;
- case KSGS_O_NACHLINKS:
- ret = new KSGSIntKlasse( obj, val << rechts->getInt() );
- break;
- case KSGS_O_NACHRECHTS:
- ret = new KSGSIntKlasse( obj, val >> rechts->getInt() );
- break;
- }
- if( !ret )
- error( 21, {}, obj );
- if( rechts )
- rechts->release();
- return ret;
- }
- // constant
- int KSGSIntKlasse::getVal() const
- {
- return val;
- }
- KSGSVariable *KSGSIntKlasse::umwandelnIn( int typ ) const
- {
- switch( typ )
- {
- case KSGS_BOOL:
- return new KSGSBoolKlasse( obj, val != 0 );
- case KSGS_DOUBLE:
- return new KSGSDoubleKlasse( obj, val );
- case KSGS_TEXT:
- return new KSGSTextKlasse( obj, Text() += val );
- }
- error( 16, {}, obj );
- return 0;
- }
- // Reference Counting
- KSGSVariable *KSGSIntKlasse::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|