From 49f612c06baea635590849cd3ac3f0f4401fc4be Mon Sep 17 00:00:00 2001
From: "m.marn" <m.marn@gsi.de>
Date: Fri, 31 Mar 2023 07:03:10 +0000
Subject: [PATCH] Remove "using namespace std" from headers

See merge request silecs/opensilecs!34
---
 .../interface/communication/MBConnection.cpp       |  2 +-
 .../interface/equipment/PLCRegister.cpp            |  4 ++--
 .../interface/equipment/SilecsCluster.cpp          |  2 +-
 .../interface/equipment/SilecsCluster.h            |  2 +-
 .../interface/equipment/SilecsPLC.cpp              |  2 +-
 .../interface/equipment/SilecsPLC.h                |  4 ++--
 .../interface/equipment/SilecsRegister.cpp         |  4 ++--
 .../interface/utility/Thread.h                     |  8 +++-----
 .../silecs-diagnostic/diagnostictoolmainview.cpp   |  6 +++---
 .../src/silecs-diagnostic/loginhandler.h           |  2 --
 .../src/silecs-diagnostic/silecsmodule.cpp         | 14 +++++++-------
 .../src/silecs-diagnostic/silecsmodule.h           |  2 +-
 12 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp
index a21bba4..cc457dd 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp
+++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp
@@ -195,7 +195,7 @@ int MBConnection::writeCoils(modbus_t *ctx, long start_addr, uint16_t count, uin
     // The src array must contain bytes set to TRUE or FALSE. We need one byte for each bit in data, e.g 2 bytes would require a 16 byte bool array 
     uint8_t src[count * 8];
     uint16_t bit_count;
-    string tmp;
+    std::string tmp;
 
     int i, k;
     int j = 0;
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp
index 239522f..321c36e 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/PLCRegister.cpp
@@ -542,7 +542,7 @@ void UnityRegister::importString(void* pBuffer, timeval ts)
     for (unsigned long i = 0; i < (dimension1_ * dimension2_); i++) // scalar has dim1=dim2=1
     {
         unsigned char* pData = & (pDataBase[i * step]);
-        size_t strSize = min((size_t)length_, strlen((const char*)pData));
+        size_t strSize = std::min((size_t)length_, strlen((const char*)pData));
         pRecvStringValue_[i]->assign((const char*)pData, strSize);
     }
     tod_ = ts;
@@ -569,7 +569,7 @@ void UnityRegister::exportString(void* pBuffer)
     for (unsigned long i = 0; i < dimension1_ * dimension2_; i++) // scalar has dim1=dim2=1
     { //Current size of the sent string should not exceed the register string max length
         size_t strSize = pSendStringValue_[i]->size();
-        std::string sendStringValue = pSendStringValue_[i]->substr(0, min((size_t)length_, strSize));
+        std::string sendStringValue = pSendStringValue_[i]->substr(0, std::min((size_t)length_, strSize));
         bzero((void *)& (pData[i * step]), step); //TwinCAT string requires '\0' terminator (mem-size of the string (~step) has been properly dimensioned in the mapping).
         memcpy((void *)& (pData[i * step]), (void *)sendStringValue.c_str(), sendStringValue.size());
     }
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp
index 66f4ec4..bf6218f 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp
@@ -150,7 +150,7 @@ std::string Cluster::getBlockList()
     return blockList;
 }
 
