#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( KSGScriptProcessor *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 = dynamic_cast( getThis() ); break; case KSGS_O_PLUSSET: val += rechts->getInt(); ret = dynamic_cast( getThis() ); break; case KSGS_O_MINUSSET: val -= rechts->getInt(); ret = dynamic_cast( getThis() ); break; case KSGS_O_MAHLSET: val = (int)( val * rechts->getDouble() ); ret = dynamic_cast( getThis() ); break; case KSGS_O_GETEILTSET: val = (int)( val / rechts->getDouble() ); ret = dynamic_cast( getThis() ); break; case KSGS_O_UNDSET: val &= rechts->getInt(); ret = dynamic_cast( getThis() ); break; case KSGS_O_ODERSET: val |= rechts->getInt(); ret = dynamic_cast( 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_GREATERGLEICH: 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_GREATER: 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; }