Commit 0c8c717a authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

[API] moved string_to_num to own header and renamed it to stringToNum

parent cd9c77b9
......@@ -22,6 +22,7 @@
#include "core/debug/TestSubsystem.h"
#include "core/logging/Logging.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "core/timing/Timer.h"
#include "geometry/containment_octree/ContainmentOctree.h"
......@@ -164,8 +165,8 @@ int main( int argc, char * argv[] )
WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " [--no-brute-force] [--force-float] MESH_FILE NUM_POINTS NUM_REPETITIONS" );
const std::string & meshFile = args[1];
const uint_t numPoints = string_to_num<uint_t>( args[2] );
const uint_t numRepetitions = string_to_num<uint_t>( args[3] );
const uint_t numPoints = stringToNum<uint_t>( args[2] );
const uint_t numRepetitions = stringToNum<uint_t>( args[3] );
if(forceFloat)
{
......
......@@ -28,7 +28,6 @@
#include <limits>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
namespace walberla {
......@@ -86,20 +85,6 @@ inline S numeric_cast( T t ) {
}
template<typename S>
inline S string_to_num( std::string & t );
template <> inline float string_to_num( std::string & t ) { return std::stof(t); }
template <> inline double string_to_num( std::string & t ) { return std::stod(t); }
template <> inline long double string_to_num( std::string & t ) { return std::stold(t); }
template <> inline int string_to_num( std::string & t ) { return std::stoi(t); }
template <> inline long string_to_num( std::string & t ) { return std::stol(t); }
template <> inline long long string_to_num( std::string & t ) { return std::stoll(t); }
template <> inline unsigned long string_to_num( std::string & t ) { return std::stoul(t); }
template <> inline unsigned long long string_to_num( std::string & t ) { return std::stoull(t); }
// fixed size signed integral types
typedef std::int8_t int8_t; ///< 8 bit signed integer
typedef std::int16_t int16_t; ///< 16 bit signed integer
......
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file stringToNum.h
//! \author Florian Schornbaum <florian.schornbaum@fau.de>
//
//======================================================================================================================
#pragma once
#include <string>
namespace walberla {
template<typename S>
inline S stringToNum( std::string & t );
template <> inline float stringToNum( std::string & t ) { return std::stof(t); }
template <> inline double stringToNum( std::string & t ) { return std::stod(t); }
template <> inline long double stringToNum( std::string & t ) { return std::stold(t); }
template <> inline int stringToNum( std::string & t ) { return std::stoi(t); }
template <> inline long stringToNum( std::string & t ) { return std::stol(t); }
template <> inline long long stringToNum( std::string & t ) { return std::stoll(t); }
template <> inline unsigned long stringToNum( std::string & t ) { return std::stoul(t); }
template <> inline unsigned long long stringToNum( std::string & t ) { return std::stoull(t); }
} // namespace walberla
......@@ -30,6 +30,7 @@
#include "core/config/Config.h"
#include "core/logging/Logging.h"
#include "core/mpi/Reduce.h"
#include "core/stringToNum.h"
namespace walberla {
......@@ -64,7 +65,7 @@ namespace initializer {
try
{
Value_T value = string_to_num<Value_T>(expression);
Value_T value = stringToNum<Value_T>(expression);
init ( *bodyFromConfig ( subBlock ), value, addOrSet, id );
}
......
......@@ -20,7 +20,7 @@
//
//======================================================================================================================
#include "core/stringToNum.h"
namespace walberla {
namespace geometry {
......@@ -62,7 +62,7 @@ void ScalarFieldFromCellInterval<Field_T>::init( const Config::BlockHandle & blo
try
{
Value_T value = string_to_num<Value_T>(expression);
Value_T value = stringToNum<Value_T>(expression);
init(globalCellInterval, value, id);
}
......
......@@ -24,6 +24,7 @@
#include "core/Abort.h"
#include "core/logging/Logging.h"
#include "core/stringToNum.h"
#include "core/StringUtility.h"
#include <functional>
......@@ -46,9 +47,9 @@ static void splitVector( T& x, T& y, T& z, const Config::BlockHandle& bb, const
if( coordinates.size() != 3 )
WALBERLA_ABORT( errorMsg );
x = string_to_num< T >( coordinates[0] );
y = string_to_num< T >( coordinates[1] );
z = string_to_num< T >( coordinates[2] );
x = stringToNum< T >( coordinates[0] );
y = stringToNum< T >( coordinates[1] );
z = stringToNum< T >( coordinates[2] );
}
......
......@@ -28,6 +28,7 @@
#include "core/load_balancing/MetisWrapper.h"
#include "core/math/Vector2.h"
#include "core/logging/Logging.h"
#include "core/stringToNum.h"
#include "field/AddToStorage.h"
#include "field/GhostLayerField.h"
......@@ -60,8 +61,8 @@ int main( int argc, char * argv[] )
}
try {
fieldSize.set( string_to_num< uint_t >( args.at(1) ), string_to_num< uint_t >( args.at(2) ) );
partitions = string_to_num< uint_t >( args.at(3) );
fieldSize.set( stringToNum< uint_t >( args.at(1) ), stringToNum< uint_t >( args.at(2) ) );
partitions = stringToNum< uint_t >( args.at(3) );
}
catch( std::exception & e )
{
......
......@@ -29,6 +29,7 @@
#include "core/math/Vector2.h"
#include "core/math/IntegerFactorization.h"
#include "core/logging/Logging.h"
#include "core/stringToNum.h"
#include "field/AddToStorage.h"
#include "field/GhostLayerField.h"
......@@ -55,8 +56,8 @@ int main( int argc, char * argv[] )
bool vtk = true;
try {
fieldSize.set( string_to_num< uint_t >( args.at(1) ), string_to_num< uint_t >( args.at(2) ) );
partitions = string_to_num< uint_t >( args.at(3) );
fieldSize.set( stringToNum< uint_t >( args.at(1) ), stringToNum< uint_t >( args.at(2) ) );
partitions = stringToNum< uint_t >( args.at(3) );
auto it = std::find( args.begin(), args.end(), "--no-vtk" );
if(it != args.end())
......
......@@ -27,6 +27,8 @@
#include "core/mpi/MPIManager.h"
#include "core/mpi/MPITextFile.h"
#include "core/stringToNum.h"
#include "core/Filesystem.h"
#include <vector>
......@@ -120,7 +122,7 @@ int main( int argc, char * argv[] )
std::string filename;
try
{
chunkSize = walberla::string_to_num<size_t>( args.at(2) );
chunkSize = walberla::stringToNum<size_t>( args.at(2) );
filename = args.at( 1 );
}
catch( ... )
......
......@@ -28,6 +28,7 @@
#include "core/mpi/Environment.h"
#include "core/timing/Timer.h"
#include "core/math/IntegerFactorization.h"
#include "core/stringToNum.h"
#include "field/AddToStorage.h"
#include "field/Field.h"
......@@ -84,10 +85,10 @@ int main( int argc, char* argv[] )
if( args.size() == 5 )
{
numBlocks = string_to_num<uint_t>( args[1] );
xBlockSize = string_to_num<uint_t>( args[2] );
yBlockSize = string_to_num<uint_t>( args[3] );
zBlockSize = string_to_num<uint_t>( args[4] );
numBlocks = stringToNum<uint_t>( args[1] );
xBlockSize = stringToNum<uint_t>( args[2] );
yBlockSize = stringToNum<uint_t>( args[3] );
zBlockSize = stringToNum<uint_t>( args[4] );
}
else if( args.size() > 5 )
{
......
......@@ -62,6 +62,7 @@
#include "core/math/Constants.h"
#include "core/math/IntegerFactorization.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "domain_decomposition/SharedSweep.h"
......@@ -198,14 +199,14 @@ int run( int argc, char **argv )
if( argc > 1 ) {
std::vector<std::string> args( argv, argv + argc );
for( uint_t i = 1; i < uint_c(argc); ++i ) {
if( std::string(argv[i]) == "-d" ) d = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-dim" ) dim = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-dx" ) dx = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-dt" ) dt = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-dv" ) dv = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-v" ) u_in = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-err" ) err = string_to_num<real_t>( args[++i] );
if( std::string(argv[i]) == "-d" ) d = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-dim" ) dim = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-dx" ) dx = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-dt" ) dt = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-dv" ) dv = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-v" ) u_in = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-err" ) err = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "--gui" ) useGui = true;
else if( std::string(argv[i]) == "--quiet" ) quiet = true;
else if( std::string(argv[i]) == "--vtk" ) useVTK = true;
......
......@@ -59,6 +59,7 @@
#include "core/math/Constants.h"
#include "core/math/IntegerFactorization.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "domain_decomposition/SharedSweep.h"
......@@ -222,12 +223,12 @@ int main( int argc, char **argv )
if( argc > 1 ) {
std::vector<std::string> args( argv, argv + argc );
for( uint_t i = 1; i < uint_c(argc); ++i ) {
if( std::string(argv[i]) == "-o" ) omega = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-l" ) length = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-w" ) width = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-v" ) velx = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-e" ) error = string_to_num<real_t>( args[++i] );
if( std::string(argv[i]) == "-o" ) omega = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-l" ) length = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-w" ) width = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-v" ) velx = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-e" ) error = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "--gui" ) useGui = true;
else if( std::string(argv[i]) == "--vtk" ) useVTK = true;
else if( argv[i][0] != '-' ){
......
......@@ -51,6 +51,7 @@
#include "core/math/IntegerFactorization.h"
#include "core/math/Limits.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "domain_decomposition/SharedSweep.h"
......@@ -430,13 +431,13 @@ int main( int argc, char **argv )
if( argc > 1 ) {
std::vector<std::string> args( argv, argv + argc );
for( uint_t i = 1; i < uint_c(argc); ++i ) {
if( std::string(argv[i]) == "-l" ) length = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-w" ) width = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-d" ) dv = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-o" ) omega = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-c" ) closed = string_to_num<int>( args[++i] ) != 0;
else if( std::string(argv[i]) == "-r" ) levels += string_to_num<uint_t>( args[++i] );
if( std::string(argv[i]) == "-l" ) length = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-w" ) width = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-d" ) dv = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-o" ) omega = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-c" ) closed = stringToNum<int>( args[++i] ) != 0;
else if( std::string(argv[i]) == "-r" ) levels += stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "--vtk" ) useVTK = true;
else if( argv[i][0] != '-' ){
std::cerr << "Usage: -option value" << std::endl; return EXIT_FAILURE;
......
......@@ -42,6 +42,7 @@
#include "core/debug/TestSubsystem.h"
#include "core/math/IntegerFactorization.h"
#include "core/mpi/MPIManager.h"
#include "core/stringToNum.h"
#include "domain_decomposition/SharedSweep.h"
......@@ -215,11 +216,11 @@ int main( int argc, char **argv )
if( args.size() != 6 )
throw std::invalid_argument( "Wrong number of command line arguments!" );
channelLength = string_to_num<uint_t>( args[1] );
channelWidth = string_to_num<uint_t>( args[2] );
omega = string_to_num<real_t>( args[3] );
deltaDensity = string_to_num<real_t>( args[4] );
numTimesteps = string_to_num<uint_t>( args[5] );
channelLength = stringToNum<uint_t>( args[1] );
channelWidth = stringToNum<uint_t>( args[2] );
omega = stringToNum<real_t>( args[3] );
deltaDensity = stringToNum<real_t>( args[4] );
numTimesteps = stringToNum<uint_t>( args[5] );
}
catch( std::exception & )
{
......
......@@ -50,6 +50,7 @@
#include "core/math/IntegerFactorization.h"
#include "core/math/Limits.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "domain_decomposition/SharedSweep.h"
......@@ -274,15 +275,15 @@ int main( int argc, char **argv )
if( argc > 1 ) {
std::vector<std::string> args( argv, argv + argc );
for( uint_t i = 1; i < uint_c(argc); ++i ) {
if( std::string(argv[i]) == "-l" ) length = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-w" ) width = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = string_to_num<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-dv" ) dv = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-v" ) v = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-do" ) domega = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-o" ) omega = string_to_num<real_t>( args[++i] );
else if( std::string(argv[i]) == "-c" ) closed = string_to_num<int>( args[++i] ) != 0;
else if( std::string(argv[i]) == "-r" ) levels += string_to_num<uint_t>( args[++i] );
if( std::string(argv[i]) == "-l" ) length = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-w" ) width = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-t" ) time = stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "-dv" ) dv = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-v" ) v = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-do" ) domega = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-o" ) omega = stringToNum<real_t>( args[++i] );
else if( std::string(argv[i]) == "-c" ) closed = stringToNum<int>( args[++i] ) != 0;
else if( std::string(argv[i]) == "-r" ) levels += stringToNum<uint_t>( args[++i] );
else if( std::string(argv[i]) == "--vtk" ) useVTK = true;
else if( argv[i][0] != '-' ){
std::cerr << "Usage: -option value" << std::endl; return EXIT_FAILURE;
......
......@@ -24,6 +24,7 @@
#include "core/math/AABB.h"
#include "core/mpi/Environment.h"
#include "core/Optional.h"
#include "core/stringToNum.h"
#include "mesh_common/MeshIO.h"
#include "mesh_common/MeshOperations.h"
......@@ -87,7 +88,7 @@ int main( int argc, char * argv[] )
if( args.size() != 2 )
WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " NUM_AABBS" );
const uint_t numAABBs = string_to_num< uint_t >( args[1] );
const uint_t numAABBs = stringToNum< uint_t >( args[1] );
runTests< mesh::TriangleMesh >( numAABBs );
runTests< mesh::FloatTriangleMesh >( numAABBs );
......
......@@ -22,6 +22,7 @@
#include "core/debug/TestSubsystem.h"
#include "core/mpi/Environment.h"
#include "core/logging/Logging.h"
#include "core/stringToNum.h"
#include "geometry/mesh/TriangleMesh.h"
#include "geometry/mesh/TriangleMeshIO.h"
......@@ -51,8 +52,8 @@ int main( int argc, char * argv[] )
WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_BOXES NUM_POINTS_TESTED_PER_BOX" );
const std::string & meshFile = args[1];
const uint_t numBoxes = string_to_num<uint_t>( args[2] );
const uint_t numPointsTestedPerBox = string_to_num<uint_t>( args[3] );
const uint_t numBoxes = stringToNum<uint_t>( args[2] );
const uint_t numPointsTestedPerBox = stringToNum<uint_t>( args[3] );
auto mesh = make_shared<TriangleMesh>();
mesh::readAndBroadcast( meshFile, *mesh );
......
......@@ -26,6 +26,7 @@
#include "core/logging/Logging.h"
#include "core/math/IntegerFactorization.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "geometry/mesh/TriangleMesh.h"
#include "geometry/mesh/TriangleMeshIO.h"
......@@ -148,7 +149,7 @@ int main( int argc, char * argv[] )
WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_BLOCKS" );
const std::string & meshFile = args[1];
const uint_t numTotalBlocks = string_to_num< uint_t >( args[2] );
const uint_t numTotalBlocks = stringToNum< uint_t >( args[2] );
run< mesh::TriangleMesh >( meshFile, numTotalBlocks );
run< mesh::FloatTriangleMesh >( meshFile, numTotalBlocks );
......
......@@ -26,6 +26,7 @@
#include "core/debug/TestSubsystem.h"
#include "core/logging/Logging.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "field/AddToStorage.h"
#include "field/vtk/VTKWriter.h"
......@@ -72,7 +73,7 @@ int main( int argc, char * argv[] )
args.erase( vtkArgIt );
}
const std::string & meshFile = args[1];
real_t dx = string_to_num<real_t>( args[2] );
real_t dx = stringToNum<real_t>( args[2] );
auto mesh = make_shared<mesh::TriangleMesh>();
mesh::readAndBroadcast( meshFile, *mesh);
......
......@@ -27,6 +27,7 @@
#include "core/logging/Logging.h"
#include "core/math/IntegerFactorization.h"
#include "core/mpi/Environment.h"
#include "core/stringToNum.h"
#include "geometry/mesh/TriangleMesh.h"
#include "geometry/mesh/TriangleMeshIO.h"
......@@ -177,8 +178,8 @@ int main( int argc, char * argv[] )
WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_PROCESSES NUM_BLOCKS" );
const std::string & meshFile = args[1];
const uint_t numProcesses = string_to_num< uint_t >( args[2] );
const uint_t numTotalBlocks = string_to_num< uint_t >( args[3] );
const uint_t numProcesses = stringToNum< uint_t >( args[2] );
const uint_t numTotalBlocks = stringToNum< uint_t >( args[3] );
test< mesh::TriangleMesh >( meshFile, numProcesses, numTotalBlocks );
//test< mesh::FloatTriangleMesh >( meshFile, numProcesses, numTotalBlocks );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment