Skip to content

Commit 0dd404b

Browse files
authored
Small improvements (#479)
* Make message for allowed port names more explicit Also throw an exception for unknown port direction rather than using `PortDirection::INOUT`. * Small code improvements * Remove code without effect
1 parent aeea56d commit 0dd404b

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

include/behaviortree_cpp/basic_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ std::pair<std::string, PortInfo> CreatePort(PortDirection direction, StringView
292292
auto sname = static_cast<std::string>(name);
293293
if (!IsAllowedPortName(sname))
294294
{
295-
throw RuntimeError("The name of a port must start with an alphabetic character. "
295+
throw RuntimeError("The name of a port must not be `name` or `ID` "
296+
"and must start with an alphabetic character. "
296297
"Underscore is reserved.");
297298
}
298299

include/behaviortree_cpp/tree_node.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma once
1515

1616
#include <condition_variable>
17+
#include <exception>
1718
#include <mutex>
1819
#include <map>
1920

@@ -343,9 +344,9 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
343344

344345
std::unique_lock<std::mutex> entry_lock(config_.blackboard->entryMutex());
345346
const Any* val = config_.blackboard->getAny(static_cast<std::string>(remapped_key));
346-
if (val && val->empty() == false)
347+
if (val && !val->empty())
347348
{
348-
if (std::is_same<T, std::string>::value == false &&
349+
if (!std::is_same_v<T, std::string> &&
349350
val->type() == typeid(std::string))
350351
{
351352
destination = convertFromString<T>(val->cast<std::string>());

src/basic_types.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ PortDirection convertFromString<PortDirection>(StringView str)
253253
return PortDirection::INPUT;
254254
if (str == "Output" || str == "OUTPUT")
255255
return PortDirection::OUTPUT;
256-
return PortDirection::INOUT;
256+
if (str == "InOut" || str == "INOUT")
257+
return PortDirection::INOUT;
258+
throw RuntimeError(std::string("Cannot convert this to PortDirection: ") +
259+
static_cast<std::string>(str));
257260
}
258261

259262
std::ostream& operator<<(std::ostream& os, const NodeType& type)
@@ -287,7 +290,7 @@ std::vector<StringView> splitString(const StringView& strToSplit, char delimeter
287290
{
288291
new_pos = strToSplit.size();
289292
}
290-
StringView sv = {&strToSplit.data()[pos], new_pos - pos};
293+
const auto sv = StringView{&strToSplit.data()[pos], new_pos - pos};
291294
splitted_strings.push_back(sv);
292295
pos = new_pos + 1;
293296
}

src/controls/fallback_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
#include "behaviortree_cpp/controls/fallback_node.h"
15-
#include "behaviortree_cpp/action_node.h"
15+
1616
namespace BT
1717
{
1818
FallbackNode::FallbackNode(const std::string& name) :

src/decorators/repeat_node.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
namespace BT
1717
{
18-
constexpr const char* RepeatNode::NUM_CYCLES;
1918

2019
RepeatNode::RepeatNode(const std::string& name, int NTries) :
2120
DecoratorNode(name, {}),

0 commit comments

Comments
 (0)