From 432299c94bbe327bf25f2ee301bf2ed8d1b806c0 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Mon, 8 Sep 2014 15:43:22 +0200
Subject: [PATCH] Replace BaseLib::number2str with std::to_string.

Also remove the header StringTools.h everywhere.
Add a previously missing sstream include in DateTools.cpp.
---
 BaseLib/DateTools.cpp                                |  7 ++++---
 BaseLib/DateTools.h                                  |  1 -
 BaseLib/StringTools.h                                | 12 ------------
 FileIO/Legacy/OGSIOVer4.cpp                          |  3 +--
 FileIO/SHPInterface.cpp                              |  5 +----
 FileIO/XmlIO/Boost/BoostVtuInterface.cpp             |  7 +++----
 GeoLib/GEOObjects.cpp                                |  5 +----
 GeoLib/Grid.h                                        | 11 +++--------
 Gui/DataView/FEMConditionSetupDialog.cpp             |  5 ++---
 Gui/DataView/GEOModels.cpp                           | 10 ++++------
 Gui/mainwindow.cpp                                   |  3 +--
 MathLib/LinAlg/Dense/DenseMatrix-impl.h              |  8 ++++----
 MathLib/LinAlg/Dense/DenseMatrix.h                   |  3 ---
 .../MeshEditing/Mesh2MeshPropertyInterpolation.cpp   |  4 +---
 MeshLib/MeshQuality/MeshValidation.cpp               |  7 +++----
 OGS/ProjectData.cpp                                  |  5 +----
 Tests/GeoLib/TestGEOObjectsMerge.cpp                 |  7 ++-----
 Utils/FileConverter/ConvertSHPToGLI.cpp              |  3 +--
 .../createMeshElemPropertiesFromASCRaster.cpp        |  5 ++---
 19 files changed, 34 insertions(+), 77 deletions(-)

diff --git a/BaseLib/DateTools.cpp b/BaseLib/DateTools.cpp
index 9781efdf6ed..6f2b6e19c4b 100644
--- a/BaseLib/DateTools.cpp
+++ b/BaseLib/DateTools.cpp
@@ -17,6 +17,7 @@
 #include <cmath>
 #include <cstdlib>
 #include <iostream>
+#include <sstream>
 
 // ThirdParty/logog
 #include "logog/include/logog.hpp"
@@ -77,13 +78,13 @@ std::string date2string(double ddate)
 	if (d < 1 || d > 31)
 		WARN("date2String(): day not in [1:31].");
 
-	std::string day = BaseLib::number2str(d);
+	std::string day = std::to_string(d);
 	if (d < 10)
 		day = "0" + day;
-	std::string month = BaseLib::number2str(m);
+	std::string month = std::to_string(m);
 	if (m < 10)
 		month = "0" + month;
-	std::string s =  BaseLib::number2str(y) + "-" + month + "-" + day;
+	std::string s =  std::to_string(y) + "-" + month + "-" + day;
 	return s;
 }
 
diff --git a/BaseLib/DateTools.h b/BaseLib/DateTools.h
index 23cd6fb4bc2..655e9e4395e 100644
--- a/BaseLib/DateTools.h
+++ b/BaseLib/DateTools.h
@@ -15,7 +15,6 @@
 #ifndef DATETOOLS_H
 #define DATETOOLS_H
 
-#include "StringTools.h"
 #include <string>
 
 namespace BaseLib {
diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h
index dd4b7f9c382..1754f50d087 100644
--- a/BaseLib/StringTools.h
+++ b/BaseLib/StringTools.h
@@ -41,18 +41,6 @@ std::list<std::string> splitString(const std::string &str, char delim);
  */
 std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace);
 
