|
@@ -13,33 +13,32 @@ using namespace KSGScript;
|
|
KSGSFunktionInstanz::KSGSFunktionInstanz( RCArray< KSGSBefehl > *ba, int rt, KSGScriptObj *obj, KSGSVariable *klasse )
|
|
KSGSFunktionInstanz::KSGSFunktionInstanz( RCArray< KSGSBefehl > *ba, int rt, KSGScriptObj *obj, KSGSVariable *klasse )
|
|
: Thread()
|
|
: Thread()
|
|
{
|
|
{
|
|
- lokaleVariablen = new RCArray< KSGSVariable >();
|
|
|
|
- befehle = ba;
|
|
|
|
- this->klasse = klasse;
|
|
|
|
- this->obj = obj;
|
|
|
|
- threadVar = 0;
|
|
|
|
- returnTyp = rt;
|
|
|
|
- retVar = 0;
|
|
|
|
- pausiert = 0;
|
|
|
|
- beendet = 0;
|
|
|
|
- breakB = 0;
|
|
|
|
- continueB = 0;
|
|
|
|
- scrId = obj->getScriptId();
|
|
|
|
- ref = 1;
|
|
|
|
|
|
+ lokaleVariablen = new RCArray< KSGSVariable >();
|
|
|
|
+ befehle = ba;
|
|
|
|
+ this->klasse = klasse;
|
|
|
|
+ this->obj = obj;
|
|
|
|
+ threadVar = 0;
|
|
|
|
+ returnTyp = rt;
|
|
|
|
+ retVar = 0;
|
|
|
|
+ pausiert = 0;
|
|
|
|
+ beendet = 0;
|
|
|
|
+ breakB = 0;
|
|
|
|
+ continueB = 0;
|
|
|
|
+ scrId = obj->getScriptId();
|
|
}
|
|
}
|
|
|
|
|
|
// Destruktor
|
|
// Destruktor
|
|
KSGSFunktionInstanz::~KSGSFunktionInstanz()
|
|
KSGSFunktionInstanz::~KSGSFunktionInstanz()
|
|
{
|
|
{
|
|
- lokaleVariablen->release();
|
|
|
|
- befehle->release();
|
|
|
|
- if( klasse )
|
|
|
|
- klasse->release();
|
|
|
|
- obj->release();
|
|
|
|
- if( threadVar )
|
|
|
|
- threadVar->release();
|
|
|
|
- if( retVar )
|
|
|
|
- retVar->release();
|
|
|
|
|
|
+ lokaleVariablen->release();
|
|
|
|
+ befehle->release();
|
|
|
|
+ if( klasse )
|
|
|
|
+ klasse->release();
|
|
|
|
+ obj->release();
|
|
|
|
+ if( threadVar )
|
|
|
|
+ threadVar->release();
|
|
|
|
+ if( retVar )
|
|
|
|
+ retVar->release();
|
|
}
|
|
}
|
|
|
|
|
|
// privat
|
|
// privat
|
|
@@ -56,264 +55,248 @@ void KSGSFunktionInstanz::unlock()
|
|
// nicht constant
|
|
// nicht constant
|
|
void KSGSFunktionInstanz::setParameter( Array< KSGSVariableDef* > *zDef, RCArray< KSGSVariable > *vars )
|
|
void KSGSFunktionInstanz::setParameter( Array< KSGSVariableDef* > *zDef, RCArray< KSGSVariable > *vars )
|
|
{
|
|
{
|
|
- int anz = zDef->getEintragAnzahl();
|
|
|
|
- for( int i = 0; i < anz; i++ )
|
|
|
|
- {
|
|
|
|
- int id = zDef->get( i )->id;
|
|
|
|
- if( vars->z( id ) )
|
|
|
|
- {
|
|
|
|
- if( zDef->get( i )->typId != vars->z( id )->getTyp() )
|
|
|
|
- {
|
|
|
|
- KSGSVariable *var = vars->z( id )->umwandelnIn( zDef->get( i )->typId );
|
|
|
|
- if( !var )
|
|
|
|
- lokaleVariablen->set( KSGSKlasseInstanz::erstellVariable( obj, zDef->get( i ) ), id );
|
|
|
|
- else
|
|
|
|
- lokaleVariablen->set( var, id );
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- lokaleVariablen->set( vars->get( id ), id );
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- lokaleVariablen->set( KSGSKlasseInstanz::erstellVariable( obj, zDef->get( i ) ), id );
|
|
|
|
- }
|
|
|
|
- vars->release();
|
|
|
|
|
|
+ int anz = zDef->getEintragAnzahl();
|
|
|
|
+ for( int i = 0; i < anz; i++ )
|
|
|
|
+ {
|
|
|
|
+ int id = zDef->get( i )->id;
|
|
|
|
+ if( vars->z( id ) )
|
|
|
|
+ {
|
|
|
|
+ if( zDef->get( i )->typId != vars->z( id )->getTyp() )
|
|
|
|
+ {
|
|
|
|
+ KSGSVariable *var = vars->z( id )->umwandelnIn( zDef->get( i )->typId );
|
|
|
|
+ if( !var )
|
|
|
|
+ lokaleVariablen->set( KSGSKlasseInstanz::erstellVariable( obj, zDef->get( i ) ), id );
|
|
|
|
+ else
|
|
|
|
+ lokaleVariablen->set( var, id );
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ lokaleVariablen->set( vars->get( id ), id );
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ lokaleVariablen->set( KSGSKlasseInstanz::erstellVariable( obj, zDef->get( i ) ), id );
|
|
|
|
+ }
|
|
|
|
+ vars->release();
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktionInstanz::setReturnVariable( KSGSVariable *var )
|
|
void KSGSFunktionInstanz::setReturnVariable( KSGSVariable *var )
|
|
{
|
|
{
|
|
- if( var->getTyp() != returnTyp )
|
|
|
|
- {
|
|
|
|
- error( 15, {}, obj );
|
|
|
|
- KSGSVariable *tmp = var->umwandelnIn( returnTyp );
|
|
|
|
- var->release();
|
|
|
|
- var = tmp;
|
|
|
|
- }
|
|
|
|
- lock();
|
|
|
|
- if( retVar )
|
|
|
|
- retVar->release();
|
|
|
|
- retVar = var;
|
|
|
|
- unlock();
|
|
|
|
|
|
+ if( var->getTyp() != returnTyp )
|
|
|
|
+ {
|
|
|
|
+ error( 15, {}, obj );
|
|
|
|
+ KSGSVariable *tmp = var->umwandelnIn( returnTyp );
|
|
|
|
+ var->release();
|
|
|
|
+ var = tmp;
|
|
|
|
+ }
|
|
|
|
+ lock();
|
|
|
|
+ if( retVar )
|
|
|
|
+ retVar->release();
|
|
|
|
+ retVar = var;
|
|
|
|
+ unlock();
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktionInstanz::setPause( bool p )
|
|
void KSGSFunktionInstanz::setPause( bool p )
|
|
{
|
|
{
|
|
- pausiert = p;
|
|
|
|
|
|
+ pausiert = p;
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktionInstanz::setContinue()
|
|
void KSGSFunktionInstanz::setContinue()
|
|
{
|
|
{
|
|
- continueB = 1;
|
|
|
|
|
|
+ continueB = 1;
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktionInstanz::setBreak()
|
|
void KSGSFunktionInstanz::setBreak()
|
|
{
|
|
{
|
|
- breakB = 0;
|
|
|
|
|
|
+ breakB = 0;
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktionInstanz::setEnde()
|
|
void KSGSFunktionInstanz::setEnde()
|
|
{
|
|
{
|
|
- beendet = 1;
|
|
|
|
|
|
+ beendet = 1;
|
|
}
|
|
}
|
|
|
|
|
|
KSGSVariable *KSGSFunktionInstanz::startFunktion()
|
|
KSGSVariable *KSGSFunktionInstanz::startFunktion()
|
|
{
|
|
{
|
|
- if( run )
|
|
|
|
- return 0;
|
|
|
|
- if( threadVar )
|
|
|
|
- threadVar = (KSGSThreadKlasse*)threadVar->release();
|
|
|
|
- if( retVar )
|
|
|
|
- retVar = retVar->release();
|
|
|
|
- if( returnTyp == KSGS_THREAD )
|
|
|
|
- {
|
|
|
|
- threadVar = new KSGSThreadKlasse( obj, getThis() );
|
|
|
|
- start();
|
|
|
|
- return threadVar->getThis();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- run = 1;
|
|
|
|
- thread();
|
|
|
|
- warteAufFunktion( INFINITE );
|
|
|
|
- return retVar ? retVar->getThis() : 0;
|
|
|
|
- }
|
|
|
|
|
|
+ if( run )
|
|
|
|
+ return 0;
|
|
|
|
+ if( threadVar )
|
|
|
|
+ threadVar = (KSGSThreadKlasse*)threadVar->release();
|
|
|
|
+ if( retVar )
|
|
|
|
+ retVar = retVar->release();
|
|
|
|
+ if( returnTyp == KSGS_THREAD )
|
|
|
|
+ {
|
|
|
|
+ threadVar = new KSGSThreadKlasse( obj, (KSGSFunktionInstanz*)getThis() );
|
|
|
|
+ start();
|
|
|
|
+ return threadVar->getThis();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ run = 1;
|
|
|
|
+ thread();
|
|
|
|
+ warteAufFunktion( INFINITE );
|
|
|
|
+ return retVar ? retVar->getThis() : 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktionInstanz::thread()
|
|
void KSGSFunktionInstanz::thread()
|
|
{
|
|
{
|
|
- getThis();
|
|
|
|
- int anz = befehle->getEintragAnzahl();
|
|
|
|
- for( int i = 0; i < anz; i++ )
|
|
|
|
- {
|
|
|
|
- while( pausiert && !beendet && !obj->istBeendet( scrId ) )
|
|
|
|
- Sleep( 100 );
|
|
|
|
- if( obj->istBeendet( scrId ) || beendet )
|
|
|
|
- break;
|
|
|
|
- KSGSBefehl *b = befehle->z( i );
|
|
|
|
- if( b )
|
|
|
|
- {
|
|
|
|
- KSGSVariable *var = b->ausführen( obj, this, klasse );
|
|
|
|
- if( var )
|
|
|
|
- var->release();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- run = 0;
|
|
|
|
- if( threadVar )
|
|
|
|
- {
|
|
|
|
- threadVar->threadEnde();
|
|
|
|
- threadVar = (KSGSThreadKlasse*)threadVar->release();
|
|
|
|
- }
|
|
|
|
- release();
|
|
|
|
|
|
+ getThis();
|
|
|
|
+ int anz = befehle->getEintragAnzahl();
|
|
|
|
+ for( int i = 0; i < anz; i++ )
|
|
|
|
+ {
|
|
|
|
+ while( pausiert && !beendet && !obj->istBeendet( scrId ) )
|
|
|
|
+ Sleep( 100 );
|
|
|
|
+ if( obj->istBeendet( scrId ) || beendet )
|
|
|
|
+ break;
|
|
|
|
+ KSGSBefehl *b = befehle->z( i );
|
|
|
|
+ if( b )
|
|
|
|
+ {
|
|
|
|
+ KSGSVariable *var = b->ausführen( obj, this, klasse );
|
|
|
|
+ if( var )
|
|
|
|
+ var->release();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ run = 0;
|
|
|
|
+ if( threadVar )
|
|
|
|
+ {
|
|
|
|
+ threadVar->threadEnde();
|
|
|
|
+ threadVar = (KSGSThreadKlasse*)threadVar->release();
|
|
|
|
+ }
|
|
|
|
+ release();
|
|
}
|
|
}
|
|
|
|
|
|
int KSGSFunktionInstanz::getStatus()
|
|
int KSGSFunktionInstanz::getStatus()
|
|
{
|
|
{
|
|
- if( !isRunning() || beendet )
|
|
|
|
- return 0;
|
|
|
|
- if( pausiert )
|
|
|
|
- return 1;
|
|
|
|
- if( breakB )
|
|
|
|
- {
|
|
|
|
- breakB = 0;
|
|
|
|
- return 2;
|
|
|
|
- }
|
|
|
|
- if( continueB )
|
|
|
|
- {
|
|
|
|
- continueB = 0;
|
|
|
|
- return 3;
|
|
|
|
- }
|
|
|
|
- return 4;
|
|
|
|
|
|
+ if( !isRunning() || beendet )
|
|
|
|
+ return 0;
|
|
|
|
+ if( pausiert )
|
|
|
|
+ return 1;
|
|
|
|
+ if( breakB )
|
|
|
|
+ {
|
|
|
|
+ breakB = 0;
|
|
|
|
+ return 2;
|
|
|
|
+ }
|
|
|
|
+ if( continueB )
|
|
|
|
+ {
|
|
|
|
+ continueB = 0;
|
|
|
|
+ return 3;
|
|
|
|
+ }
|
|
|
|
+ return 4;
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktionInstanz::setVariable( int id, KSGSVariable *var )
|
|
void KSGSFunktionInstanz::setVariable( int id, KSGSVariable *var )
|
|
{
|
|
{
|
|
- lokaleVariablen->set( var, id );
|
|
|
|
|
|
+ lokaleVariablen->set( var, id );
|
|
}
|
|
}
|
|
|
|
|
|
// constant
|
|
// constant
|
|
KSGSVariable *KSGSFunktionInstanz::getVariable( int id ) const
|
|
KSGSVariable *KSGSFunktionInstanz::getVariable( int id ) const
|
|
{
|
|
{
|
|
- return lokaleVariablen->get( id );
|
|
|
|
|
|
+ return lokaleVariablen->get( id );
|
|
}
|
|
}
|
|
|
|
|
|
int KSGSFunktionInstanz::getReturnTyp() const
|
|
int KSGSFunktionInstanz::getReturnTyp() const
|
|
{
|
|
{
|
|
- return returnTyp;
|
|
|
|
|
|
+ return returnTyp;
|
|
}
|
|
}
|
|
|
|
|
|
bool KSGSFunktionInstanz::wirdFunktionAusgeführt() const
|
|
bool KSGSFunktionInstanz::wirdFunktionAusgeführt() const
|
|
{
|
|
{
|
|
- return isRunning();
|
|
|
|
|
|
+ return isRunning();
|
|
}
|
|
}
|
|
|
|
|
|
int KSGSFunktionInstanz::warteAufFunktion( int zeit )
|
|
int KSGSFunktionInstanz::warteAufFunktion( int zeit )
|
|
{
|
|
{
|
|
- if( run )
|
|
|
|
- return warteAufThread( zeit );
|
|
|
|
- return 0;
|
|
|
|
|
|
+ if( run )
|
|
|
|
+ return warteAufThread( zeit );
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
bool KSGSFunktionInstanz::wirdAusgeführt() const
|
|
bool KSGSFunktionInstanz::wirdAusgeführt() const
|
|
{
|
|
{
|
|
- return isRunning() && !beendet && !pausiert;
|
|
|
|
|
|
+ return isRunning() && !beendet && !pausiert;
|
|
}
|
|
}
|
|
|
|
|
|
-// Reference Counting
|
|
|
|
-KSGSFunktionInstanz *KSGSFunktionInstanz::getThis()
|
|
|
|
-{
|
|
|
|
- ref++;
|
|
|
|
- return this;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-KSGSFunktionInstanz *KSGSFunktionInstanz::release()
|
|
|
|
-{
|
|
|
|
- ref--;
|
|
|
|
- if( !ref )
|
|
|
|
- delete this;
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// Inhalt der KSGSFunktion Klasse aus KSGSFunktion.h
|
|
// Inhalt der KSGSFunktion Klasse aus KSGSFunktion.h
|
|
// Konstruktor
|
|
// Konstruktor
|
|
KSGSFunktion::KSGSFunktion( int id, int sichtbar, int typ )
|
|
KSGSFunktion::KSGSFunktion( int id, int sichtbar, int typ )
|
|
- : typId( typ ),
|
|
|
|
- sichtbar( sichtbar ),
|
|
|
|
- id( id ),
|
|
|
|
- ref( 1 )
|
|
|
|
|
|
+ : typId( typ ),
|
|
|
|
+ sichtbar( sichtbar ),
|
|
|
|
+ id( id ),
|
|
|
|
+ ref( 1 )
|
|
{
|
|
{
|
|
- befehle = new RCArray< KSGSBefehl >();
|
|
|
|
- parameter = new Array< KSGSVariableDef* >();
|
|
|
|
- name = "";
|
|
|
|
|
|
+ befehle = new RCArray< KSGSBefehl >();
|
|
|
|
+ parameter = new Array< KSGSVariableDef* >();
|
|
|
|
+ name = "";
|
|
}
|
|
}
|
|
|
|
|
|
// Destruktor
|
|
// Destruktor
|
|
KSGSFunktion::~KSGSFunktion()
|
|
KSGSFunktion::~KSGSFunktion()
|
|
{
|
|
{
|
|
- if( befehle )
|
|
|
|
- befehle->release();
|
|
|
|
- int anz = parameter->getEintragAnzahl();
|
|
|
|
- for( int i = 0; i < anz; i++ )
|
|
|
|
- delete parameter->get( i );
|
|
|
|
- if( parameter )
|
|
|
|
- parameter->release();
|
|
|
|
|
|
+ if( befehle )
|
|
|
|
+ befehle->release();
|
|
|
|
+ int anz = parameter->getEintragAnzahl();
|
|
|
|
+ for( int i = 0; i < anz; i++ )
|
|
|
|
+ delete parameter->get( i );
|
|
|
|
+ if( parameter )
|
|
|
|
+ parameter->release();
|
|
}
|
|
}
|
|
|
|
|
|
// nicht constant
|
|
// nicht constant
|
|
void KSGSFunktion::setName( const char *txt )
|
|
void KSGSFunktion::setName( const char *txt )
|
|
{
|
|
{
|
|
- name = txt;
|
|
|
|
|
|
+ name = txt;
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktion::addParameter( KSGSVariableDef *var )
|
|
void KSGSFunktion::addParameter( KSGSVariableDef *var )
|
|
{
|
|
{
|
|
- parameter->add( var );
|
|
|
|
|
|
+ parameter->add( var );
|
|
}
|
|
}
|
|
|
|
|
|
void KSGSFunktion::addBefehl( KSGSBefehl *befehl )
|
|
void KSGSFunktion::addBefehl( KSGSBefehl *befehl )
|
|
{
|
|
{
|
|
- befehle->add( befehl );
|
|
|
|
|
|
+ befehle->add( befehl );
|
|
}
|
|
}
|
|
|
|
|
|
KSGSFunktionInstanz *KSGSFunktion::erstellInstanz( KSGScriptObj *obj, KSGSVariable *klasse, RCArray< KSGSVariable > *params )
|
|
KSGSFunktionInstanz *KSGSFunktion::erstellInstanz( KSGScriptObj *obj, KSGSVariable *klasse, RCArray< KSGSVariable > *params )
|
|
{
|
|
{
|
|
- KSGSFunktionInstanz *inst = new KSGSFunktionInstanz( befehle->getThis(), typId, obj, klasse );
|
|
|
|
- if( params )
|
|
|
|
- inst->setParameter( parameter, params );
|
|
|
|
- return inst;
|
|
|
|
|
|
+ KSGSFunktionInstanz *inst = new KSGSFunktionInstanz( befehle->getThis(), typId, obj, klasse );
|
|
|
|
+ if( params )
|
|
|
|
+ inst->setParameter( parameter, params );
|
|
|
|
+ return inst;
|
|
}
|
|
}
|
|
|
|
|
|
// constant
|
|
// constant
|
|
int KSGSFunktion::getId() const
|
|
int KSGSFunktion::getId() const
|
|
{
|
|
{
|
|
- return id;
|
|
|
|
|
|
+ return id;
|
|
}
|
|
}
|
|
|
|
|
|
int KSGSFunktion::getTypId() const
|
|
int KSGSFunktion::getTypId() const
|
|
{
|
|
{
|
|
- return typId;
|
|
|
|
|
|
+ return typId;
|
|
}
|
|
}
|
|
|
|
|
|
int KSGSFunktion::getSichtbarkeit() const
|
|
int KSGSFunktion::getSichtbarkeit() const
|
|
{
|
|
{
|
|
- return sichtbar;
|
|
|
|
|
|
+ return sichtbar;
|
|
}
|
|
}
|
|
|
|
|
|
bool KSGSFunktion::hatName( const char *txt ) const
|
|
bool KSGSFunktion::hatName( const char *txt ) const
|
|
{
|
|
{
|
|
- return name.istGleich( txt );
|
|
|
|
|
|
+ return name.istGleich( txt );
|
|
}
|
|
}
|
|
|
|
|
|
// Reference Counting
|
|
// Reference Counting
|
|
KSGSFunktion *KSGSFunktion::getThis()
|
|
KSGSFunktion *KSGSFunktion::getThis()
|
|
{
|
|
{
|
|
- ref++;
|
|
|
|
- return this;
|
|
|
|
|
|
+ ref++;
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
KSGSFunktion *KSGSFunktion::release()
|
|
KSGSFunktion *KSGSFunktion::release()
|
|
{
|
|
{
|
|
- ref--;
|
|
|
|
- if( !ref )
|
|
|
|
- delete this;
|
|
|
|
- return 0;
|
|
|
|
|
|
+ ref--;
|
|
|
|
+ if( !ref )
|
|
|
|
+ delete this;
|
|
|
|
+ return 0;
|
|
}
|
|
}
|