-PLC* Cluster::getPLC(std::string plcID, string parameterFile)
+PLC* Cluster::getPLC(std::string plcID, std::string parameterFile)
 {
     //getPLC() supports IP and host-name addressing, but both are required to register the PLC object:
     //Host-name will be used to manage related configuration documents.
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.h b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.h
index 386a304..6efddd5 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.h
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.h
@@ -124,7 +124,7 @@ public:
      * \param parameterFile optional parameterFile which should be used to configure this PLC
      * \return Reference of the PLC object
      */
-    PLC* getPLC(std::string plcID, string parameterFile = "");
+    PLC* getPLC(std::string plcID, std::string parameterFile = "");
 
     /*!
      * \brief Provides the list of the PLCs attached to the Cluster (using getPLC() method)
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp
index 01e0f6c..a221918 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp
@@ -39,7 +39,7 @@ Contributors:
 namespace Silecs
 {
 connMapType PLC::connMap_;
-PLC::PLC(Cluster* theCluster, std::string plcName, std::string plcIPaddr, string parameterFile) :
+PLC::PLC(Cluster* theCluster, std::string plcName, std::string plcIPaddr, std::string parameterFile) :
                 theCluster_(theCluster),
                 IPaddr_(plcIPaddr),
                 parameterFile_(parameterFile)
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h
index 0386fc3..118c039 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h
@@ -479,7 +479,7 @@ private:
     friend class CNVSendBlockMode;
     friend class CNVSendDeviceMode;
 
-    PLC(Cluster* theCluster, std::string plcName, std::string plcIPaddr, string parameterFile = "");
+    PLC(Cluster* theCluster, std::string plcName, std::string plcIPaddr, std::string parameterFile = "");
     virtual ~PLC();
 
     inline PLCType& getTypeID()
@@ -592,7 +592,7 @@ private:
     long baseAOAddr_;
     std::string usedMem_;
 
-    string parameterFile_;
+    std::string parameterFile_;
 
     // Unique instance of the Header Device for diagnostic purpose
     Device* theHeader_;
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp
index 4c66a67..a0d9022 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp
@@ -1597,7 +1597,7 @@ std::string Register::dumpInputVal(bool asAsciiChar)
             os << (char) ((unsigned char*)pRecvValue_)[i];
         }
         else
-            os << hex << (unsigned int) ((unsigned char*)pRecvValue_)[i] << " ";
+            os << std::hex << (unsigned int) ((unsigned char*)pRecvValue_)[i] << " ";
     }
     return os.str();
 }
@@ -1611,7 +1611,7 @@ std::string Register::dumpOutputVal(bool asAsciiChar)
         if (asAsciiChar)
             os << (char) ((unsigned char*)pSendValue_)[i];
         else
-            os << hex << (unsigned int) ((unsigned char*)pSendValue_)[i] << " ";
+            os << std::hex << (unsigned int) ((unsigned char*)pSendValue_)[i] << " ";
     }
     return os.str();
 }
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h b/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h
index 82b17c4..15718aa 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h
+++ b/silecs-communication-cpp/src/silecs-communication/interface/utility/Thread.h
@@ -15,6 +15,7 @@ Contributors:
 #define _THREAD_H_
 
 #include <iostream>
+#include <cstring>
 #include <string>
 #include <vector>
 #include <list>
@@ -24,13 +25,10 @@ Contributors:
 #include <pthread.h>
 #include <signal.h>
 #include <malloc.h>
-#include <string.h>
 
 #include <silecs-communication/interface/core/Context.h>
 #include <silecs-communication/interface/utility/Condition.h>
 
-using namespace std;
-
 namespace Silecs
 {
 class Context;
@@ -184,7 +182,7 @@ unsigned int Thread<UserDataType>::getPriority()
 
     if (pthread_getschedparam(*pTid_, &policy, &params) != 0)
     {
-        string errMsg(string("Cannot get dynamically schedparams: ") + strerror(errno));
+        std::string errMsg(std::string("Cannot get dynamically schedparams: ") + std::strerror(errno));
         throw errMsg;
     }
     return params.sched_priority;
@@ -202,7 +200,7 @@ void Thread<UserDataType>::setPriority(unsigned int rtprio)
         if (pthread_setschedparam(*pTid_, sched_getscheduler(getpid()), &params) == 0)
             return;
     }
-    string errMsg(string("Cannot set dynamically schedparams: ") + strerror(errno));
+    std::string errMsg(std::string("Cannot set dynamically schedparams: ") + std::strerror(errno));
     throw errMsg;
 }
 
diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp
index 03ae945..ceabd3a 100755
--- a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp
+++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp
@@ -156,7 +156,7 @@ void diagnosticToolMainView::loadFiles()
 
             std::string writeBlockList = cluster->getBlockList(AccessType::Command)+" "+cluster->getBlockList(AccessType::Setting);
 
-            istringstream blockListSplitted(writeBlockList);
+            std::istringstream blockListSplitted(writeBlockList);
             Utils::logInfo(ui->console, writeBlockList);
             do
             {
@@ -170,7 +170,7 @@ void diagnosticToolMainView::loadFiles()
 
             // Receive combo box
             std::string readBlockList = cluster->getBlockList(AccessType::Acquisition)+" "+cluster->getBlockList(AccessType::Setting);
-            istringstream blockListSplitted2(readBlockList);
+            std::istringstream blockListSplitted2(readBlockList);
             Utils::logInfo(ui->console,readBlockList);
             do
             {
@@ -184,7 +184,7 @@ void diagnosticToolMainView::loadFiles()
 
             // Send combo box
             std::string copyBlockList = cluster->getBlockList(AccessType::Setting);
-            istringstream blockListSplitted3(copyBlockList);
+            std::istringstream blockListSplitted3(copyBlockList);
             Utils::logInfo(ui->console, copyBlockList);
             do
             {
diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/loginhandler.h b/silecs-diagnostic-cpp/src/silecs-diagnostic/loginhandler.h
index 4824cef..c5fd44a 100755
--- a/silecs-diagnostic-cpp/src/silecs-diagnostic/loginhandler.h
+++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/loginhandler.h
@@ -24,8 +24,6 @@ Contributors:
     #include <cmw-rbac/AuthenticationFailure.h>
 #endif
 
-using namespace std;
-
 #ifdef WITH_RBAC
     extern std::string USER_NAME;
 
diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp
index 3ecf320..9b8d83a 100755
--- a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp
+++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp
@@ -102,7 +102,7 @@ void silecsModule::updatePLCRunState(Item *plcItem)
 
 }
 
-Item *silecsModule::generateTree(string className, string deployFile)
+Item *silecsModule::generateTree(const std::string& className, const std::string& deployFile)
 {
     Utils::logInfo(messageConsole_,"Loading deploy file: " + deployFile);
     XMLParser parserDeploy(deployFile,true);
@@ -116,7 +116,7 @@ Item *silecsModule::generateTree(string className, string deployFile)
     else
     {
         ElementXML silecsDesign = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/SilecsDesign[@silecs-design-name='" + className + "']");
-        string classVersion = silecsDesign.getAttribute("silecs-design-version");
+        std::string classVersion = silecsDesign.getAttribute("silecs-design-version");
         silecsCluster = silecsService->getCluster(className,classVersion);
         root->setText(0,QString::fromStdString(className+" v"+classVersion));
     }
@@ -124,15 +124,15 @@ Item *silecsModule::generateTree(string className, string deployFile)
     root->setLinkedObject(silecsCluster);
 
     ElementXML deployUnitNode = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Deploy-Unit");
-    string deployName = deployUnitNode.getAttribute("name");
+    std::string deployName = deployUnitNode.getAttribute("name");
     std::size_t deployFolderPos = deployFile.find(deployName);
-    string deployProjectPath = deployFile.substr(0,deployFolderPos) + deployName;
+    std::string deployProjectPath = deployFile.substr(0,deployFolderPos) + deployName;
     std::vector<ElementXML> controllerNodes = parserDeploy.getElementsFromXPath("/SILECS-Deploy/Controller");
     for(auto controllerIter = controllerNodes.begin(); controllerIter != controllerNodes.end(); controllerIter++)
     {
         std::string plcName = controllerIter->getAttribute("host-name");
         Silecs::PLC *plc;
-        string parameterFile = "";
+        std::string parameterFile = "";
         try
         {
             parameterFile = deployProjectPath + "/generated-silecs/client/" + plcName + ".silecsparam";
@@ -171,7 +171,7 @@ Item *silecsModule::generateTree(string className, string deployFile)
 
             // get register List for the current device
             std::string registerList = device->getRegisterList();
-            istringstream registerListSplitted(registerList);
+            std::istringstream registerListSplitted(registerList);
 
             do
             {
@@ -212,7 +212,7 @@ void silecsModule::setScalarDataInDeviceFromItem(Item *currentItem, std::string
     std::string deviceName = device->getLabel();
 
     std::string registerList = device->getRegisterList();
-    istringstream registerListSplitted(registerList);
+    std::istringstream registerListSplitted(registerList);
 
     int registerIndex = -1;
     do
diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h
index 85b0b99..59c5bbb 100755
--- a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h
+++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h
@@ -69,7 +69,7 @@ public:
     /**
       *Generate the empty entire tree
       */
-    Item *generateTree(string className, string deployFile);
+    Item *generateTree(const std::string& className, const std::string& deployFile);
 
     /**
       * Set the device with the proper scalar data converting
-- 
GitLab