39 #include <boost/algorithm/string.hpp> 53 std::list<std::string> list_string;
54 std::string delim(
"/");
55 boost::split(list_string, name, boost::is_any_of(delim));
57 if (list_string.size() > 0) {
58 list_string.pop_back();
60 return boost::algorithm::join(list_string,
"/");
65 ros::init(argc, argv,
"standalone_complexed_nodelet");
70 std::vector<std::string> candidate_root;
71 candidate_root.push_back(
"nodelets");
73 private_nh.
param(
"candidate_num", candidate_num, 100);
74 for (
size_t i = 0; i < candidate_num; i++) {
75 candidate_root.push_back((boost::format(
"nodelets_%lu") % i).
str());
77 for (
size_t i_candidate = 0; i_candidate < candidate_root.size(); i_candidate++) {
78 std::string root_name = candidate_root[i_candidate];
79 if (private_nh.
hasParam(root_name)) {
81 private_nh.
param(root_name, nodelets_values, nodelets_values);
83 for (
size_t i_nodelet = 0; i_nodelet < nodelets_values.
size(); i_nodelet++) {
84 ROS_INFO(
"i_nodelet %lu", i_nodelet);
87 std::string name,
type;
89 if (onenodelet_param.
hasMember(
"if") && !(bool)onenodelet_param[
"if"]) {
92 if (onenodelet_param.
hasMember(
"unless") && (bool)onenodelet_param[
"unless"]) {
96 name = nh.
resolveName((std::string)onenodelet_param[
"name"]);
99 ROS_FATAL(
"element ~nodelets should have name field");
102 if (onenodelet_param.
hasMember(
"type")) {
103 type = (std::string)onenodelet_param[
"type"];
106 ROS_FATAL(
"element ~nodelets should have type field");
109 if (onenodelet_param.
hasMember(
"remappings")) {
111 = onenodelet_param[
"remappings"];
113 for (
size_t remappings_i = 0; remappings_i < remappings_params.
size(); remappings_i++) {
116 if (remapping_element_param.
hasMember(
"from") && remapping_element_param.
hasMember(
"to")) {
117 std::string from = (std::string)remapping_element_param[
"from"];
118 std::string to = (std::string)remapping_element_param[
"to"];
119 if (from.size() > 0 && from[0] ==
'~') {
121 from = nodelet_private_nh.
resolveName(from.substr(1, from.size() - 1));
127 if (to.size() > 0 && to[0] ==
'~') {
129 to = nodelet_private_nh.
resolveName(to.substr(1, to.size() - 1));
135 ROS_INFO(
"remapping: %s => %s", from.c_str(), to.c_str());
136 remappings[from] = to;
139 ROS_FATAL(
"remappings parameter requires from and to fields");
144 ROS_FATAL(
"remappings should be an array");
150 ROS_FATAL(
"remappings should be an array");
156 if (!manager.
load(name, type, remappings, my_argv)) {
157 ROS_ERROR(
"Failed to load nodelet [%s -- %s]", name.c_str(), type.c_str());
160 ROS_INFO(
"Succeeded to load nodelet [%s -- %s]", name.c_str(), type.c_str());
164 ROS_FATAL(
"element ~nodelets should be a dictionay");
175 ROS_INFO(
"done reading parmaeters");
177 ROS_INFO(
"loaded nodelets: %lu", loaded_nodelets.size());
178 for (
size_t i = 0; i < loaded_nodelets.size(); i++) {
179 ROS_INFO(
"loaded nodelet: %s", loaded_nodelets[i].c_str());
bool load(const std::string &name, const std::string &type, const M_string &remappings, const V_string &my_argv)
std::string resolveName(const std::string &name, bool remap=true) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::vector< std::string > listLoadedNodelets()
Type const & getType() const
ROSCPP_DECL void spin(Spinner &spinner)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool hasMember(const std::string &name) const
bool hasParam(const std::string &key) const
int main(int argc, char **argv)
std::vector< std::string > V_string
std::map< std::string, std::string > M_string
std::string parentName(const std::string &name)