From 1e8cc4b7f168ccf9c85e4359d5c5c602cd28bba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 15 Dec 2018 23:01:44 +0100 Subject: [PATCH 1/2] Removed templated String constructor fixes #18 --- src/Benchmarks/BLAS/tnl-benchmark-blas.h | 8 ++-- src/Benchmarks/Benchmarks.h | 38 +++++++++---------- .../DistSpMV/tnl-benchmark-distributed-spmv.h | 10 ++--- src/Benchmarks/HeatEquation/tnlTestGrid2D.h | 20 +++++----- .../tnl-benchmark-linear-solvers.h | 16 ++++---- src/Examples/StringExample.cpp | 4 +- .../transportEquationProblemEoc_impl.h | 2 +- src/Python/pytnl/tnl/String.cpp | 4 +- src/TNL/Containers/MultiVector1D_impl.h | 2 +- src/TNL/Containers/MultiVector2D_impl.h | 2 +- src/TNL/Containers/MultiVector3D_impl.h | 2 +- src/TNL/Containers/MultiVector4D_impl.h | 2 +- src/TNL/Containers/StaticArray1D_impl.h | 2 +- src/TNL/Containers/StaticArray2D_impl.h | 2 +- src/TNL/Containers/StaticArray3D_impl.h | 2 +- src/TNL/Containers/StaticArray_impl.h | 2 +- src/TNL/Containers/StaticVector1D_impl.h | 2 +- src/TNL/Containers/StaticVector2D_impl.h | 4 +- src/TNL/Containers/StaticVector3D_impl.h | 4 +- src/TNL/Containers/StaticVector_impl.h | 4 +- src/TNL/Devices/CudaDeviceInfo.cu | 4 +- src/TNL/Devices/SystemInfo.cpp | 14 +++---- src/TNL/Functions/MeshFunction_impl.h | 4 +- src/TNL/Functions/VectorField.h | 12 +++--- src/TNL/Meshes/DefaultConfig.h | 2 +- src/TNL/Meshes/GridDetails/Grid1D_impl.h | 2 +- src/TNL/Meshes/GridDetails/Grid2D_impl.h | 2 +- src/TNL/Meshes/GridDetails/Grid3D_impl.h | 2 +- src/TNL/String.cpp | 4 +- src/TNL/String.h | 13 ------- src/UnitTests/Containers/ListTest.cpp | 31 ++++++++++++++- src/UnitTests/StringTest.cpp | 10 ++--- 32 files changed, 124 insertions(+), 108 deletions(-) diff --git a/src/Benchmarks/BLAS/tnl-benchmark-blas.h b/src/Benchmarks/BLAS/tnl-benchmark-blas.h index 3472dd6f6..390b17279 100644 --- a/src/Benchmarks/BLAS/tnl-benchmark-blas.h +++ b/src/Benchmarks/BLAS/tnl-benchmark-blas.h @@ -42,7 +42,7 @@ runBlasBenchmarks( Benchmark & benchmark, metadata ); for( std::size_t size = minSize; size <= maxSize; size *= 2 ) { benchmark.setMetadataColumns( Benchmark::MetadataColumns({ - {"size", convertToString( size ) }, + { "size", convertToString( size ) }, } )); benchmarkArrayOperations< Real >( benchmark, size ); } @@ -62,9 +62,9 @@ runBlasBenchmarks( Benchmark & benchmark, metadata ); for( std::size_t size = minSize; size <= maxSize; size *= 2 ) { benchmark.setMetadataColumns( Benchmark::MetadataColumns({ - {"rows", convertToString( size ) }, - {"columns", convertToString( size ) }, - {"elements per row", convertToString( elementsPerRow ) }, + { "rows", convertToString( size ) }, + { "columns", convertToString( size ) }, + { "elements per row", convertToString( elementsPerRow ) }, } )); benchmarkSpmvSynthetic< Real >( benchmark, size, elementsPerRow ); } diff --git a/src/Benchmarks/Benchmarks.h b/src/Benchmarks/Benchmarks.h index ceb6b9c7e..559e27ee2 100644 --- a/src/Benchmarks/Benchmarks.h +++ b/src/Benchmarks/Benchmarks.h @@ -339,7 +339,7 @@ public: closeTable(); writeTitle( title ); // add loops to metadata - metadata["loops"] = String(loops); + metadata["loops"] = convertToString(loops); writeMetadata( metadata ); } @@ -488,14 +488,14 @@ Benchmark::MetadataMap getHardwareMetadata() { const int cpu_id = 0; Devices::CacheSizes cacheSizes = Devices::SystemInfo::getCPUCacheSizes( cpu_id ); - String cacheInfo = String( cacheSizes.L1data ) + ", " - + String( cacheSizes.L1instruction ) + ", " - + String( cacheSizes.L2 ) + ", " - + String( cacheSizes.L3 ); + String cacheInfo = convertToString( cacheSizes.L1data ) + ", " + + convertToString( cacheSizes.L1instruction ) + ", " + + convertToString( cacheSizes.L2 ) + ", " + + convertToString( cacheSizes.L3 ); #ifdef HAVE_CUDA const int activeGPU = Devices::CudaDeviceInfo::getActiveDevice(); - const String deviceArch = String( Devices::CudaDeviceInfo::getArchitectureMajor( activeGPU ) ) + "." + - String( Devices::CudaDeviceInfo::getArchitectureMinor( activeGPU ) ); + const String deviceArch = convertToString( Devices::CudaDeviceInfo::getArchitectureMajor( activeGPU ) ) + "." + + convertToString( Devices::CudaDeviceInfo::getArchitectureMinor( activeGPU ) ); #endif Benchmark::MetadataMap metadata { { "host name", Devices::SystemInfo::getHostname() }, @@ -504,25 +504,25 @@ Benchmark::MetadataMap getHardwareMetadata() { "system release", Devices::SystemInfo::getSystemRelease() }, { "start time", Devices::SystemInfo::getCurrentTime() }, #ifdef HAVE_MPI - { "number of MPI processes", String( (Communicators::MpiCommunicator::IsInitialized()) + { "number of MPI processes", convertToString( (Communicators::MpiCommunicator::IsInitialized()) ? Communicators::MpiCommunicator::GetSize( Communicators::MpiCommunicator::AllGroup ) : 1 ) }, #endif - { "OpenMP enabled", String( Devices::Host::isOMPEnabled() ) }, - { "OpenMP threads", String( Devices::Host::getMaxThreadsCount() ) }, + { "OpenMP enabled", convertToString( Devices::Host::isOMPEnabled() ) }, + { "OpenMP threads", convertToString( Devices::Host::getMaxThreadsCount() ) }, { "CPU model name", Devices::SystemInfo::getCPUModelName( cpu_id ) }, - { "CPU cores", String( Devices::SystemInfo::getNumberOfCores( cpu_id ) ) }, - { "CPU threads per core", String( Devices::SystemInfo::getNumberOfThreads( cpu_id ) / Devices::SystemInfo::getNumberOfCores( cpu_id ) ) }, - { "CPU max frequency (MHz)", String( Devices::SystemInfo::getCPUMaxFrequency( cpu_id ) / 1e3 ) }, + { "CPU cores", convertToString( Devices::SystemInfo::getNumberOfCores( cpu_id ) ) }, + { "CPU threads per core", convertToString( Devices::SystemInfo::getNumberOfThreads( cpu_id ) / Devices::SystemInfo::getNumberOfCores( cpu_id ) ) }, + { "CPU max frequency (MHz)", convertToString( Devices::SystemInfo::getCPUMaxFrequency( cpu_id ) / 1e3 ) }, { "CPU cache sizes (L1d, L1i, L2, L3) (kiB)", cacheInfo }, #ifdef HAVE_CUDA { "GPU name", Devices::CudaDeviceInfo::getDeviceName( activeGPU ) }, - { "GPU architecture", String( deviceArch ) }, - { "GPU CUDA cores", String( Devices::CudaDeviceInfo::getCudaCores( activeGPU ) ) }, - { "GPU clock rate (MHz)", String( (double) Devices::CudaDeviceInfo::getClockRate( activeGPU ) / 1e3 ) }, - { "GPU global memory (GB)", String( (double) Devices::CudaDeviceInfo::getGlobalMemory( activeGPU ) / 1e9 ) }, - { "GPU memory clock rate (MHz)", String( (double) Devices::CudaDeviceInfo::getMemoryClockRate( activeGPU ) / 1e3 ) }, - { "GPU memory ECC enabled", String( Devices::CudaDeviceInfo::getECCEnabled( activeGPU ) ) }, + { "GPU architecture", deviceArch }, + { "GPU CUDA cores", convertToString( Devices::CudaDeviceInfo::getCudaCores( activeGPU ) ) }, + { "GPU clock rate (MHz)", convertToString( (double) Devices::CudaDeviceInfo::getClockRate( activeGPU ) / 1e3 ) }, + { "GPU global memory (GB)", convertToString( (double) Devices::CudaDeviceInfo::getGlobalMemory( activeGPU ) / 1e9 ) }, + { "GPU memory clock rate (MHz)", convertToString( (double) Devices::CudaDeviceInfo::getMemoryClockRate( activeGPU ) / 1e3 ) }, + { "GPU memory ECC enabled", convertToString( Devices::CudaDeviceInfo::getECCEnabled( activeGPU ) ) }, #endif }; diff --git a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h index ecc001d66..738fda056 100644 --- a/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h +++ b/src/Benchmarks/DistSpMV/tnl-benchmark-distributed-spmv.h @@ -176,12 +176,12 @@ struct SpmvBenchmark benchmark.newBenchmark( name, metadata ); benchmark.setMetadataColumns( Benchmark::MetadataColumns({ // TODO: strip the device -// {"matrix type", matrix.getType()}, - {"rows", String( matrix.getRows() ) }, - {"columns", String( matrix.getColumns() ) }, +// { "matrix type", matrix.getType() }, + { "rows", convertToString( matrix.getRows() ) }, + { "columns", convertToString( matrix.getColumns() ) }, // FIXME: getMaxRowLengths() returns 0 for matrices loaded from file -// {"max elements per row", matrix.getMaxRowLength()}, - {"max elements per row", String( maxRowLength ) }, +// { "max elements per row", matrix.getMaxRowLength() }, + { "max elements per row", convertToString( maxRowLength ) }, } )); const bool reorder = parameters.getParameter< bool >( "reorder-dofs" ); diff --git a/src/Benchmarks/HeatEquation/tnlTestGrid2D.h b/src/Benchmarks/HeatEquation/tnlTestGrid2D.h index afe284ad7..084d6cc39 100644 --- a/src/Benchmarks/HeatEquation/tnlTestGrid2D.h +++ b/src/Benchmarks/HeatEquation/tnlTestGrid2D.h @@ -214,11 +214,11 @@ template< typename Real, typename Index > String Meshes::Grid< 2, Real, Device, Index > :: getType() { - return TNL::String( "Meshes::Grid< " ) + - TNL::String( getMeshDimension() ) + ", " + - TNL::String( ::getType< RealType >() ) + ", " + - TNL::String( Device :: getDeviceType() ) + ", " + - TNL::String( ::getType< IndexType >() ) + " >"; + return String( "Meshes::Grid< " ) + + convertToString( getMeshDimension() ) + ", " + + String( ::getType< RealType >() ) + ", " + + String( Device :: getDeviceType() ) + ", " + + String( ::getType< IndexType >() ) + " >"; } template< typename Real, @@ -979,11 +979,11 @@ template< typename Real, typename Index > String Meshes::Grid< 2, Real, Device, Index > :: getType() { - return TNL::String( "Meshes::Grid< " ) + - TNL::String( getMeshDimension() ) + ", " + - TNL::String( ::getType< RealType >() ) + ", " + - TNL::String( Device :: getDeviceType() ) + ", " + - TNL::String( ::getType< IndexType >() ) + " >"; + return String( "Meshes::Grid< " ) + + convertToString( getMeshDimension() ) + ", " + + String( ::getType< RealType >() ) + ", " + + String( Device :: getDeviceType() ) + ", " + + String( ::getType< IndexType >() ) + " >"; } template< typename Real, diff --git a/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h index c31f776cd..ce8d49ae0 100644 --- a/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h +++ b/src/Benchmarks/LinearSolvers/tnl-benchmark-linear-solvers.h @@ -188,7 +188,7 @@ benchmarkIterativeSolvers( Benchmark& benchmark, benchmark.setOperation("BiCGstab (Jacobi)"); for( int ell = 1; ell <= ell_max; ell++ ) { parameters.template setParameter< int >( "bicgstab-ell", ell ); - benchmark.setOperation("BiCGstab(" + String(ell) + ") (Jacobi)"); + benchmark.setOperation("BiCGstab(" + convertToString(ell) + ") (Jacobi)"); benchmarkSolver< BICGStabL, Diagonal >( benchmark, parameters, matrixPointer, x0, b ); #ifdef HAVE_CUDA benchmarkSolver< BICGStabL, Diagonal >( benchmark, parameters, cudaMatrixPointer, cuda_x0, cuda_b ); @@ -244,7 +244,7 @@ benchmarkIterativeSolvers( Benchmark& benchmark, if( solvers.count( "bicgstab-ell" ) ) { for( int ell = 1; ell <= ell_max; ell++ ) { parameters.template setParameter< int >( "bicgstab-ell", ell ); - benchmark.setOperation("BiCGstab(" + String(ell) + ") (ILU0)"); + benchmark.setOperation("BiCGstab(" + convertToString(ell) + ") (ILU0)"); benchmarkSolver< BICGStabL, ILU0 >( benchmark, parameters, matrixPointer, x0, b ); #ifdef HAVE_CUDA benchmarkSolver< BICGStabL, ILU0 >( benchmark, parameters, cudaMatrixPointer, cuda_x0, cuda_b ); @@ -300,7 +300,7 @@ benchmarkIterativeSolvers( Benchmark& benchmark, if( solvers.count( "bicgstab-ell" ) ) { for( int ell = 1; ell <= ell_max; ell++ ) { parameters.template setParameter< int >( "bicgstab-ell", ell ); - benchmark.setOperation("BiCGstab(" + String(ell) + ") (ILUT)"); + benchmark.setOperation("BiCGstab(" + convertToString(ell) + ") (ILUT)"); benchmarkSolver< BICGStabL, ILUT >( benchmark, parameters, matrixPointer, x0, b ); #ifdef HAVE_CUDA benchmarkSolver< BICGStabL, ILUT >( benchmark, parameters, cudaMatrixPointer, cuda_x0, cuda_b ); @@ -346,12 +346,12 @@ struct LinearSolversBenchmark benchmark.newBenchmark( name, metadata ); benchmark.setMetadataColumns( Benchmark::MetadataColumns({ // TODO: strip the device -// {"matrix type", matrixPointer->getType()}, - {"rows", String( matrixPointer->getRows() ) }, - {"columns", String( matrixPointer->getColumns() ) }, +// { "matrix type", matrixPointer->getType() }, + { "rows", convertToString( matrixPointer->getRows() ) }, + { "columns", convertToString( matrixPointer->getColumns() ) }, // FIXME: getMaxRowLengths() returns 0 for matrices loaded from file -// {"max elements per row", matrixPointer->getMaxRowLength()}, - {"max elements per row", String( maxRowLength ) }, +// { "max elements per row", matrixPointer->getMaxRowLength() }, + { "max elements per row", convertToString( maxRowLength ) }, } )); const bool reorder = parameters.getParameter< bool >( "reorder-dofs" ); diff --git a/src/Examples/StringExample.cpp b/src/Examples/StringExample.cpp index f69fe9f1f..3db23e6a1 100644 --- a/src/Examples/StringExample.cpp +++ b/src/Examples/StringExample.cpp @@ -12,7 +12,7 @@ int main( int argc, char* argv[] ) String str1; String str2( "xxstringxxx", 2, 3 ); String str3( str2 ); // copy constructor - String str4( 28.4 ); // converts to string + String str4 = convertToString( 28.4 ); // converts to string cout << "str1:" << str1 << endl; cout << "str2:" << str2 << endl; @@ -93,7 +93,7 @@ int main( int argc, char* argv[] ) cout << "h:" << h << endl; String i; - i = 'a' + 'b'; + i = convertToString( 'a' ) + 'b'; cout << "i:" << i << endl; String letter1( "u" ); diff --git a/src/Examples/transport-equation/transportEquationProblemEoc_impl.h b/src/Examples/transport-equation/transportEquationProblemEoc_impl.h index 481818877..512e310d2 100644 --- a/src/Examples/transport-equation/transportEquationProblemEoc_impl.h +++ b/src/Examples/transport-equation/transportEquationProblemEoc_impl.h @@ -89,7 +89,7 @@ setup( const Config::ParameterContainer& parameters, return false; Containers::StaticVector< Dimension, RealType > velocity; for( int i = 0; i < Dimension; i++ ) - velocity[ i ] = parameters.getParameter< double >( "velocity-field-" + String( i ) + "-constant" ); + velocity[ i ] = parameters.getParameter< double >( "velocity-field-" + convertToString( i ) + "-constant" ); Functions::MeshFunctionEvaluator< MeshFunction, ExactSolutionType > evaluator; RealType time( 0.0 ); diff --git a/src/Python/pytnl/tnl/String.cpp b/src/Python/pytnl/tnl/String.cpp index 309a6fe25..551f94ddf 100644 --- a/src/Python/pytnl/tnl/String.cpp +++ b/src/Python/pytnl/tnl/String.cpp @@ -19,8 +19,8 @@ void export_String( py::module & m ) .def(py::init()) .def(py::init()) .def(py::init()) - .def(py::init()) - .def(py::init()) + .def(py::init([](int v){ return TNL::convertToString(v); })) + .def(py::init([](double v){ return TNL::convertToString(v); })) .def_static("getType", &TNL::String::getType) // __str__ (uses operator<<) // explicit namespace resolution is necessary, see http://stackoverflow.com/a/3084341/4180822 diff --git a/src/TNL/Containers/MultiVector1D_impl.h b/src/TNL/Containers/MultiVector1D_impl.h index e8f42c539..5ac452c29 100644 --- a/src/TNL/Containers/MultiVector1D_impl.h +++ b/src/TNL/Containers/MultiVector1D_impl.h @@ -22,7 +22,7 @@ template< typename Real, typename Device, typename Index > String MultiVector< 1, Real, Device, Index > :: getType() { return String( "Containers::MultiVector< ") + - String( Dimension ) + + convertToString( Dimension ) + String( ", " ) + String( TNL::getType< Real >() ) + String( ", " ) + diff --git a/src/TNL/Containers/MultiVector2D_impl.h b/src/TNL/Containers/MultiVector2D_impl.h index 2c39f2222..7f061ad06 100644 --- a/src/TNL/Containers/MultiVector2D_impl.h +++ b/src/TNL/Containers/MultiVector2D_impl.h @@ -22,7 +22,7 @@ template< typename Real, typename Device, typename Index > String MultiVector< 2, Real, Device, Index > :: getType() { return String( "Containers::MultiVector< ") + - String( Dimension ) + + convertToString( Dimension ) + String( ", " ) + String( TNL::getType< Real >() ) + String( ", " ) + diff --git a/src/TNL/Containers/MultiVector3D_impl.h b/src/TNL/Containers/MultiVector3D_impl.h index cd4e543ce..c7949014d 100644 --- a/src/TNL/Containers/MultiVector3D_impl.h +++ b/src/TNL/Containers/MultiVector3D_impl.h @@ -22,7 +22,7 @@ template< typename Real, typename Device, typename Index > String MultiVector< 3, Real, Device, Index > :: getType() { return String( "Containers::MultiVector< ") + - String( Dimension ) + + convertToString( Dimension ) + String( ", " ) + String( TNL::getType< Real >() ) + String( ", " ) + diff --git a/src/TNL/Containers/MultiVector4D_impl.h b/src/TNL/Containers/MultiVector4D_impl.h index 6fe5a4a06..14708ec20 100644 --- a/src/TNL/Containers/MultiVector4D_impl.h +++ b/src/TNL/Containers/MultiVector4D_impl.h @@ -22,7 +22,7 @@ template< typename Real, typename Device, typename Index > String MultiVector< 4, Real, Device, Index > :: getType() { return String( "Containers::MultiVector< ") + - String( Dimension ) + + convertToString( Dimension ) + String( ", " ) + String( TNL::getType< Real >() ) + String( ", " ) + diff --git a/src/TNL/Containers/StaticArray1D_impl.h b/src/TNL/Containers/StaticArray1D_impl.h index 3fd541450..81f5a08d2 100644 --- a/src/TNL/Containers/StaticArray1D_impl.h +++ b/src/TNL/Containers/StaticArray1D_impl.h @@ -48,7 +48,7 @@ template< typename Value > String StaticArray< 1, Value >::getType() { return String( "Containers::StaticArray< " ) + - String( size ) + + convertToString( size ) + String( ", " ) + TNL::getType< Value >() + String( " >" ); diff --git a/src/TNL/Containers/StaticArray2D_impl.h b/src/TNL/Containers/StaticArray2D_impl.h index 841c89529..55096abd0 100644 --- a/src/TNL/Containers/StaticArray2D_impl.h +++ b/src/TNL/Containers/StaticArray2D_impl.h @@ -60,7 +60,7 @@ template< typename Value > String StaticArray< 2, Value >::getType() { return String( "Containers::StaticArray< " ) + - String( size ) + + convertToString( size ) + String( ", " ) + TNL::getType< Value >() + String( " >" ); diff --git a/src/TNL/Containers/StaticArray3D_impl.h b/src/TNL/Containers/StaticArray3D_impl.h index 1ed6d2c15..1aac8cc89 100644 --- a/src/TNL/Containers/StaticArray3D_impl.h +++ b/src/TNL/Containers/StaticArray3D_impl.h @@ -64,7 +64,7 @@ template< typename Value > String StaticArray< 3, Value >::getType() { return String( "Containers::StaticArray< " ) + - String( size ) + + convertToString( size ) + String( ", " ) + TNL::getType< Value >() + String( " >" ); diff --git a/src/TNL/Containers/StaticArray_impl.h b/src/TNL/Containers/StaticArray_impl.h index 898bc9bd5..0917b0f1c 100644 --- a/src/TNL/Containers/StaticArray_impl.h +++ b/src/TNL/Containers/StaticArray_impl.h @@ -52,7 +52,7 @@ template< int Size, typename Value > String StaticArray< Size, Value >::getType() { return String( "Containers::StaticArray< " ) + - String( Size ) + + convertToString( Size ) + String( ", " ) + TNL::getType< Value >() + String( " >" ); diff --git a/src/TNL/Containers/StaticVector1D_impl.h b/src/TNL/Containers/StaticVector1D_impl.h index 8045d12ac..9eb2d90c0 100644 --- a/src/TNL/Containers/StaticVector1D_impl.h +++ b/src/TNL/Containers/StaticVector1D_impl.h @@ -56,7 +56,7 @@ template< typename Real > String StaticVector< 1, Real >::getType() { return String( "Containers::StaticVector< " ) + - String( 1 ) + + convertToString( 1 ) + String( ", " ) + TNL::getType< Real >() + String( " >" ); diff --git a/src/TNL/Containers/StaticVector2D_impl.h b/src/TNL/Containers/StaticVector2D_impl.h index 8691508b8..0a8cb3ec0 100644 --- a/src/TNL/Containers/StaticVector2D_impl.h +++ b/src/TNL/Containers/StaticVector2D_impl.h @@ -64,9 +64,9 @@ template< typename Real > String StaticVector< 2, Real >::getType() { return String( "Containers::StaticVector< " ) + - String( 2 ) + + convertToString( 2 ) + String( ", " ) + - TNL::getType< Real >() + + TNL::getType< Real >() + String( " >" ); } diff --git a/src/TNL/Containers/StaticVector3D_impl.h b/src/TNL/Containers/StaticVector3D_impl.h index 1e2a44cfb..77f1893f6 100644 --- a/src/TNL/Containers/StaticVector3D_impl.h +++ b/src/TNL/Containers/StaticVector3D_impl.h @@ -65,9 +65,9 @@ template< typename Real > String StaticVector< 3, Real >::getType() { return String( "Containers::StaticVector< " ) + - String( 3 ) + + convertToString( 3 ) + String( ", " ) + - TNL::getType< Real >() + + TNL::getType< Real >() + String( " >" ); } diff --git a/src/TNL/Containers/StaticVector_impl.h b/src/TNL/Containers/StaticVector_impl.h index bfb473c92..09fbcc34d 100644 --- a/src/TNL/Containers/StaticVector_impl.h +++ b/src/TNL/Containers/StaticVector_impl.h @@ -49,7 +49,7 @@ StaticVector< Size, Real >::setup( const Config::ParameterContainer& parameters, const String& prefix ) { for( int i = 0; i < Size; i++ ) - if( ! parameters.template getParameter< double >( prefix + String( i ), this->data[ i ] ) ) + if( ! parameters.template getParameter< double >( prefix + convertToString( i ), this->data[ i ] ) ) return false; return true; } @@ -58,7 +58,7 @@ template< int Size, typename Real > String StaticVector< Size, Real >::getType() { return String( "Containers::StaticVector< " ) + - String( Size ) + + convertToString( Size ) + String( ", " ) + TNL::getType< Real >() + String( " >" ); diff --git a/src/TNL/Devices/CudaDeviceInfo.cu b/src/TNL/Devices/CudaDeviceInfo.cu index 56905df96..4e66c095d 100644 --- a/src/TNL/Devices/CudaDeviceInfo.cu +++ b/src/TNL/Devices/CudaDeviceInfo.cu @@ -198,8 +198,8 @@ writeDeviceInfo( Logger& logger ) // logger.writeParameter< int >( "Device no.", i, 1 ); int i = getActiveDevice(); logger.writeParameter< String >( "Name", getDeviceName( i ), 2 ); - String deviceArch = String( getArchitectureMajor( i ) ) + "." + - String( getArchitectureMinor( i ) ); + String deviceArch = convertToString( getArchitectureMajor( i ) ) + "." + + convertToString( getArchitectureMinor( i ) ); logger.writeParameter< String >( "Architecture", deviceArch, 2 ); logger.writeParameter< int >( "CUDA cores", getCudaCores( i ), 2 ); double clockRate = ( double ) getClockRate( i ) / 1.0e3; diff --git a/src/TNL/Devices/SystemInfo.cpp b/src/TNL/Devices/SystemInfo.cpp index 490f65f10..377922b26 100644 --- a/src/TNL/Devices/SystemInfo.cpp +++ b/src/TNL/Devices/SystemInfo.cpp @@ -118,7 +118,7 @@ int SystemInfo::getCPUMaxFrequency( int cpu_id ) { String fileName( "/sys/devices/system/cpu/cpu" ); - fileName += String( cpu_id ) + "/cpufreq/cpuinfo_max_freq"; + fileName += convertToString( cpu_id ) + "/cpufreq/cpuinfo_max_freq"; return readFile< int >( fileName ); } @@ -126,11 +126,11 @@ CacheSizes SystemInfo::getCPUCacheSizes( int cpu_id ) { String directory( "/sys/devices/system/cpu/cpu" ); - directory += String( cpu_id ) + "/cache"; + directory += convertToString( cpu_id ) + "/cache"; CacheSizes sizes; for( int i = 0; i <= 3; i++ ) { - const String cache = directory + "/index" + String( i ); + const String cache = directory + "/index" + convertToString( i ); // check if the directory exists struct stat st; @@ -175,10 +175,10 @@ writeDeviceInfo( Logger& logger ) logger.writeParameter< int >( "Threads per core:", threadsPerCore, 1 ); logger.writeParameter< float >( "Max clock rate (in MHz):", getCPUMaxFrequency( cpu_id ) / 1000, 1 ); CacheSizes cacheSizes = getCPUCacheSizes( cpu_id ); - String cacheInfo = String( cacheSizes.L1data ) + ", " - + String( cacheSizes.L1instruction ) + ", " - + String( cacheSizes.L2 ) + ", " - + String( cacheSizes.L3 ); + String cacheInfo = convertToString( cacheSizes.L1data ) + ", " + + convertToString( cacheSizes.L1instruction ) + ", " + + convertToString( cacheSizes.L2 ) + ", " + + convertToString( cacheSizes.L3 ); logger.writeParameter< String >( "Cache (L1d, L1i, L2, L3):", cacheInfo, 1 ); } diff --git a/src/TNL/Functions/MeshFunction_impl.h b/src/TNL/Functions/MeshFunction_impl.h index 3a8c74b67..49b75d52f 100644 --- a/src/TNL/Functions/MeshFunction_impl.h +++ b/src/TNL/Functions/MeshFunction_impl.h @@ -102,7 +102,7 @@ getType() { return String( "Functions::MeshFunction< " ) + Mesh::getType() + ", " + - String( MeshEntityDimension ) + ", " + + convertToString( MeshEntityDimension ) + ", " + TNL::getType< Real >() + " >"; }; @@ -126,7 +126,7 @@ getSerializationType() { return String( "Functions::MeshFunction< " ) + Mesh::getSerializationType() + ", " + - String( MeshEntityDimension ) + ", " + + convertToString( MeshEntityDimension ) + ", " + TNL::getType< Real >() + " >"; }; diff --git a/src/TNL/Functions/VectorField.h b/src/TNL/Functions/VectorField.h index a873165b4..46fdffcba 100644 --- a/src/TNL/Functions/VectorField.h +++ b/src/TNL/Functions/VectorField.h @@ -36,7 +36,7 @@ class VectorField const String& prefix = "" ) { for( int i = 0; i < Size; i++ ) - FunctionType::configSetup( config, prefix + String( i ) + "-" ); + FunctionType::configSetup( config, prefix + convertToString( i ) + "-" ); } template< typename MeshPointer > @@ -45,7 +45,7 @@ class VectorField const String& prefix = "" ) { for( int i = 0; i < Size; i++ ) - if( ! vectorField[ i ].setup( parameters, prefix + String( i ) + "-" ) ) + if( ! vectorField[ i ].setup( parameters, prefix + convertToString( i ) + "-" ) ) { std::cerr << "Unable to setup " << i << "-th coordinate of the vector field." << std::endl; return false; @@ -103,7 +103,7 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > const String& prefix = "" ) { for( int i = 0; i < Size; i++ ) - FunctionType::configSetup( config, prefix + String( i ) + "-" ); + FunctionType::configSetup( config, prefix + convertToString( i ) + "-" ); } VectorField() {}; @@ -117,7 +117,7 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > static String getType() { return String( "Functions::VectorField< " ) + - String( Size) + ", " + + convertToString( Size) + ", " + FunctionType::getType() + " >"; } @@ -130,7 +130,7 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > static String getSerializationType() { return String( "Functions::VectorField< " ) + - String( Size) + ", " + + convertToString( Size) + ", " + FunctionType::getSerializationType() + " >"; } @@ -164,7 +164,7 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > const String& prefix = "" ) { for( int i = 0; i < Size; i++ ) - if( ! vectorField[ i ].setup( meshPointer, parameters, prefix + String( i ) + "-" ) ) + if( ! vectorField[ i ].setup( meshPointer, parameters, prefix + convertToString( i ) + "-" ) ) { std::cerr << "Unable to setup " << i << "-th coordinate of the vector field." << std::endl; return false; diff --git a/src/TNL/Meshes/DefaultConfig.h b/src/TNL/Meshes/DefaultConfig.h index 147a9ab10..5e8a7cbef 100644 --- a/src/TNL/Meshes/DefaultConfig.h +++ b/src/TNL/Meshes/DefaultConfig.h @@ -50,7 +50,7 @@ struct DefaultConfig { return String( "Meshes::DefaultConfig< " ) + Cell::getType() + ", " + - String( WorldDimension ) + ", " + + convertToString( WorldDimension ) + ", " + TNL::getType< Real >() + ", " + TNL::getType< GlobalIndex >() + ", " + TNL::getType< LocalIndex >() + ", " + diff --git a/src/TNL/Meshes/GridDetails/Grid1D_impl.h b/src/TNL/Meshes/GridDetails/Grid1D_impl.h index 99e456112..1754edc58 100644 --- a/src/TNL/Meshes/GridDetails/Grid1D_impl.h +++ b/src/TNL/Meshes/GridDetails/Grid1D_impl.h @@ -39,7 +39,7 @@ template< typename Real, String Grid< 1, Real, Device, Index >::getType() { return String( "Meshes::Grid< " ) + - String( getMeshDimension() ) + ", " + + convertToString( getMeshDimension() ) + ", " + String( TNL::getType< RealType >() ) + ", " + String( Device::getDeviceType() ) + ", " + String( TNL::getType< IndexType >() ) + " >"; diff --git a/src/TNL/Meshes/GridDetails/Grid2D_impl.h b/src/TNL/Meshes/GridDetails/Grid2D_impl.h index 15874efd5..b315d5d08 100644 --- a/src/TNL/Meshes/GridDetails/Grid2D_impl.h +++ b/src/TNL/Meshes/GridDetails/Grid2D_impl.h @@ -42,7 +42,7 @@ template< typename Real, String Grid< 2, Real, Device, Index > :: getType() { return String( "Meshes::Grid< " ) + - String( getMeshDimension() ) + ", " + + convertToString( getMeshDimension() ) + ", " + String( TNL::getType< RealType >() ) + ", " + String( Device :: getDeviceType() ) + ", " + String( TNL::getType< IndexType >() ) + " >"; diff --git a/src/TNL/Meshes/GridDetails/Grid3D_impl.h b/src/TNL/Meshes/GridDetails/Grid3D_impl.h index e802be7df..cc6805ac0 100644 --- a/src/TNL/Meshes/GridDetails/Grid3D_impl.h +++ b/src/TNL/Meshes/GridDetails/Grid3D_impl.h @@ -49,7 +49,7 @@ template< typename Real, String Grid< 3, Real, Device, Index > :: getType() { return String( "Meshes::Grid< " ) + - String( getMeshDimension() ) + ", " + + convertToString( getMeshDimension() ) + ", " + String( TNL::getType< RealType >() ) + ", " + String( Device :: getDeviceType() ) + ", " + String( TNL::getType< IndexType >() ) + " >"; diff --git a/src/TNL/String.cpp b/src/TNL/String.cpp index 92663a4d8..d814a662c 100644 --- a/src/TNL/String.cpp +++ b/src/TNL/String.cpp @@ -240,7 +240,7 @@ String String::operator+( char str ) const bool String::operator==( char str ) const { - return *this == String( str ); + return *this == convertToString( str ); } bool String::operator!=( char str ) const @@ -424,7 +424,7 @@ bool String :: getLine( std::istream& stream ) String operator+( char string1, const String& string2 ) { - return String( string1 ) + string2; + return convertToString( string1 ) + string2; } String operator+( const char* string1, const String& string2 ) diff --git a/src/TNL/String.h b/src/TNL/String.h index 44f42423f..f949b8770 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -67,19 +67,6 @@ class String /// @param str Another string object, whose value is copied. String( const String& str ); - /// \brief Converts anything to a string. - /// - /// This function converts any type of value into type string. - /// @tparam T is a type of a value to be converted - /// @param value Word of any type (e.g. int, bool, double,...). - template< typename T > - explicit - String( T value ) - : string( nullptr ), length( 0 ) - { - setString( convertToString( value ).getString() ); - } - /// \brief Destructor. ~String(); diff --git a/src/UnitTests/Containers/ListTest.cpp b/src/UnitTests/Containers/ListTest.cpp index 3b5fdaecf..32e65c223 100644 --- a/src/UnitTests/Containers/ListTest.cpp +++ b/src/UnitTests/Containers/ListTest.cpp @@ -16,6 +16,35 @@ using namespace TNL; using namespace TNL::Containers; +// minimal custom data structure usable as ValueType in List +struct MyData +{ + double data; + + __cuda_callable__ + MyData() : data(0) {} + + template< typename T > + __cuda_callable__ + MyData( T v ) : data(v) {} + + __cuda_callable__ + bool operator==( const MyData& v ) const { return data == v.data; } + + __cuda_callable__ + bool operator!=( const MyData& v ) const { return data != v.data; } + + static String getType() + { + return String( "MyData" ); + } +}; + +std::ostream& operator<<( std::ostream& str, const MyData& v ) +{ + return str << v.data; +} + // test fixture for typed tests template< typename List > @@ -32,7 +61,7 @@ using ListTypes = ::testing::Types< List< long >, List< float >, List< double >, - List< String > + List< MyData > >; TYPED_TEST_CASE( ListTest, ListTypes ); diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp index f6ee1a572..389c208e7 100644 --- a/src/UnitTests/StringTest.cpp +++ b/src/UnitTests/StringTest.cpp @@ -51,12 +51,12 @@ TEST( StringTest, CopyConstructor ) EXPECT_EQ( strcmp( emptyString2.getString(), "" ), 0 ); } -TEST( StringTest, ConstructorWithNumber ) +TEST( StringTest, convertToString ) { - String string1( 10 ); - String string2( -5 ); - String string3( true ); - String string4( false ); + String string1 = convertToString( 10 ); + String string2 = convertToString( -5 ); + String string3 = convertToString( true ); + String string4 = convertToString( false ); EXPECT_EQ( strcmp( string1.getString(), "10" ), 0 ); EXPECT_EQ( strcmp( string2.getString(), "-5" ), 0 ); -- GitLab From 2f9831c0f81928875a50f8ed31d94f18bba45fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 15 Dec 2018 23:06:47 +0100 Subject: [PATCH 2/2] Removed useless friend specifier from String --- src/TNL/String.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/TNL/String.h b/src/TNL/String.h index f949b8770..9e2fb201d 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -263,8 +263,6 @@ class String /// expression based on the success in reading the line. bool getLine( std::istream& stream ); - friend std::ostream& operator<<( std::ostream& stream, const String& str ); - protected: /// \brief Pointer to char ended with zero byte. -- GitLab