Browse Source

An neues Framework angepasst

Kolja Strohm 5 years ago
parent
commit
dce707e3c3

+ 2 - 2
ksgScript/Befehl/KSGSKlasse.cpp

@@ -26,7 +26,7 @@ KSGSKlasseInstanz::KSGSKlasseInstanz( int typ, Array< KSGSVariableDef* > *zVars,
 	lokaleVariablen = new RCArray< KSGSVariable >();
 	varPublic = new Array< bool >();
 	funktionen = funcs;
-	obj = zObj->getThis();
+	obj = dynamic_cast<KSGScriptO *>( zObj->getThis() );
 	lokaleVariablen->add( getThis(), 0 );
 	varPublic->set( 0, 0 );
 	int anz = zVars ? zVars->getEintragAnzahl() : 0;
@@ -63,7 +63,7 @@ KSGSVariable *KSGSKlasseInstanz::startFunktion( int id, bool zugriff, RCArray< K
 		parameter->release();
 		return 0;
 	}
-	KSGSFunktionInstanz *inst = funktionen->z( id )->erstellInstanz( (KSGScriptO*)obj->getThis(), (KSGSKlasseInstanz*)getThis(), parameter );
+	KSGSFunktionInstanz *inst = funktionen->z( id )->erstellInstanz( dynamic_cast<KSGScriptO *>( obj->getThis() ), (KSGSKlasseInstanz*)getThis(), parameter );
 	KSGSVariable *ret = inst->startFunktion();
 	inst->release();
 	return ret;

+ 4 - 8
ksgScript/Editor/Editor.cpp

@@ -19,7 +19,6 @@ Editor::Editor()
     tickVal( 0 ),
     mausKlick( 0 )
 {
-    ref = 1;
     textRd = 0;
     script = 0;
     errorDetection = 1;
@@ -682,15 +681,12 @@ void Editor::setTextColor( int color, ColorType cType )
 }
 
 // Reference Counting
-KSGScriptEditor *Editor::getThis()
+Zeichnung *Editor::getThis()
 {
-    ref++;
-    return this;
+    return ZeichnungHintergrund::getThis();
 }
 
-KSGScriptEditor *Editor::release()
+Zeichnung *Editor::release()
 {
-    if( !--ref )
-        delete this;
-    return 0;
+    return ZeichnungHintergrund::release();
 }

+ 2 - 3
ksgScript/Editor/Editor.h

@@ -29,7 +29,6 @@ namespace KSGScript
         int begF;
         int colors[ COLOR_ANZAHL ];
         bool mausKlick;
-        int ref;
 
         void updateHScroll( int pos );
         void updateVScroll( int pos );
@@ -77,7 +76,7 @@ namespace KSGScript
         //  cType: Der Codetyp, der die Farbe bekommen soll
         void setTextColor( int color, ColorType cType ) override;
         // Reference Counting
-        KSGScriptEditor *getThis() override;
-        KSGScriptEditor *release() override;
+        Zeichnung *getThis() override;
+        Zeichnung *release() override;
     };
 }

+ 5 - 5
ksgScript/Include/KSGScript.h

@@ -74,7 +74,7 @@ namespace KSGScript
 	* Virtuelle Vordefinition der Klasse KSGScriptObj aus ../Main/KSGScriptObj.h
 	*/
 
-	class KSGScriptObj : public Framework::Zeichnung
+	class KSGScriptObj : virtual public Framework::Zeichnung
 	{
 	public:
 		// nicht constant
@@ -111,8 +111,8 @@ namespace KSGScript
 		virtual int getFunktionId( const char *name ) const = 0;
 		virtual KSGSVariable *getVariable( int id ) const = 0;
 		// Reference Counting
-		virtual KSGScriptObj *getThis() = 0;
-		virtual KSGScriptObj *release() = 0;
+		virtual Zeichnung *getThis() = 0;
+		virtual Zeichnung *release() = 0;
 	};
 
     // Ein Textfeld, das eine Entwicklungsumgebung für die KSG-Script Sprache darstellt
@@ -157,8 +157,8 @@ namespace KSGScript
         //  cType: Der Codetyp, der die Farbe bekommen soll
         virtual void setTextColor( int color, ColorType cType ) = 0;
         // Reference Counting
-        virtual KSGScriptEditor *getThis() = 0;
-        virtual KSGScriptEditor *release() = 0;
+        virtual Zeichnung *getThis() = 0;
+        virtual Zeichnung *release() = 0;
     };
 	// DLL Einstieg
     typedef KSGScriptEditor *( *KSGSGetEditor )( );

+ 1 - 1
ksgScript/Klassen/KSGSFenster.cpp

@@ -212,7 +212,7 @@ KSGSVariable *KSGSFensterKlasse::startFunktion( int id, bool access, RCArray< KS
                 error( 20, {}, obj );
             Zeichnung *obj = parameter->z( 0 ) ? parameter->z( 0 )->getZeichnung() : 0;
             if( obj )
-                val->addMember( obj );
+                val->addMember( obj->getThis() );
         }
         break;
     case 33: // void removeMember( Zeichnung )

