Skip to content

Commit c2d1e4b

Browse files
committed
clang form at
1 parent 7c5f0d1 commit c2d1e4b

14 files changed

+601
-618
lines changed

examples/broken_sequence.cpp

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,63 @@ using namespace BT;
66

77
NodeStatus SayHello()
88
{
9-
printf("hello\n");
10-
return NodeStatus::SUCCESS;
9+
printf("hello\n");
10+
return NodeStatus::SUCCESS;
1111
}
1212

1313
class ActionTestNode : public ActionNode
1414
{
15-
public:
16-
ActionTestNode(const std::string& name) : ActionNode(name)
15+
public:
16+
ActionTestNode(const std::string& name) : ActionNode(name)
17+
{}
18+
19+
NodeStatus tick() override
20+
{
21+
time_ = 5;
22+
stop_loop_ = false;
23+
int i = 0;
24+
while (!stop_loop_ && i++ < time_)
1725
{
26+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
1827
}
28+
return NodeStatus::SUCCESS;
29+
}
1930

20-
NodeStatus tick() override
21-
{
22-
time_ = 5;
23-
stop_loop_ = false;
24-
int i = 0;
25-
while (!stop_loop_ && i++ < time_)
26-
{
27-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
28-
}
29-
return NodeStatus::SUCCESS;
30-
}
31-
32-
virtual void halt() override
33-
{
34-
stop_loop_ = true;
35-
setStatus(NodeStatus::IDLE);
36-
}
31+
virtual void halt() override
32+
{
33+
stop_loop_ = true;
34+
setStatus(NodeStatus::IDLE);
35+
}
3736

38-
private:
39-
int time_;
40-
std::atomic_bool stop_loop_;
37+
private:
38+
int time_;
39+
std::atomic_bool stop_loop_;
4140
};
4241

4342
int main()
4443
{
45-
BT::SequenceNode root("root");
46-
BT::SimpleActionNode action1("say_hello", std::bind(SayHello));
47-
ActionTestNode action2("async_action");
44+
BT::SequenceNode root("root");
45+
BT::SimpleActionNode action1("say_hello", std::bind(SayHello));
46+
ActionTestNode action2("async_action");
4847

49-
root.addChild(&action1);
50-
root.addChild(&action2);
48+
root.addChild(&action1);
49+
root.addChild(&action2);
5150

52-
int count = 0;
51+
int count = 0;
5352

54-
NodeStatus status = NodeStatus::RUNNING;
53+
NodeStatus status = NodeStatus::RUNNING;
5554

56-
while (status == NodeStatus::RUNNING)
57-
{
58-
status = root.executeTick();
55+
while (status == NodeStatus::RUNNING)
56+
{
57+
status = root.executeTick();
5958

60-
std::cout << count++ << " : " << root.status() << " / " << action1.status() << " / "
61-
<< action2.status() << std::endl;
62-
63-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
64-
}
59+
std::cout << count++ << " : " << root.status() << " / " << action1.status() << " / "
60+
<< action2.status() << std::endl;
6561

66-
62+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
63+
}
6764

68-
return 0;
65+
return 0;
6966
}
7067
// Output
7168
/*

examples/ex01_wrap_legacy.cpp

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,45 @@
88

99
// This is my custom type. We won't know how to read this from a string,
1010
// unless we implement convertFromString<Point3D>()
11-
struct Point3D { double x,y,z; };
11+
struct Point3D
12+
{
13+
double x, y, z;
14+
};
1215

1316
// We want to create an ActionNode that calls the method MyLegacyMoveTo::go
1417
class MyLegacyMoveTo
1518
{
1619
public:
17-
bool go(Point3D goal)
18-
{
19-
printf("Going to: %f %f %f\n", goal.x, goal.y, goal.z);
20-
return true; // true means success in my legacy code
21-
}
20+
bool go(Point3D goal)
21+
{
22+
printf("Going to: %f %f %f\n", goal.x, goal.y, goal.z);
23+
return true; // true means success in my legacy code
24+
}
2225
};
2326

2427
// Similarly to the previous tutorials, we need to implement this parsing method,
2528
// providing a specialization of BT::convertFromString
2629
namespace BT
2730
{
28-
template <> Point3D convertFromString(StringView key)
31+
template <>
32+
Point3D convertFromString(StringView key)
2933
{
30-
// three real numbers separated by semicolons
31-
auto parts = BT::splitString(key, ';');
32-
if (parts.size() != 3)
33-
{
34-
throw RuntimeError("invalid input)");
35-
}
36-
else
37-
{
38-
Point3D output;
39-
output.x = convertFromString<double>(parts[0]);
40-
output.y = convertFromString<double>(parts[1]);
41-
output.z = convertFromString<double>(parts[2]);
42-
return output;
43-
}
34+
// three real numbers separated by semicolons
35+
auto parts = BT::splitString(key, ';');
36+
if (parts.size() != 3)
37+
{
38+
throw RuntimeError("invalid input)");
39+
}
40+
else
41+
{
42+
Point3D output;
43+
output.x = convertFromString<double>(parts[0]);
44+
output.y = convertFromString<double>(parts[1]);
45+
output.z = convertFromString<double>(parts[2]);
46+
return output;
47+
}
4448
}
45-
} // end anmespace BT
46-
49+
} // namespace BT
4750

4851
// clang-format off
4952
static const char* xml_text = R"(
@@ -59,34 +62,33 @@ static const char* xml_text = R"(
5962

6063
int main()
6164
{
62-
using namespace BT;
65+
using namespace BT;
6366

64-
MyLegacyMoveTo move_to;
67+
MyLegacyMoveTo move_to;
6568

66-
// Here we use a lambda that captures the reference of move_to
67-
auto MoveToWrapperWithLambda = [&move_to](TreeNode& parent_node) -> NodeStatus
68-
{
69-
Point3D goal;
70-
// thanks to paren_node, you can access easily the input and output ports.
71-
parent_node.getInput("goal", goal);
69+
// Here we use a lambda that captures the reference of move_to
70+
auto MoveToWrapperWithLambda = [&move_to](TreeNode& parent_node) -> NodeStatus {
71+
Point3D goal;
72+
// thanks to paren_node, you can access easily the input and output ports.
73+
parent_node.getInput("goal", goal);
7274

73-
bool res = move_to.go( goal );
74-
// convert bool to NodeStatus
75-
return res ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
76-
};
75+
bool res = move_to.go(goal);
76+
// convert bool to NodeStatus
77+
return res ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
78+
};
7779

78-
BehaviorTreeFactory factory;
80+
BehaviorTreeFactory factory;
7981

80-
// Register the lambda with BehaviorTreeFactory::registerSimpleAction
82+
// Register the lambda with BehaviorTreeFactory::registerSimpleAction
8183

82-
PortsList ports = { BT::InputPort<Point3D>("goal") };
83-
factory.registerSimpleAction("MoveTo", MoveToWrapperWithLambda, ports );
84+
PortsList ports = {BT::InputPort<Point3D>("goal")};
85+
factory.registerSimpleAction("MoveTo", MoveToWrapperWithLambda, ports);
8486

85-
auto tree = factory.createTreeFromText(xml_text);
87+
auto tree = factory.createTreeFromText(xml_text);
8688

87-
tree.tickRoot();
89+
tree.tickRoot();
8890

89-
return 0;
91+
return 0;
9092
}
9193

9294
/* Expected output:

examples/ex02_runtime_ports.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,55 @@ static const char* xml_text = R"(
1414
)";
1515
// clang-format on
1616

17-
class ThinkRuntimePort: public BT::SyncActionNode
17+
class ThinkRuntimePort : public BT::SyncActionNode
1818
{
19-
public:
20-
ThinkRuntimePort(const std::string& name,
21-
const BT::NodeConfiguration& config)
22-
: BT::SyncActionNode(name, config)
23-
{
24-
}
19+
public:
20+
ThinkRuntimePort(const std::string& name, const BT::NodeConfiguration& config) :
21+
BT::SyncActionNode(name, config)
22+
{}
2523

26-
BT::NodeStatus tick() override {
27-
setOutput("text", "The answer is 42" );
24+
BT::NodeStatus tick() override
25+
{
26+
setOutput("text", "The answer is 42");
2827
return NodeStatus::SUCCESS;
2928
}
3029
};
3130

3231
class SayRuntimePort : public BT::SyncActionNode
3332
{
34-
public:
35-
SayRuntimePort(const std::string& name, const BT::NodeConfiguration& config)
36-
: BT::SyncActionNode(name, config)
37-
{
38-
}
33+
public:
34+
SayRuntimePort(const std::string& name, const BT::NodeConfiguration& config) :
35+
BT::SyncActionNode(name, config)
36+
{}
3937

4038
// You must override the virtual function tick()
4139
BT::NodeStatus tick() override
4240
{
4341
auto msg = getInput<std::string>("message");
44-
if (!msg){
45-
throw BT::RuntimeError( "missing required input [message]: ", msg.error() );
42+
if (!msg)
43+
{
44+
throw BT::RuntimeError("missing required input [message]: ", msg.error());
4645
}
4746
std::cout << "Robot says: " << msg.value() << std::endl;
4847
return BT::NodeStatus::SUCCESS;
4948
}
5049
};
5150

52-
5351
int main()
5452
{
55-
BehaviorTreeFactory factory;
53+
BehaviorTreeFactory factory;
5654

57-
//-------- register ports that might be defined at runtime --------
58-
// more verbose way
59-
PortsList think_ports = {BT::OutputPort<std::string>("text")};
60-
factory.registerBuilder(CreateManifest<ThinkRuntimePort>("ThinkRuntimePort", think_ports),
61-
CreateBuilder<ThinkRuntimePort>());
62-
// less verbose way
63-
PortsList say_ports = {BT::InputPort<std::string>("message")};
64-
factory.registerNodeType<SayRuntimePort>("SayRuntimePort", say_ports);
55+
//-------- register ports that might be defined at runtime --------
56+
// more verbose way
57+
PortsList think_ports = {BT::OutputPort<std::string>("text")};
58+
factory.registerBuilder(
59+
CreateManifest<ThinkRuntimePort>("ThinkRuntimePort", think_ports),
60+
CreateBuilder<ThinkRuntimePort>());
61+
// less verbose way
62+
PortsList say_ports = {BT::InputPort<std::string>("message")};
63+
factory.registerNodeType<SayRuntimePort>("SayRuntimePort", say_ports);
6564

66-
auto tree = factory.createTreeFromText(xml_text);
67-
tree.tickRoot();
68-
return 0;
65+
auto tree = factory.createTreeFromText(xml_text);
66+
tree.tickRoot();
67+
return 0;
6968
}
70-
71-

examples/ex03_ncurses_manual_selector.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ static const char* xml_text = R"(
2828

2929
int main()
3030
{
31-
BehaviorTreeFactory factory;
32-
factory.registerNodeType<DummyNodes::SaySomething>("SaySomething");
31+
BehaviorTreeFactory factory;
32+
factory.registerNodeType<DummyNodes::SaySomething>("SaySomething");
3333

34-
auto tree = factory.createTreeFromText(xml_text);
35-
auto ret = tree.tickRoot();
34+
auto tree = factory.createTreeFromText(xml_text);
35+
auto ret = tree.tickRoot();
3636

37-
std::cout << "Result: " << ret << std::endl;
37+
std::cout << "Result: " << ret << std::endl;
3838

39-
return 0;
39+
return 0;
4040
}
41-
42-

0 commit comments

Comments
 (0)