Browse Source

fix array usages

Kolja Strohm 3 years ago
parent
commit
e73c1a3ed3
3 changed files with 8 additions and 14 deletions
  1. 5 10
      EditorServer/EditorServer.cpp
  2. 0 1
      EditorServer/EditorServer.h
  3. 3 3
      EditorServer/KarteEditor.cpp

+ 5 - 10
EditorServer/EditorServer.cpp

@@ -11,7 +11,6 @@ EditorServer::EditorServer( InitDatei *zIni )
     Network::Start( 100 );
     std::cout << "EdS: Verbindung mit Datenbank wird hergestellt...\n";
     db = new EdSDatenbank( zIni );
-    klientAnzahl = 0;
     klients = new RCArray< EdSKlient >();
     empfangen = 0;
     gesendet = 0;
@@ -87,8 +86,7 @@ void EditorServer::thread()
         Framework::getThreadRegister()->cleanUpClosedThreads();
         EdSKlient *clHandle = new EdSKlient( klient, dynamic_cast<EditorServer *>( getThis() ) );
         EnterCriticalSection( &cs );
-        klients->set( clHandle, klientAnzahl );
-        klientAnzahl++;
+        klients->add( clHandle );
         LeaveCriticalSection( &cs );
         clHandle->start();
     }
@@ -102,10 +100,9 @@ void EditorServer::close()
     warteAufThread( 1000 );
 #endif
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
+    for( int i = 0; i < klients->getEintragAnzahl(); i++ )
         klients->z( i )->absturz();
     klients = ( RCArray<EdSKlient>* )klients->release();
-    klientAnzahl = 0;
     LeaveCriticalSection( &cs );
     ende();
     run = 0;
@@ -208,13 +205,12 @@ bool EditorServer::absturzKlient( int klientId )
 {
     bool gefunden = 0;
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
+    for( int i = 0; i < klients->getEintragAnzahl(); i++ )
     {
         if( klients->z( i )->getKlientNummer() == klientId )
         {
             klients->z( i )->absturz();
             klients->remove( i );
-            klientAnzahl--;
             gefunden = 1;
             break;
         }
@@ -227,12 +223,11 @@ bool EditorServer::removeKlient( EdSKlient *zKlient )
 {
     bool gefunden = 0;
     EnterCriticalSection( &cs );
-    for( int i = 0; i < klientAnzahl; i++ )
+    for( int i = 0; i < klients->getEintragAnzahl(); i++ )
     {
         if( klients->z( i ) == zKlient )
         {
             klients->remove( i );
-            klientAnzahl--;
             gefunden = 1;
             break;
         }
@@ -274,7 +269,7 @@ InitDatei *EditorServer::zIni() const
 
 bool EditorServer::hatClients() const
 {
-    return klientAnzahl > 0;
+    return klients->hat(0);
 }
 
 int EditorServer::getId() const

+ 0 - 1
EditorServer/EditorServer.h

@@ -24,7 +24,6 @@ private:
 	CRITICAL_SECTION cs;
 	RCArray< EdSKlient > *klients;
 	Text *fehler;
-	int klientAnzahl;
 	int id;
 	bool nichtPausiert;
 	int empfangen;

+ 3 - 3
EditorServer/KarteEditor.cpp

@@ -170,8 +170,8 @@ bool KarteEditor::getAbbildListe( RCArray< Text > *name, RCArray< Zeit > *datum
         Zeit *z = d.getLastChange();
         if( z )
         {
-            name->set( list->get( i ), i );
-            datum->set( z, i );
+            name->add( list->get( i ) );
+            datum->add( z );
         }
     }
     list->release();
@@ -189,7 +189,7 @@ int KarteEditor::getDateiUpdateListe( char *p, RCArray< Text > *pfad )
     for( int i = 0; i < anz; i++ )
     {
         list->z( i )->remove( pf.getText() );
-        pfad->set( list->get( i ), i );
+        pfad->add( list->get( i ) );
     }
     list->release();
     return anz;