Skip to content

Commit 7d8c173

Browse files
author
Davide Faconti
committed
moving to C++14... deal with it
1 parent e282af2 commit 7d8c173

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 2.8.12) # version on Ubuntu Trusty
22
project(behaviortree_cpp_v3)
33

44
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
5-
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD 14)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
else()
8-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
8+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
99
endif()
1010

1111
if(MSVC)

docs/tutorial_08_additional_args.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,12 @@ int main()
115115
NodeBuilder builder_A =
116116
[](const std::string& name, const NodeConfiguration& config)
117117
{
118-
auto ptr = new Action_A(name, config, 42, 3.14, "hello world")
119-
return std::unique_ptr<Action_A>( ptr );
118+
return std::make_unique<Action_A>( name, config, 42, 3.14, "hello world" );
120119
};
121120

122-
// You may create manifest_A by hand, but in this case we can use a
123-
// convenient helper function called BehaviorTreeFactory::buildManifest
124-
auto manifest_A = BehaviorTreeFactory::buildManifest<Action_A>("Action_A");
125-
126-
// BehaviorTreeFactory::registerBuilder is the more general way to
121+
// BehaviorTreeFactory::registerBuilder is a more general way to
127122
// register a custom node.
128-
factory.registerBuilder( manifest_A, builder_A);
123+
factory.registerBuilder<Action_A>( "Action_A", builder_A);
129124

130125
// The regitration of Action_B is done as usual, but remember
131126
// that we still need to call Action_B::init()

examples/t08_additional_node_args.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,12 @@ int main()
8888
// Using lambdas or std::bind, we can easily "inject" additional arguments.
8989
NodeBuilder builder_A = [](const std::string& name, const NodeConfiguration& config)
9090
{
91-
return std::unique_ptr<Action_A>( new Action_A(name, config, 42, 3.14, "hello world") );
91+
return std::make_unique<Action_A>( name, config, 42, 3.14, "hello world" );
9292
};
9393

94-
// You may create manifest_A by hand, but in this case we can use a convenient helper function
95-
// called BehaviorTreeFactory::buildManifest
96-
TreeNodeManifest manifest_A = BehaviorTreeFactory::buildManifest<Action_A>("Action_A");
97-
9894
// BehaviorTreeFactory::registerBuilder is the more general way to register a custom node.
9995
// Not the most user friendly, but definitely the most flexible one.
100-
factory.registerBuilder( manifest_A, builder_A);
96+
factory.registerBuilder<Action_A>( "Action_A", builder_A);
10197

10298
// The regitration of Action_B is done as usual, but we still need to call Action_B::init()
10399
factory.registerNodeType<Action_B>( "Action_B" );

include/behaviortree_cpp/bt_factory.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ class BehaviorTreeFactory
9595
/// The most generic way to register your own builder.
9696
void registerBuilder(const TreeNodeManifest& manifest, const NodeBuilder& builder);
9797

98+
template <typename T>
99+
void registerBuilder(const std::string& ID, const NodeBuilder& builder )
100+
{
101+
auto manifest = BehaviorTreeFactory::buildManifest<T>(ID);
102+
registerBuilder(manifest, builder);
103+
}
104+
98105
/**
99106
* @brief registerSimpleAction help you register nodes of type SimpleActionNode.
100107
*
@@ -244,9 +251,9 @@ class BehaviorTreeFactory
244251
config.output_ports.empty() &&
245252
has_default_constructor<T>::value)
246253
{
247-
return std::unique_ptr<TreeNode>(new T(name));
254+
return std::make_unique<T>(name);
248255
}
249-
return std::unique_ptr<TreeNode>(new T(name, config));
256+
return std::make_unique<T>(name, config);
250257
};
251258
}
252259

src/bt_factory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void BehaviorTreeFactory::registerSimpleCondition(const std::string& ID,
8282
PortsList ports)
8383
{
8484
NodeBuilder builder = [tick_functor, ID](const std::string& name, const NodeConfiguration& config) {
85-
return std::unique_ptr<TreeNode>(new SimpleConditionNode(name, tick_functor, config));
85+
return std::make_unique<SimpleConditionNode>(name, tick_functor, config);
8686
};
8787

8888
TreeNodeManifest manifest = { NodeType::CONDITION, ID, std::move(ports) };
@@ -94,7 +94,7 @@ void BehaviorTreeFactory::registerSimpleAction(const std::string& ID,
9494
PortsList ports)
9595
{
9696
NodeBuilder builder = [tick_functor, ID](const std::string& name, const NodeConfiguration& config) {
97-
return std::unique_ptr<TreeNode>(new SimpleActionNode(name, tick_functor, config));
97+
return std::make_unique<SimpleActionNode>(name, tick_functor, config);
9898
};
9999

100100
TreeNodeManifest manifest = { NodeType::ACTION, ID, std::move(ports) };
@@ -106,7 +106,7 @@ void BehaviorTreeFactory::registerSimpleDecorator(const std::string& ID,
106106
PortsList ports)
107107
{
108108
NodeBuilder builder = [tick_functor, ID](const std::string& name, const NodeConfiguration& config) {
109-
return std::unique_ptr<TreeNode>(new SimpleDecoratorNode(name, tick_functor, config));
109+
return std::make_unique<SimpleDecoratorNode>(name, tick_functor, config);
110110
};
111111

112112
TreeNodeManifest manifest = { NodeType::DECORATOR, ID, std::move(ports) };

src/xml_parsing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement *element,
577577
child_node = factory.instantiateTreeNode(instance_name, ID, config);
578578
}
579579
else if( tree_roots.count(ID) != 0) {
580-
child_node = std::unique_ptr<TreeNode>( new DecoratorSubtreeNode(instance_name) );
580+
child_node = std::make_unique<DecoratorSubtreeNode>( instance_name );
581581
}
582582
else{
583583
throw RuntimeError( ID, " is not a registered node, nor a Subtree");

0 commit comments

Comments
 (0)