diff --git a/src/Benchmarks/BLAS/tnl-benchmark-blas.h b/src/Benchmarks/BLAS/tnl-benchmark-blas.h index 3472dd6f6e6326ef0016f56251c8b4d17c36685c..390b17279db2dd153172b7fcb6c294e0a6969d9b 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 ceb6b9c7eb8656925f8c780ce1272d98ee5178b6..559e27ee26fe6c03d1df5d3d76584376f6f0f7ed 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 ecc001d6676c5c8021c3e115ed2af49d49bab614..738fda0566c3cce187005427008391d3118d72c2 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 afe284ad7c2951f364082d97e78e1ec9a79a895a..084d6cc39a6a755b5ead53d791d22d2c327b37b9 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 c31f776cd4ff571b4f00e85a6ffcef2959a55e50..ce8d49ae0864a4c414eb10f93d1d7aae45783810 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 f69fe9f1f70a1996892228600c9062855d6d0f40..3db23e6a1b9ac02108de82689acd8a9e50a54288 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 4818188774c2ceedb53266e54367e371251e51ac..512e310d2f62ac5e118a729db9a1c5ae775bef89 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 309a6fe25fdafae45c672cd321ad851a55f57056..551f94ddf61f3e492dbeefb2b140d570dd779c6f 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 e8f42c5391774360f6af595c6e47d2b329e7c1de..5ac452c2929a5717d37d726aa1778bf13db77921 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 2c39f22226a9ad5f070505f144e1811ac19e18ca..7f061ad06cf9e0288d465ab3aa775855374ddd98 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 cd4e543cec48c96464c2775d5ad971791f6ae221..c7949014d7233bc14d744457201d14e7923a70fe 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 6fe5a4a062eca65d83adfe10537b79d77af5f449..14708ec20c6d7c4daa5cb1424843bb34fcd78aa9 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 3fd54145053bffb24e2ab4219e694102853b3165..81f5a08d24c01780a3ba5e96757399a96d4e746f 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 841c89529aa55571f0446eb2a7d0895b21aecf69..55096abd08da4b319f3e59bbb2b5445be2249723 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 1ed6d2c155f7e0d5d170d12ba8c426adca41b52d..1aac8cc890b0ba46572e1fffca4a53616cb20f11 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 898bc9bd5625ba73b77c015d0472337a0eeda81f..0917b0f1cb9019665a3b0f829953ecf45f677d66 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 8045d12ac680c802bacb959842a0bc2b0ffe22e2..9eb2d90c01692600d9e7ae7c3a633037b1d5db59 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 8691508b81557b6ce448ca24d65df2b2089bc035..0a8cb3ec0be4a23919a121fb29d8d31511b58a65 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 1e2a44cfbc29caa97f12fb3e3b0d0b417cb31458..77f1893f66b60cddc032099435a095b5a0abf09f 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 bfb473c92f8440ad941869a39ec933d85025f27c..09fbcc34d392fcccd9252860d86a11d05f4828e4 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 56905df9675ef10b07ba40d1876215376ade611c..4e66c095d6579385f668de4cf93b255b3182c87f 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 490f65f101c762c96dc0c6a5bf281a1ef232d7e5..377922b26e320db704fe327050e93e77de932ada 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 3a8c74b6785b68357707ff9e7349a42a67e07f5f..49b75d52fdbdb14eca36cd9d5b543fb838f4426c 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 a873165b401fa4f8dc10c7c6fac31682cb81dd2b..46fdffcba1ffe34d1a57f75ad8b6b1474fbefb5e 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 147a9ab10b911ba0a0bca9ec1dd3b74035508e6e..5e8a7cbef85fc2a03681553f7348af5c95f45dbb 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 99e456112366547368cccb03c5a240e01583a534..1754edc587fee6202d59f778cb6c9485d3a05f4e 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 15874efd502bb07bf157561e0324d6c992470929..b315d5d086aee7532817edd67b9870735d4a49a5 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 e802be7df9ff79acd5ae447d5f976664566c3053..cc6805ac0632de43899d124c87fe4427f84487e5 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 92663a4d8aed06405514f4a9e2ca69013832a92a..d814a662c32ab562cefbddac714186366568b5f4 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 44f42423fe207955dab89e05eddf62344191ea19..9e2fb201d0af02d3573d0f03b37c32cddf1e3ee2 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(); @@ -276,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. diff --git a/src/UnitTests/Containers/ListTest.cpp b/src/UnitTests/Containers/ListTest.cpp index 3b5fdaecf385dab8da032a020ef6b6511ccf0c18..32e65c22318a4059c981e9fb38bd93de22a2e5da 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 f6ee1a57225d0287da3418a162363ee39e73925e..389c208e7f83d67a16ff0d70dace341976f55444 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 );