#include "KSGSDouble.h" #include "KSGSTyp.h" #include "../Error/Error.h" #include "KSGSBool.h" #include "KSGSInt.h" #include "KSGSText.h" using namespace KSGScript; // Inhalt der KSGSDoubleKlasse Klasse aus KSGSDouble.h // Konstruktor KSGSDoubleKlasse::KSGSDoubleKlasse( KSGScriptProcessor *zObj, double std ) : KSGSKlasseInstanz( KSGS_DOUBLE, 0, 0, zObj ) { val = std; } // Destruktor KSGSDoubleKlasse::~KSGSDoubleKlasse() { } // nicht constant void KSGSDoubleKlasse::set( double d ) { val = d; } KSGSVariable *KSGSDoubleKlasse::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->getDouble(); ret = dynamic_cast( getThis() ); break; case KSGS_O_PLUSSET: val += rechts->getDouble(); ret = dynamic_cast( getThis() ); break; case KSGS_O_MINUSSET: val -= rechts->getDouble(); ret = dynamic_cast( getThis() ); break; case KSGS_O_MAHLSET: val *= rechts->getDouble(); ret = dynamic_cast( getThis() ); break; case KSGS_O_GETEILTSET: val /= rechts->getDouble(); ret = dynamic_cast( getThis() ); break; case KSGS_O_UNDSET: val = (int)val & rechts->getInt(); ret = dynamic_cast( getThis() ); break; case KSGS_O_ODERSET: val = (int)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 KSGSDoubleKlasse( obj, (int)val | rechts->getInt() ); break; case KSGS_O_BITUND: ret = new KSGSDoubleKlasse( obj, (int)val & rechts->getInt() ); break; case KSGS_O_PLUS: ret = new KSGSDoubleKlasse( obj, val + rechts->getDouble() ); break; case KSGS_O_MINUS: ret = new KSGSDoubleKlasse( obj, val - rechts->getDouble() ); break; case KSGS_O_MAHL: ret = new KSGSDoubleKlasse( obj, val * rechts->getDouble() ); break; case KSGS_O_GETEILT: ret = new KSGSDoubleKlasse( obj, val / rechts->getDouble() ); break; case KSGS_O_REST: ret = new KSGSDoubleKlasse( obj, (int)val % rechts->getInt() ); break; case KSGS_O_PLUS1: ret = new KSGSDoubleKlasse( obj, val++ ); break; case KSGS_O_MINUS1: ret = new KSGSDoubleKlasse( obj, val-- ); break; case KSGS_O_NICHT: ret = new KSGSDoubleKlasse( obj, !val ); break; case KSGS_O_BITNICHT: ret = new KSGSDoubleKlasse( obj, ~(int)val ); break; case KSGS_O_NACHLINKS: ret = new KSGSDoubleKlasse( obj, (int)val << rechts->getInt() ); break; case KSGS_O_NACHRECHTS: ret = new KSGSDoubleKlasse( obj, (int)val >> rechts->getInt() ); break; } if( !ret ) error( 21, {}, obj ); if( rechts ) rechts->release(); return ret; } // constant double KSGSDoubleKlasse::getVal() const { return val; } KSGSVariable *KSGSDoubleKlasse::umwandelnIn( int typ ) const { switch( typ ) { case KSGS_BOOL: return new KSGSBoolKlasse( obj, val != 0 ); case KSGS_INT: return new KSGSIntKlasse( obj, (int)val ); case KSGS_TEXT: return new KSGSTextKlasse( obj, Text() += val ); } error( 16, {}, obj ); return 0; }