Compare commits

...

6 Commits

Author SHA1 Message Date
Jorge Santos Simón ce65b96337
Merge 98b2218062 into 8d47d397e7 2025-07-31 22:45:16 +07:00
Vince Reda 8d47d397e7
Set current_child_idx of SequenceNode protected (#991)
Signed-off-by: redvinaa <redvinaa@gmail.com>
2025-07-20 11:05:17 +02:00
Marcus Ebner von Eschenbach 6ec652d368
Add convertFromString<vector<bool>> (#992) 2025-07-20 11:03:41 +02:00
Davide Faconti 4d6f92add1
Update README.md fix #985
Duuuude
2025-07-15 18:40:31 +02:00
corot 98b2218062 Remake DefaultWronglyOverriden test as AllowEmptyValues 2024-08-29 09:53:18 +09:00
corot 317ae5d7e6 Allow letting value field empty for numeric ports 2024-08-05 14:45:34 +09:00
6 changed files with 44 additions and 18 deletions

View File

@ -64,19 +64,19 @@ Compiling with [conan](https://conan.io/):
Assuming that you are in the **parent** directory of `BehaviorTree.CPP`:
```
mkdir build; cd build
conan install ../BehaviorTree.CPP --output-folder=. --build=missing
cmake ../BehaviorTree.CPP -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake"
cmake --build . --parallel
mkdir build_release
conan install . -of build_release -s build_type=Release
cmake -S . -B build_release -DCMAKE_TOOLCHAIN_FILE="build_release/conan_toolchain.cmake"
cmake --build build_release --parallel
```
If you have dependencies such as ZeroMQ and SQlite already installed and you don't want to
use conan, simply type:
```
mkdir build; cd build
cmake ../BehaviorTree.CPP
cmake --build . --parallel
mkdir build_release
cmake -S . -B build_release
cmake --build build_release --parallel
```
If you want to build in a [pixi](https://pixi.sh/) project (conda virtual environment).

View File

@ -183,6 +183,10 @@ template <>
template <>
[[nodiscard]] std::vector<double> convertFromString<std::vector<double>>(StringView str);
// Boolean values separated by the character ";"
template <>
[[nodiscard]] std::vector<bool> convertFromString<std::vector<bool>>(StringView str);
// Strings separated by the character ";"
template <>
[[nodiscard]] std::vector<std::string>

View File

@ -40,8 +40,10 @@ public:
virtual void halt() override;
private:
protected:
size_t current_child_idx_;
private:
size_t skipped_count_ = 0;
bool asynch_ = false;

View File

@ -237,6 +237,19 @@ std::vector<double> convertFromString<std::vector<double>>(StringView str)
return output;
}
template <>
std::vector<bool> convertFromString<std::vector<bool>>(StringView str)
{
auto parts = splitString(str, ';');
std::vector<bool> output;
output.reserve(parts.size());
for(const StringView& part : parts)
{
output.push_back(convertFromString<bool>(part));
}
return output;
}
template <>
std::vector<std::string> convertFromString<std::vector<std::string>>(StringView str)
{

View File

@ -703,7 +703,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
") but not in the providedPorts() of its "
"registered node type."));
}
else
else if(!port_value.empty())
{
const auto& port_model = port_model_it->second;
bool is_blacbkboard = port_value.size() >= 3 && port_value.front() == '{' &&

View File

@ -704,29 +704,36 @@ TEST(PortTest, Default_Issues_767)
"default nullptr"));
}
TEST(PortTest, DefaultWronglyOverriden)
TEST(PortTest, AllowEmptyValues)
{
BT::BehaviorTreeFactory factory;
factory.registerNodeType<NodeWithPorts>("NodeWithPorts");
factory.registerNodeType<NodeWithDefaultNullptr>("NodeWithDefaultNullptr");
std::string xml_txt_wrong = R"(
std::string xml_txt_empty_number = R"(
<root BTCPP_format="4" >
<BehaviorTree>
<NodeWithPorts in_port_A=""/>
</BehaviorTree>
</root>)";
std::string xml_txt_empty_pointer = R"(
<root BTCPP_format="4" >
<BehaviorTree>
<NodeWithDefaultNullptr input=""/>
</BehaviorTree>
</root>)";
std::string xml_txt_correct = R"(
std::string xml_txt_empty_default = R"(
<root BTCPP_format="4" >
<BehaviorTree>
<NodeWithDefaultNullptr/>
</BehaviorTree>
</root>)";
// this should throw, because we are NOT using the default,
// but overriding it with an empty string instead.
// See issue 768 for reference
ASSERT_ANY_THROW(auto tree = factory.createTreeFromText(xml_txt_wrong));
// This is correct
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_correct));
// All are correct, as we allow empty strings that will get retrieved as std::nullopt
// Note that this is the opposite request on issue 768
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_number));
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_pointer));
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_default));
}