Skip to content

Commit 24f9e9b

Browse files
committed
helper name changed, prefix enable flag removed
1 parent 9622039 commit 24f9e9b

File tree

2 files changed

+26
-41
lines changed

2 files changed

+26
-41
lines changed

controller_interface/include/controller_interface/helpers.hpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,29 @@ inline bool interface_list_contains_interface_type(
9696
}
9797

9898
/**
99-
* @brief Apply tf prefix
100-
* @param tf_prefix_enabled Whether tf prefixing is enabled
101-
* @param prefix The tf prefix to apply
99+
* @brief Resolve the TF prefix with normalized slashes
100+
* @param prefix The TF prefix
102101
* @param node_ns Node namespace to use as prefix if prefix is empty
103-
* @return Slash normalized prefix
102+
* @return Prefix to be prepended
104103
*/
105-
inline std::string apply_tf_prefix(
106-
const bool tf_prefix_enabled, const std::string & prefix, const std::string & node_ns)
104+
inline std::string resolve_tf_prefix(const std::string & prefix, const std::string & node_ns)
107105
{
108-
if (!tf_prefix_enabled)
106+
if (prefix.empty())
109107
{
110108
return std::string{};
111109
}
112-
std::string nprefix = prefix.empty() ? node_ns : prefix;
113110

114-
// Normalize the prefix
115-
if (!nprefix.empty())
111+
std::string nprefix = prefix == "~" ? node_ns : prefix;
112+
113+
// ensure trailing '/'
114+
if (nprefix.back() != '/')
116115
{
117-
// ensure trailing '/'
118-
if (nprefix.back() != '/')
119-
{
120-
nprefix.push_back('/');
121-
}
122-
// remove leading '/'
123-
if (nprefix.front() == '/')
124-
{
125-
nprefix.erase(0, 1);
126-
}
116+
nprefix.push_back('/');
117+
}
118+
// remove leading '/'
119+
if (nprefix.front() == '/')
120+
{
121+
nprefix.erase(0, 1);
127122
}
128123
return nprefix;
129124
}

controller_interface/test/test_controller_tf_prefix.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,26 @@
1717
#include "controller_interface/helpers.hpp"
1818
#include "test_controller_tf_prefix.hpp"
1919

20-
TEST_F(TestControllerTFPrefix, DisabledPrefixReturnsEmpty)
20+
TEST_F(TestControllerTFPrefix, EmptyPrefixReturnsEmpty)
2121
{
22-
EXPECT_EQ(controller_interface::apply_tf_prefix(false, "robot", "/ns"), "");
23-
EXPECT_EQ(controller_interface::apply_tf_prefix(false, "", "/ns"), "");
22+
EXPECT_EQ(controller_interface::resolve_tf_prefix("", "/ns"), "");
2423
}
2524

26-
TEST_F(TestControllerTFPrefix, EmptyPrefixUsesNamespace)
25+
TEST_F(TestControllerTFPrefix, TildePrefixUsesNamespace)
2726
{
28-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "", "/ns"), "ns/");
27+
EXPECT_EQ(controller_interface::resolve_tf_prefix("~", "/ns"), "ns/");
28+
EXPECT_EQ(controller_interface::resolve_tf_prefix("~", "/ns/"), "ns/");
2929
}
3030

3131
TEST_F(TestControllerTFPrefix, ExplicitPrefixUsed)
3232
{
33-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "robot", "/ns"), "robot/");
33+
EXPECT_EQ(controller_interface::resolve_tf_prefix("robot", "/ns"), "robot/");
3434
}
3535

36-
TEST_F(TestControllerTFPrefix, NormalizesPrefixSlashes)
36+
TEST_F(TestControllerTFPrefix, NormalizePrefixSlashes)
3737
{
38-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "/robot1", "/ns"), "robot1/");
39-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "robot2//", "/ns"), "robot2//");
40-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "/robot3/", "/ns"), "robot3/");
41-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "/", "/ns"), "");
42-
}
43-
44-
TEST_F(TestControllerTFPrefix, EmptyPrefixAndNamespace)
45-
{
46-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "", ""), "");
47-
}
48-
49-
TEST_F(TestControllerTFPrefix, ComplexNamespace)
50-
{
51-
EXPECT_EQ(controller_interface::apply_tf_prefix(true, "", "/ns/"), "ns/");
38+
EXPECT_EQ(controller_interface::resolve_tf_prefix("/robot1", "/ns"), "robot1/");
39+
EXPECT_EQ(controller_interface::resolve_tf_prefix("robot2//", "/ns"), "robot2//");
40+
EXPECT_EQ(controller_interface::resolve_tf_prefix("/robot3/", "/ns"), "robot3/");
41+
EXPECT_EQ(controller_interface::resolve_tf_prefix("/", "/ns"), "");
5242
}

0 commit comments

Comments
 (0)