From 73fd00c3e123a6a7482f51a8d588a902cc7da75b Mon Sep 17 00:00:00 2001 From: Ko van der Sloot Date: Thu, 2 May 2024 12:54:32 +0200 Subject: [PATCH] code quality --- demos/sockettestServer.cxx | 2 +- include/timblserver/ClientBase.h | 8 ++++---- src/HttpServer.cxx | 6 +++--- src/JsonServer.cxx | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/demos/sockettestServer.cxx b/demos/sockettestServer.cxx index c5d8dff..1e817af 100644 --- a/demos/sockettestServer.cxx +++ b/demos/sockettestServer.cxx @@ -75,7 +75,7 @@ int randomSecs(){ } void *do_to_child( void *arg ){ - Sockets::Socket *mysock = (Sockets::Socket*)arg; + Sockets::Socket *mysock = static_cast(arg); // Greeting message for the client // // diff --git a/include/timblserver/ClientBase.h b/include/timblserver/ClientBase.h index f4ec807..47d5175 100644 --- a/include/timblserver/ClientBase.h +++ b/include/timblserver/ClientBase.h @@ -42,13 +42,13 @@ namespace TimblServer { bool connect( const std::string&, const std::string& ); const std::string& getBase( ) const { return _base; }; bool setBase( const std::string& ); - const std::set baseNames() const { return bases;}; + const std::set& baseNames() const { return bases;}; bool classify( const std::string& ); bool classifyFile( std::istream&, std::ostream& ); bool runScript( std::istream&, std::ostream& ); - std::string getClass() const { return Class; }; - std::string getDistance() const { return distance; }; - std::string getDistribution() const { return distribution; }; + const std::string& getClass() const { return Class; }; + const std::string& getDistance() const { return distance; }; + const std::string& getDistribution() const { return distribution; }; const std::vector& getNeighbors() const { return neighbors; }; private: bool extractBases( const std::string& ); diff --git a/src/HttpServer.cxx b/src/HttpServer.cxx index 3743665..b59af7c 100644 --- a/src/HttpServer.cxx +++ b/src/HttpServer.cxx @@ -83,7 +83,7 @@ void HttpServer::callback( childArgs *args ){ // report connection to the server terminal // args->socket()->setNonBlocking(); - map experiments = + map my_experiments = *(static_cast *>(callback_data())); string logLine = "Thread " + to_string( (uintptr_t)pthread_self() ) + " on Socket " + to_string( args->id() ); @@ -112,8 +112,8 @@ void HttpServer::callback( childArgs *args ){ epos = basename.find( "/" ); if ( epos != string::npos ){ basename = basename.substr( epos+1 ); - auto exp_it = experiments.find(basename); - if ( exp_it != experiments.end() ){ + auto exp_it = my_experiments.find(basename); + if ( exp_it != my_experiments.end() ){ TimblThread *client = new TimblThread( exp_it->second, args ); if ( client ){ TiCC::LogStream LS( &logstream() ); diff --git a/src/JsonServer.cxx b/src/JsonServer.cxx index 195dbb5..55542fd 100644 --- a/src/JsonServer.cxx +++ b/src/JsonServer.cxx @@ -96,16 +96,16 @@ void JsonServer::callback( childArgs *args ){ JsonServer *theServer = dynamic_cast( args->mother() ); int sockId = args->id(); TimblThread *client = 0; - map experiments = + map my_experiments = *(static_cast *>(callback_data())); int result = 0; json out_json; out_json["status"] = "ok"; - if ( experiments.size() == 1 - && experiments.find("default") != experiments.end() ){ + if ( my_experiments.size() == 1 + && my_experiments.find("default") != my_experiments.end() ){ DBG << "Before Create Default Client " << endl; - TimblExperiment *exp = experiments["default"]; + TimblExperiment *exp = my_experiments["default"]; client = new TimblThread( exp, args, true ); DBG << "After Create Client " << endl; // report connection to the server terminal @@ -113,7 +113,7 @@ void JsonServer::callback( childArgs *args ){ } else { json arr = json::array(); - for ( const auto& it : experiments ){ + for ( const auto& it : my_experiments ){ arr.push_back( it.first ); } out_json["available_bases"] = arr; @@ -166,8 +166,8 @@ void JsonServer::callback( childArgs *args ){ args->os() << err_json << endl; } else { - auto it = experiments.find(param); - if ( it != experiments.end() ){ + auto it = my_experiments.find(param); + if ( it != my_experiments.end() ){ // args->os() << "selected base: '" << Params << "'" << endl; if ( client ){ delete client;