+ 29 - 34
ksgScript/Main/KSGScriptObj.cpp

@@ -36,7 +36,6 @@ KSGScriptO::KSGScriptO()
     renderId = 0;
     geladen = 0;
     scrId = 0;
-    ref = 1;
     mausP = new RCArray< KSGSVariable >();
     tastaturP = new RCArray< KSGSVariable >();
     tickP = new RCArray< KSGSVariable >();
@@ -85,7 +84,7 @@ void KSGScriptO::setScriptDatei( const char *pfad )
         wd->setText( pfad, l );
 }
 
-void KSGScriptO::setScriptDatei( Text *pfad )
+void KSGScriptO::setScriptDatei( Text * pfad )
 {
     setScriptDatei( pfad->getText() );
     pfad->release();
@@ -99,8 +98,8 @@ bool KSGScriptO::neuLaden()
     if( geladen )
         zurücksetzen();
     scrId++;
-    KSGSLeser *reader = new KSGSLeser( *pfad, this );
-    ZeitMesser *zm = new ZeitMesser();
+    KSGSLeser * reader = new KSGSLeser( *pfad, this );
+    ZeitMesser * zm = new ZeitMesser();
     zm->messungStart();
     if( !reader->laden() )
     {
@@ -118,7 +117,7 @@ bool KSGScriptO::neuLaden()
         logNachricht( msg );
     }
     std::cout << "KSGS Reader: Zum lesen benötigte Sekunden: " << zm->getSekunden() << "\n";
-    Array< KSGSVariableDef* > *varDefs = new Array< KSGSVariableDef* >();
+    Array< KSGSVariableDef * > *varDefs = new Array< KSGSVariableDef * >();
     zm->messungStart();
     if( !reader->compile( klassen, funktionen, varDefs ) )
     {
@@ -163,7 +162,7 @@ bool KSGScriptO::neuLaden()
     {
         if( funktionen->z( i )->getId() == mainId )
         {
-            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( (KSGScriptO*)getThis(), 0, 0 );
+            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( dynamic_cast<KSGScriptO *>( getThis() ), 0, 0 );
             KSGSVariable *ret = inst->startFunktion();
             if( ret )
                 ret->release();
@@ -206,26 +205,26 @@ void KSGScriptO::setR
     rParam = p;
 }
 
-void KSGScriptO::setRückrufFunktion( void( *funktion )( void *, RCArray< KSGSVariable > *, KSGSVariable ** ) )
+void KSGScriptO::setRückrufFunktion( void( *funktion )( void *, RCArray< KSGSVariable > *, KSGSVariable * * ) )
 {
     rFunktion = funktion;
 }
 
-void KSGScriptO::setSchriftZ( Schrift *s )
+void KSGScriptO::setSchriftZ( Schrift * s )
 {
     if( schrift )
         schrift->release();
     schrift = s;
 }
 
-void KSGScriptO::setBildschirmZ( Bildschirm *s )
+void KSGScriptO::setBildschirmZ( Bildschirm * s )
 {
     if( screen )
         screen->release();
     screen = s;
 }
 
-void KSGScriptO::doMausEreignis( MausEreignis &me )
+void KSGScriptO::doMausEreignis( MausEreignis & me )
 {
     if( geladen != 2 )
         return;
@@ -237,8 +236,8 @@ void KSGScriptO::doMausEreignis( MausEreignis &me )
     {
         if( funktionen->z( i )->getId() == mausId )
         {
-            ( (KSGSMausEreignisKlasse*)mausP->z( 0 ) )->set( me );
-            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( (KSGScriptO*)getThis(), 0, mausP->getThis() );
+            ( (KSGSMausEreignisKlasse *)mausP->z( 0 ) )->set( me );
+            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( dynamic_cast<KSGScriptO *>( getThis() ), 0, mausP->getThis() );
             KSGSVariable *ret = inst->startFunktion();
             if( ret )
             {
@@ -256,7 +255,7 @@ void KSGScriptO::doMausEreignis( MausEreignis &me )
     unlock();
 }
 
-void KSGScriptO::doTastaturEreignis( TastaturEreignis &te )
+void KSGScriptO::doTastaturEreignis( TastaturEreignis & te )
 {
     if( geladen != 2 )
         return;
@@ -266,8 +265,8 @@ void KSGScriptO::doTastaturEreignis( TastaturEreignis &te )
     {
         if( funktionen->z( i )->getId() == tastaturId )
         {
-            ( (KSGSTastaturEreignisKlasse*)tastaturP->z( 0 ) )->set( te );
-            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( (KSGScriptO*)getThis(), 0, tastaturP->getThis() );
+            ( (KSGSTastaturEreignisKlasse *)tastaturP->z( 0 ) )->set( te );
+            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( dynamic_cast<KSGScriptO *>( getThis() ), 0, tastaturP->getThis() );
             KSGSVariable *ret = inst->startFunktion();
             if( ret )
             {
@@ -293,8 +292,8 @@ bool KSGScriptO::tick( double zeit )
     {
         if( funktionen->z( i )->getId() == tickId )
         {
-            ( (KSGSDoubleKlasse*)tickP->z( 0 ) )->set( zeit );
-            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( (KSGScriptO*)getThis(), 0, tickP->getThis() );
+            ( (KSGSDoubleKlasse *)tickP->z( 0 ) )->set( zeit );
+            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( dynamic_cast<KSGScriptO *>( getThis() ), 0, tickP->getThis() );
             KSGSVariable *ret = inst->startFunktion();
             bool r = 0;
             if( ret )
@@ -313,7 +312,7 @@ bool KSGScriptO::tick( double zeit )
     return 0;
 }
 
-void KSGScriptO::render( Bild &zRObj )
+void KSGScriptO::render( Bild & zRObj )
 {
     if( geladen != 2 )
         return;
@@ -328,8 +327,8 @@ void KSGScriptO::render( Bild &zRObj )
     {
         if( funktionen->z( i )->getId() == renderId )
         {
-            ( (KSGSBildKlasse*)renderP->z( 0 ) )->set( zRObj.getThis() );
-            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( (KSGScriptO*)getThis(), 0, renderP->getThis() );
+            ( (KSGSBildKlasse *)renderP->z( 0 ) )->set( zRObj.getThis() );
+            KSGSFunktionInstanz *inst = funktionen->z( i )->erstellInstanz( dynamic_cast<KSGScriptO *>( getThis() ), 0, renderP->getThis() );
             KSGSVariable *ret = inst->startFunktion();
             if( ret )
                 ret->release();
@@ -343,7 +342,7 @@ void KSGScriptO::render( Bild &zRObj )
     unlock();
 }
 
-KSGSVariable *KSGScriptO::startFunktion( int id, RCArray< KSGSVariable > *parameter )
+KSGSVariable *KSGScriptO::startFunktion( int id, RCArray< KSGSVariable > * parameter )
 {
     if( !funktionen || !funktionen->z( id ) || funktionen->z( id )->getSichtbarkeit() != 0 )
     {
@@ -351,7 +350,7 @@ KSGSVariable *KSGScriptO::startFunktion( int id, RCArray< KSGSVariable > *parame
         parameter->release();
         return 0;
     }
-    KSGSFunktionInstanz *inst = funktionen->z( id )->erstellInstanz( (KSGScriptO*)getThis(), 0, parameter );
+    KSGSFunktionInstanz *inst = funktionen->z( id )->erstellInstanz( dynamic_cast<KSGScriptO *>( getThis() ), 0, parameter );
     KSGSVariable *ret = inst->startFunktion();
     inst->release();
     return ret;
@@ -369,7 +368,7 @@ KSGSVariable *KSGScriptO::erstellKlassenInstanz( int id )
     return 0;
 }
 
-void KSGScriptO::setVariable( int id, KSGSVariable *var )
+void KSGScriptO::setVariable( int id, KSGSVariable * var )
 {
     variablen->set( var, id );
 }
@@ -387,7 +386,7 @@ Text *KSGScriptO::convertPfad( char *pf )
     return ret;
 }
 
-void KSGScriptO::setLog( TextFeld *log )
+void KSGScriptO::setLog( TextFeld * log )
 {
     lock();
     if( this->log )
@@ -407,7 +406,7 @@ void KSGScriptO::logNachricht( char *n )
 }
 
 // constant
-KSGSVariable *KSGScriptO::rückruf( RCArray< KSGSVariable > *parameter ) const
+KSGSVariable *KSGScriptO::rückruf( RCArray< KSGSVariable > * parameter ) const
 {
     if( !rFunktion )
     {
@@ -475,23 +474,19 @@ KSGSVariable *KSGScriptO::getVariable( int id ) const
 {
     if( !variablen || !variablen->z( id ) )
     {
-        error( 17, {}, ( KSGScriptO* )this );
+        error( 17, {}, (KSGScriptO *)this );
         return 0;
     }
     return variablen->get( id );
 }
 
 // Reference Counting
-KSGScriptObj *KSGScriptO::getThis()
+Zeichnung *KSGScriptO::getThis()
 {
-    ref++;
-    return this;
+    return Zeichnung::getThis();
 }
 
-KSGScriptObj *KSGScriptO::release()
+Zeichnung *KSGScriptO::release()
 {
-    ref--;
-    if( !ref )
-        delete this;
-    return 0;
+    return Zeichnung::release();
 }

+ 2 - 3
ksgScript/Main/KSGScriptObj.h

@@ -41,7 +41,6 @@ namespace KSGScript
 		int geladen;
 		int scrId;
 		Critical cs;
-		int ref;
 
 	public:
 		// Konstruktor
@@ -82,7 +81,7 @@ namespace KSGScript
 		virtual int getFunktionId( const char *name ) const override;
 		virtual KSGSVariable *getVariable( int id ) const override;
 		// Reference Counting
-		virtual KSGScriptObj *getThis() override;
-		virtual KSGScriptObj *release() override;
+		virtual Zeichnung *getThis() override;
+		virtual Zeichnung *release() override;
 	};
 }