Skip to content
Snippets Groups Projects
Commit 1031fb31 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Merge branch 'GAUDI-1121' into 'master'

use `double` parser for floats with Boost 1.59

* introduced a test to expose the problem
* use the parser for doubles to parse strings into floats when Boost > 1.55

Fixes GAUDI-1121.

See merge request !60
parents de80db56 cebc3867
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,16 @@ PARSERS_DEF_FOR_SINGLE(unsigned long) ...@@ -30,6 +30,16 @@ PARSERS_DEF_FOR_SINGLE(unsigned long)
PARSERS_DEF_FOR_SINGLE(long long) PARSERS_DEF_FOR_SINGLE(long long)
PARSERS_DEF_FOR_SINGLE(unsigned long long) PARSERS_DEF_FOR_SINGLE(unsigned long long)
PARSERS_DEF_FOR_SINGLE(double) PARSERS_DEF_FOR_SINGLE(double)
#if BOOST_VERSION <= 105500
PARSERS_DEF_FOR_SINGLE(float) PARSERS_DEF_FOR_SINGLE(float)
#else
// See GAUDI-1121.
StatusCode Gaudi::Parsers::parse(float& result, const std::string& input) {
double tmp{0};
StatusCode sc = Gaudi::Parsers::parse_(tmp, input);
result = static_cast<float>(tmp);
return std::move(sc);
}
#endif
PARSERS_DEF_FOR_SINGLE(long double) PARSERS_DEF_FOR_SINGLE(long double)
PARSERS_DEF_FOR_SINGLE(std::string) PARSERS_DEF_FOR_SINGLE(std::string)
...@@ -78,6 +78,13 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name! ...@@ -78,6 +78,13 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name!
BOOST_CHECK( parse(result, "1.5E2") ); BOOST_CHECK( parse(result, "1.5E2") );
BOOST_CHECK( result == 150); BOOST_CHECK( result == 150);
} }
{
// test bug GAUDI-1121
float result;
BOOST_CHECK( parse(result, "-10000000000.0") );
BOOST_CHECK( result == -1.E10 );
}
//============================================================================== //==============================================================================
// VectorGramar // VectorGramar
//============================================================================== //==============================================================================
...@@ -232,7 +239,7 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name! ...@@ -232,7 +239,7 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name!
{ {
std::vector<std::tuple<int, std::string, bool>> result; std::vector<std::tuple<int, std::string, bool>> result;
BOOST_REQUIRE(Gaudi::Parsers::parse(result, BOOST_REQUIRE(Gaudi::Parsers::parse(result,
"[(2, 'hello', True), (3, 'world', False)]")); "[(2, 'hello', True), (3, 'world', False)]"));
BOOST_REQUIRE(result.size() == 2); BOOST_REQUIRE(result.size() == 2);
BOOST_CHECK(std::get<0>(result[0]) == 2); BOOST_CHECK(std::get<0>(result[0]) == 2);
...@@ -243,7 +250,7 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name! ...@@ -243,7 +250,7 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name!
BOOST_CHECK(!std::get<2>(result[1])); BOOST_CHECK(!std::get<2>(result[1]));
} }
{ {
std::tuple<int, std::string> result; std::tuple<int, std::string> result;
BOOST_CHECK(!Gaudi::Parsers::parse(result, "(2, 'hello', 1.0)")); BOOST_CHECK(!Gaudi::Parsers::parse(result, "(2, 'hello', 1.0)"));
...@@ -256,7 +263,7 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name! ...@@ -256,7 +263,7 @@ int test_main(int /*argc*/, char** /*argv*/) // note the name!
std::array<int, 2> result; std::array<int, 2> result;
BOOST_REQUIRE(Gaudi::Parsers::parse(result, "(1, 2)")); BOOST_REQUIRE(Gaudi::Parsers::parse(result, "(1, 2)"));
BOOST_CHECK(result[0] == 1); BOOST_CHECK(result[0] == 1);
BOOST_CHECK(result[1] == 2); BOOST_CHECK(result[1] == 2);
} }
//============================================================================== //==============================================================================
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment