OPM-94: Removed specialized int,double,string implementations, one generic covers the same
This commit is contained in:
parent
d6594c587f
commit
697c273c19
@ -42,35 +42,4 @@ namespace Opm {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
int readValueToken(const std::string& valueToken) {
|
||||
try {
|
||||
return boost::lexical_cast<int>(valueToken);
|
||||
}
|
||||
catch (boost::bad_lexical_cast&) {
|
||||
throw std::invalid_argument("Unable to parse string" + valueToken + " to an integer");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
double readValueToken(const std::string& valueToken) {
|
||||
try {
|
||||
return boost::lexical_cast<double>(valueToken);
|
||||
}
|
||||
catch (boost::bad_lexical_cast&) {
|
||||
throw std::invalid_argument("Unable to parse string " + valueToken + " to a double");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
std::string readValueToken(const std::string& valueToken) {
|
||||
return valueToken;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,27 +24,25 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib> // strtol, strtod
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#define STAR '*'
|
||||
#define C_EOS '\0'
|
||||
|
||||
namespace Opm {
|
||||
|
||||
bool tokenContainsStar(const std::string& token);
|
||||
|
||||
|
||||
template <class T>
|
||||
T readValueToken(const std::string& /* valueToken */) {
|
||||
return 0;
|
||||
T readValueToken(const std::string& valueToken ) {
|
||||
try {
|
||||
return boost::lexical_cast<T>(valueToken);
|
||||
}
|
||||
catch (boost::bad_lexical_cast&) {
|
||||
throw std::invalid_argument("Unable to parse string" + valueToken + " to typeid: " + typeid(T).name());
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string readValueToken(const std::string& valueToken);
|
||||
|
||||
template <>
|
||||
double readValueToken(const std::string& valueToken);
|
||||
|
||||
template <>
|
||||
int readValueToken(const std::string& valueToken);
|
||||
|
||||
|
||||
template <class T>
|
||||
class StarToken {
|
||||
|
@ -120,3 +120,10 @@ BOOST_AUTO_TEST_CASE( ContainsStar_WithStar_ReturnsTrue ) {
|
||||
|
||||
BOOST_CHECK_EQUAL( false , Opm::tokenContainsStar("12") );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( readValueToken_basic_validity_tests ) {
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<int>("3.3"), std::invalid_argument );
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<double>("truls"), std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( "3.3", Opm::readValueToken<std::string>("3.3") );
|
||||
BOOST_CHECK_EQUAL( "OLGA", Opm::readValueToken<std::string>("OLGA") );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user