-/**
- *   Converts a number (double, float, int, ...) into a string
- *  \param d The number to be converted
- *  \return The number as string
- */
-template<typename T> std::string number2str(T d)
-{
-	std::stringstream out;
-	out << d;
-	return out.str();
-}
-
 /**
  *   Converts a string into a number (double, float, int, ...)
  *  Example: std::size_t number (str2number<std::size_t> (str));
diff --git a/FileIO/Legacy/OGSIOVer4.cpp b/FileIO/Legacy/OGSIOVer4.cpp
index ba6064e6a85..d7de162b91c 100644
--- a/FileIO/Legacy/OGSIOVer4.cpp
+++ b/FileIO/Legacy/OGSIOVer4.cpp
@@ -25,7 +25,6 @@
 
 // BaseLib
 #include "FileTools.h"
-#include "StringTools.h"
 #include "quicksort.h"
 
 // GeoLib
@@ -717,7 +716,7 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects
 						os << "\t$NAME " << "\n" << "\t\t" << sfc_name << "\n";
 					} else {
 						os << "\t$NAME " << "\n" << "\t\t" << sfcs_cnt << "\n";
-					sfc_name = BaseLib::number2str (sfcs_cnt);
+					sfc_name = std::to_string (sfcs_cnt);
 				}
 				sfc_name += ".tin";
 				os << "\t$TIN" << "\n";
diff --git a/FileIO/SHPInterface.cpp b/FileIO/SHPInterface.cpp
index da25aef0365..04e6e73abb4 100644
--- a/FileIO/SHPInterface.cpp
+++ b/FileIO/SHPInterface.cpp
@@ -20,9 +20,6 @@
 
 #include "SHPInterface.h"
 
-// BaseLib
-#include "StringTools.h"
-
 // MathLib
 #include "AnalyticalGeometry.h"
 
@@ -101,7 +98,7 @@ void SHPInterface::readStations(const SHPHandle &hSHP, int numberOfElements, std
 
 		for (int i = 0; i < numberOfElements; i++) {
 			hSHPObject = SHPReadObject(hSHP, i);
-			GeoLib::Station* stn = GeoLib::Station::createStation(BaseLib::number2str(i),
+			GeoLib::Station* stn = GeoLib::Station::createStation(std::to_string(i),
 			                                                      *(hSHPObject->padfX),
 			                                                      *(hSHPObject->padfY),
 			                                                      *(hSHPObject->padfZ));
diff --git a/FileIO/XmlIO/Boost/BoostVtuInterface.cpp b/FileIO/XmlIO/Boost/BoostVtuInterface.cpp
index b913c0323fa..a3553fa425a 100644
--- a/FileIO/XmlIO/Boost/BoostVtuInterface.cpp
+++ b/FileIO/XmlIO/Boost/BoostVtuInterface.cpp
@@ -27,7 +27,6 @@
 #include "logog/include/logog.hpp"
 
 #include "FileTools.h"
-#include "StringTools.h"
 
 // MSH
 #include "Elements/Line.h"
@@ -462,8 +461,8 @@ void BoostVtuInterface::buildPropertyTree()
 		root_node.put("<xmlattr>.compressor", "vtkZLibDataCompressor");
 
 	ptree &piece_node = root_node.put("UnstructuredGrid.Piece", "");
-	const std::string str_nNodes (BaseLib::number2str(nNodes));
-	const std::string str_nElems (BaseLib::number2str(nElems));
+	const std::string str_nNodes (std::to_string(nNodes));
+	const std::string str_nElems (std::to_string(nElems));
 	piece_node.put("<xmlattr>.NumberOfPoints", str_nNodes.c_str());
 	piece_node.put("<xmlattr>.NumberOfCells", str_nElems.c_str());
 
@@ -567,7 +566,7 @@ void BoostVtuInterface::addDataArray(property_tree::ptree &parent_node, const st
 	dataarray_node.put("<xmlattr>.type", data_type.c_str());
 	dataarray_node.put("<xmlattr>.Name", name.c_str());
 	if (nComponents > 1)
-		dataarray_node.put("<xmlattr>.NumberOfComponents", BaseLib::number2str(nComponents).c_str());
+		dataarray_node.put("<xmlattr>.NumberOfComponents", std::to_string(nComponents).c_str());
 	std::string comp_type = (_use_compressor) ? "appended" : "ascii";
 	dataarray_node.put("<xmlattr>.format", comp_type.c_str());
 	// ---- offset attribute for compressed data! ----
diff --git a/GeoLib/GEOObjects.cpp b/GeoLib/GEOObjects.cpp
index 294bfbbf678..d3f55d808b6 100644
--- a/GeoLib/GEOObjects.cpp
+++ b/GeoLib/GEOObjects.cpp
@@ -20,9 +20,6 @@
 // GeoLib
 #include "GEOObjects.h"
 
-// BaseLib
-#include "StringTools.h"
-
 namespace GeoLib
 {
 GEOObjects::GEOObjects()
@@ -327,7 +324,7 @@ bool GEOObjects::isUniquePointVecName(std::string &name)
 		// If the original name already exists we start to add numbers to name for
 		// as long as it takes to make the name unique.
 		if (count > 1)
-			cpName = cpName + "-" + BaseLib::number2str(count);
+			cpName = cpName + "-" + std::to_string(count);
 
 		for (std::size_t i = 0; i < _pnt_vecs.size(); i++)
 			if ( cpName.compare(_pnt_vecs[i]->getName()) == 0 )
diff --git a/GeoLib/Grid.h b/GeoLib/Grid.h
index fb552c45e0e..286b61e2a96 100644
--- a/GeoLib/Grid.h
+++ b/GeoLib/Grid.h
@@ -24,11 +24,6 @@
 #include "AABB.h"
 #include "GEOObjects.h"
 
-#ifndef NDEBUG
-// BaseLib
-#include "StringTools.h"
-#endif
-
 // MathLib
 #include "MathTools.h"
 
@@ -452,11 +447,11 @@ void Grid<POINT>::createGridGeometry(GeoLib::GEOObjects* geo_obj) const
 			for (std::size_t k(0); k<_n_steps[2]; k++) {
 
 				std::string name("Grid-");
-				name += BaseLib::number2str<std::size_t>(i);
+				name += std::to_string(i);
 				name += "-";
-				name += BaseLib::number2str<std::size_t>(j);
+				name += std::to_string(j);
 				name += "-";
-				name += BaseLib::number2str<std::size_t> (k);
+				name += std::to_string (k);
 				grid_names.push_back(name);
 
 				std::vector<GeoLib::Point*>* points (new std::vector<GeoLib::Point*>);
diff --git a/Gui/DataView/FEMConditionSetupDialog.cpp b/Gui/DataView/FEMConditionSetupDialog.cpp
index aba1e7b99b7..7d1fbe17093 100644
--- a/Gui/DataView/FEMConditionSetupDialog.cpp
+++ b/Gui/DataView/FEMConditionSetupDialog.cpp
@@ -21,7 +21,6 @@
 #include "FEMEnums.h"
 #include "ProjectData.h"
 #include "StrictDoubleValidator.h"
-#include "StringTools.h"
 #include "LinearEditDialog.h"
 #include "CondFromRasterDialog.h"
 
@@ -340,7 +339,7 @@ void FEMConditionSetupDialog::copyCondOnPoints()
 			FEMCondition* cond = new FEMCondition(_cond);
 			cond->setGeoObj(nullptr);
 			cond->setGeoType(GeoLib::GEOTYPE::POINT);
-			cond->setGeoName(_cond.getAssociatedGeometryName() + "_Point" + BaseLib::number2str(ply->getPointID(i)));
+			cond->setGeoName(_cond.getAssociatedGeometryName() + "_Point" + std::to_string(ply->getPointID(i)));
 			cond->clearDisValues();
 			cond->setConstantDisValue((*ply->getPoint(i))[2]);
 			conditions.push_back(this->typeCast(*cond));
@@ -359,7 +358,7 @@ void FEMConditionSetupDialog::copyCondOnPoints()
 				FEMCondition* cond = new FEMCondition(_cond);
 				cond->setGeoObj(nullptr);
 				cond->setGeoType(GeoLib::GEOTYPE::POINT);
-				cond->setGeoName(_cond.getAssociatedGeometryName() + "_Point" + BaseLib::number2str((*tri)[j]));
+				cond->setGeoName(_cond.getAssociatedGeometryName() + "_Point" + std::to_string((*tri)[j]));
 				cond->clearDisValues();
 				cond->setConstantDisValue((*tri->getPoint(j))[2]);
 				conditions.push_back(this->typeCast(*cond));
diff --git a/Gui/DataView/GEOModels.cpp b/Gui/DataView/GEOModels.cpp
index a8a2fd75988..34ee2e2b640 100644
--- a/Gui/DataView/GEOModels.cpp
+++ b/Gui/DataView/GEOModels.cpp
@@ -21,8 +21,6 @@
 #include "GeoTreeModel.h"
 #include "StationTreeModel.h"
 
-#include "StringTools.h"
-
 #include "OGSError.h"
 
 GEOModels::GEOModels( QObject* parent /*= 0*/ ) :
@@ -282,7 +280,7 @@ void GEOModels::addNameForObjectPoints(const std::string &geometry_name,
 		for (std::size_t i = 0; i < nPoints; i++)
 			pnt_vec->setNameForElement(ply->getPointID(
 			                                   i), new_name + "_Point" +
-			                           BaseLib::number2str(ply->getPointID(i)));
+			                           std::to_string(ply->getPointID(i)));
 	}
 	else if (object_type == GeoLib::GEOTYPE::SURFACE)
 	{
@@ -293,13 +291,13 @@ void GEOModels::addNameForObjectPoints(const std::string &geometry_name,
 			const GeoLib::Triangle* tri = (*sfc)[i];
 			pnt_vec->setNameForElement((*tri)[0],
 			                           new_name + "_Point" +
-			                           BaseLib::number2str((*tri)[0]));
+			                           std::to_string((*tri)[0]));
 			pnt_vec->setNameForElement((*tri)[1],
 			                           new_name + "_Point" +
-			                           BaseLib::number2str((*tri)[1]));
+			                           std::to_string((*tri)[1]));
 			pnt_vec->setNameForElement((*tri)[2],
 			                           new_name + "_Point" +
-			                           BaseLib::number2str((*tri)[2]));
+			                           std::to_string((*tri)[2]));
 		}
 	}
 	else
diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp
index a17663d2ffb..611f095759b 100644
--- a/Gui/mainwindow.cpp
+++ b/Gui/mainwindow.cpp
@@ -83,7 +83,6 @@
 #include "XmlIO/Qt/XmlGspInterface.h"
 #include "XmlIO/Qt/XmlStnInterface.h"
 
-#include "StringTools.h"
 #include "LastSavedFileDirectory.h"
 
 // MeshLib
@@ -1342,7 +1341,7 @@ void MainWindow::on_actionExportVTK_triggered(bool checked /*= false*/)
 		{
 			count++;
 			static_cast<VtkVisPipelineItem*> (*it)->writeToFile(basename
-			                                                    + BaseLib::number2str(count));
+                                                    + std::to_string(count));
 			++it;
 		}
 	}
diff --git a/MathLib/LinAlg/Dense/DenseMatrix-impl.h b/MathLib/LinAlg/Dense/DenseMatrix-impl.h
index b97fd221a1c..ef710200a19 100644
--- a/MathLib/LinAlg/Dense/DenseMatrix-impl.h
+++ b/MathLib/LinAlg/Dense/DenseMatrix-impl.h
@@ -62,10 +62,10 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::operator=(DenseMatrix<FP_TYPE, IDX_TYPE> const&
 
 	if (_n_rows != rhs.getNRows() || _n_cols != rhs.getNCols()) {
 		std::string msg("DenseMatrix::operator=(DenseMatrix const& rhs), Dimension mismatch, ");
-		msg += " left hand side: " + BaseLib::number2str(_n_rows) + " x "
-				+ BaseLib::number2str(_n_cols);
-		msg += " right hand side: " + BaseLib::number2str(rhs.getNRows()) + " x "
-				+ BaseLib::number2str(rhs.getNCols());
+		msg += " left hand side: " + std::to_string(_n_rows) + " x "
+				+ std::to_string(_n_cols);
+		msg += " right hand side: " + std::to_string(rhs.getNRows()) + " x "
+				+ std::to_string(rhs.getNCols());
 		throw std::range_error(msg);
 		return *this;
 	}
diff --git a/MathLib/LinAlg/Dense/DenseMatrix.h b/MathLib/LinAlg/Dense/DenseMatrix.h
index 6d7fb3715c5..1cfabae56cb 100644
--- a/MathLib/LinAlg/Dense/DenseMatrix.h
+++ b/MathLib/LinAlg/Dense/DenseMatrix.h
@@ -20,9 +20,6 @@
 #include <stdexcept>
 #include <iostream>
 
-// BaseLib
-#include "StringTools.h"
-
 namespace MathLib {
 
 /**
diff --git a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp
index 058e1b608b9..281829ac3fc 100644
--- a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp
+++ b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp
@@ -17,9 +17,7 @@
 
 #include "Mesh2MeshPropertyInterpolation.h"
 
-// BaseLib
 #include "logog/include/logog.hpp"
-#include "StringTools.h"
 
 // GeoLib
 #include "AABB.h"
@@ -109,7 +107,7 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh(Mesh *dest_mes
 
 		if (cnt == 0) {
 			std::string base_name("DebugData/Element-");
-			base_name += BaseLib::number2str(k);
+			base_name += std::to_string(k);
 
 			std::string aabb_fname(base_name + "-aabb.gli");
 			std::ofstream out_aabb(aabb_fname.c_str());
diff --git a/MeshLib/MeshQuality/MeshValidation.cpp b/MeshLib/MeshQuality/MeshValidation.cpp
index bed91b85fff..3c5eb3402ea 100644
--- a/MeshLib/MeshQuality/MeshValidation.cpp
+++ b/MeshLib/MeshQuality/MeshValidation.cpp
@@ -18,7 +18,6 @@
 
 #include "logog/include/logog.hpp"
 
-#include "StringTools.h"
 #include "Mesh.h"
 #include "Node.h"
 #include "Elements/Element.h"
@@ -55,7 +54,7 @@ std::vector<std::size_t> MeshValidation::findUnusedMeshNodes(const MeshLib::Mesh
 			++count;
 		}
 
-	std::string nUnusedNodesStr = (count) ? BaseLib::number2str(count) : "No";
+	std::string nUnusedNodesStr = (count) ? std::to_string(count) : "No";
 	INFO ("%s unused mesh nodes found.", nUnusedNodesStr.c_str());
 	return del_node_idx;
 }
@@ -128,12 +127,12 @@ MeshValidation::ElementErrorCodeOutput(const std::vector<ElementErrorCode> &erro
 		{
 			if (error_codes[j][flags[i]])
 			{
-				elementIdStr += (BaseLib::number2str(j) + ", ");
+				elementIdStr += (std::to_string(j) + ", ");
 				count++;
 			}
 		
 		}
-		const std::string nErrorsStr = (count) ? BaseLib::number2str(count) : "No";
+		const std::string nErrorsStr = (count) ? std::to_string(count) : "No";
 		output[i] = (nErrorsStr + " elements found with " + ElementErrorCode::toString(flags[i]) + ".\n");
 
 		if (count)
diff --git a/OGS/ProjectData.cpp b/OGS/ProjectData.cpp
index 41a02995fa7..f2714b0fc58 100644
--- a/OGS/ProjectData.cpp
+++ b/OGS/ProjectData.cpp
@@ -14,9 +14,6 @@
 
 #include "ProjectData.h"
 
-// BaseLib
-#include "StringTools.h"
-
 #include "Mesh.h"
 
 ProjectData::ProjectData()
@@ -221,7 +218,7 @@ bool ProjectData::isUniqueMeshName(std::string &name)
 		// If the original name already exists we start to add numbers to name for
 		// as long as it takes to make the name unique.
 		if (count > 1)
-			cpName = cpName + "-" + BaseLib::number2str(count);
+			cpName = cpName + "-" + std::to_string(count);
 
 		for (std::vector<MeshLib::Mesh*>::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it)
 			if ( cpName.compare((*it)->getName()) == 0 )
diff --git a/Tests/GeoLib/TestGEOObjectsMerge.cpp b/Tests/GeoLib/TestGEOObjectsMerge.cpp
index 6210af4696c..29cc37fb3f8 100644
--- a/Tests/GeoLib/TestGEOObjectsMerge.cpp
+++ b/Tests/GeoLib/TestGEOObjectsMerge.cpp
@@ -19,9 +19,6 @@
 #include <map>
 #include <string>
 
-// BaseLib
-#include "StringTools.h"
-
 // GeoLib
 #include "GEOObjects.h"
 
@@ -38,8 +35,8 @@ void createSetOfTestPointsAndAssociatedNames(GeoLib::GEOObjects & geo_objs, std:
 			for (std::size_t i(0); i < pnts_per_edge; i++) {
 				pnts->push_back(new GeoLib::Point(i+shift[0], j+shift[1], k+shift[2]));
 				std::string pnt_name(
-						name + "-" + BaseLib::number2str(i) + "-" + BaseLib::number2str(j) + "-"
-								+ BaseLib::number2str(k));
+						name + "-" + std::to_string(i) + "-" + std::to_string(j) + "-"
+								+ std::to_string(k));
 				pnt_name_map->insert(std::pair< std::string, std::size_t>(pnt_name, i + offset));
 			}
 		}
diff --git a/Utils/FileConverter/ConvertSHPToGLI.cpp b/Utils/FileConverter/ConvertSHPToGLI.cpp
index 6bde561bb43..36975243de1 100644
--- a/Utils/FileConverter/ConvertSHPToGLI.cpp
+++ b/Utils/FileConverter/ConvertSHPToGLI.cpp
@@ -28,7 +28,6 @@
 
 // BaseLib
 #include "LogogSimpleFormatter.h"
-#include "StringTools.h"
 
 // FileIO
 #include "XmlIO/Qt/XmlGmlInterface.h"
@@ -71,7 +70,7 @@ void convertPoints (DBFHandle dbf_handle,
 				}
 		}
 		else
-			name = BaseLib::number2str(k);
+			name = std::to_string(k);
 
 		if (station) {
 			GeoLib::Station* pnt(GeoLib::Station::createStation(name, x, y, z));
diff --git a/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp b/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp
index 6e7018a4c9f..557d506b6cb 100644
--- a/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp
+++ b/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp
@@ -23,7 +23,6 @@
 
 // BaseLib
 #include "LogogSimpleFormatter.h"
-#include "StringTools.h"
 #include "quicksort.h"
 
 // FileIO/Legacy
@@ -121,8 +120,8 @@ int main (int argc, char* argv[])
 			// write new asc file
 			std::string new_raster_fname (BaseLib::dropFileExtension(
 			                                      raster_arg.getValue()));
-			new_raster_fname += "-" + BaseLib::number2str(raster->getNRows()) + "x" +
-			                    BaseLib::number2str(raster->getNCols()) + ".asc";
+			new_raster_fname += "-" + std::to_string(raster->getNRows()) + "x" +
+			                    std::to_string(raster->getNCols()) + ".asc";
 			std::ofstream out(new_raster_fname);
 			raster->writeRasterAsASC(out);
 			out.close();
-- 
GitLab