Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change behavior of Param::Get<bool> #1397

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ but with improved human-readability..
+ Details about the 1.11 to 1.12 transition are explained below in this same
document

### Modifications

1. **Behavior change of `Param::Get<bool>`**
+ Previously when a Param was set from a string, the `Get<bool>` method
would always return `true`, and the value would be `true` if the lowercase
string value matched `"1"` or `"true"` and `false` otherwise. Now,
the `Get<bool>` method returns `true` only if the lowercase value string
matches `"0"`, `"1"`, `"true"`, or `"false"` and returns `false`
otherwise.

## libsdformat 13.x to 14.x

### Additions
Expand Down
16 changes: 0 additions & 16 deletions include/sdf/Param.hh
Original file line number Diff line number Diff line change
Expand Up @@ -740,22 +740,6 @@ namespace sdf
{
_value = std::get<T>(pv);
}
else if (typeStr == "bool" && this->dataPtr->typeName == "string")
{
// this section for handling bool types is to keep backward behavior
// TODO(anyone) remove for Fortress. For more details:
// https://github.com/gazebosim/sdformat/pull/638
valueStr = lowercase(valueStr);

std::stringstream tmp;
if (valueStr == "true" || valueStr == "1")
tmp << "1";
else
tmp << "0";

tmp >> _value;
return true;
}

return success;
}
Expand Down
2 changes: 1 addition & 1 deletion python/test/pyParam_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_bool(self):
str_param.set_string("TRUE")
self.assertTrue(str_param.get_bool()[0])

# Anything other than 1 or true is treated as a False value
# Anything other than "0", "1" , "false", or "true" raises an exception
str_param.set_string("%")
with self.assertRaises(SDFErrorsException):
str_param.get_bool()
Expand Down
6 changes: 3 additions & 3 deletions src/Param_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ TEST(Param, Bool)
EXPECT_TRUE(strParam.Get<bool>(value));
EXPECT_TRUE(value);

// Anything other than 1 or true is treated as a false value
// Anything other than 0, 1, true, or false (any capitalization) will
// causes Get<bool> to fail.
EXPECT_TRUE(strParam.Set("%"));
EXPECT_TRUE(strParam.Get<bool>(value));
EXPECT_FALSE(value);
EXPECT_FALSE(strParam.Get<bool>(value));

EXPECT_TRUE(boolParam.Set(true));
std::any anyValue;
Expand Down
Loading