14 #include <mc_rtc/config.h>
27 template<
typename... Args>
37 template<
typename T,
typename... Args>
38 struct are_strings<T, Args...> : std::integral_constant<bool, are_strings<T>::value && are_strings<Args...>::value>
51 typename std::conditional<std::is_same<std::string, T>::value,
const std::string &, std::string>::type
to_string(
54 static_assert(!std::is_integral<T>::value,
55 "Passing integral value here would create empty strings of the provided size");
74 template<
typename... Args>
78 std::unique_lock<std::mutex> guard{mtx};
84 if(rm->_canonicalParameters.empty()) { rm->_canonicalParameters = rm->_parameters; }
85 if(!rm->controlToCanonicalPostProcess)
90 if(aliases.count(name))
92 const auto & params = aliases[name];
93 if(params.size() == 1) { rm = get_robot_module_from_lib(params[0]); }
94 else if(params.size() == 2) { rm = get_robot_module_from_lib(params[0], params[1]); }
95 else if(params.size() == 3) { rm = get_robot_module_from_lib(params[0], params[1], params[2]); }
98 mc_rtc::log::error_and_throw<mc_rtc::LoaderException>(
99 "Aliases can only handle 1 to 3 parameters, {} provided ({})", params.size(),
102 rm->_parameters.resize(1);
103 rm->_parameters[0] = name;
105 else { rm = get_robot_module_from_lib(name, args...); }
116 template<
typename RetT,
typename... Args>
117 static void register_object(
const std::string & name, std::function<RetT *(
const Args &...)> callback)
119 std::unique_lock<std::mutex> guard{mtx};
121 robot_loader->register_object(name, callback);
132 std::lock_guard<std::mutex> guard{mtx};
134 robot_loader->clear();
143 std::lock_guard<std::mutex> guard{mtx};
145 return robot_loader->has_object(name) || aliases.count(name) != 0;
150 std::lock_guard<std::mutex> guard{mtx};
152 if(robot_loader) { robot_loader->set_verbosity(verbose); }
168 static void init(
bool skip_default_path =
false);
170 template<
typename... Args>
173 rm->_parameters.push_back(arg0);
174 fill_rm_parameters(rm, args...);
179 template<
typename... Args>
182 if(!robot_loader->has_object(name))
184 mc_rtc::log::error(
"Cannot load the requested robot: {}\nIt is neither a valid alias nor a known exported robot",
189 mc_rtc::log::error_and_throw<mc_rtc::LoaderException>(
"Cannot load the requested robot: {}", name);
193 rm->_parameters = {name};
194 fill_rm_parameters(rm, args...);
198 static std::unique_ptr<mc_rtc::ObjectLoader<mc_rbdyn::RobotModule>> robot_loader;
199 static bool verbose_;
200 static std::mutex mtx;
201 static std::map<std::string, std::vector<std::string>> aliases;
#define MC_RBDYN_DLLAPI
Definition: api.h:50
ltdl wrapper for mc_rtc purpose
std::conditional< std::is_same< std::string, T >::value, const std::string &, std::string >::type to_string(const T &value)
Definition: RobotLoader.h:51
Definition: generic_gripper.h:15
std::shared_ptr< RobotModule > RobotModulePtr
Definition: RobotModule.h:629
std::string to_string(const Container &c, const std::string &delimiter=", ")
Definition: io_utils.h:31
void info(Args &&... args)
Definition: logging.h:75
void error_and_throw(Args &&... args)
Definition: logging.h:47
void error(Args &&... args)
Definition: logging.h:63
Load RobotModule instances from shared libraries.
Definition: RobotLoader.h:65
static RobotModulePtr get_robot_module(const std::vector< std::string > &args)
static void register_object(const std::string &name, std::function< RetT *(const Args &...)> callback)
Definition: RobotLoader.h:117
static bool has_robot(const std::string &name)
Definition: RobotLoader.h:141
static void update_robot_module_path(const std::vector< std::string > &paths)
static void set_verbosity(bool verbose)
Definition: RobotLoader.h:148
static void load_aliases(const std::string &fname)
static void clear()
Definition: RobotLoader.h:130
static std::vector< std::string > available_robots()
static mc_rbdyn::RobotModulePtr get_robot_module(const std::string &name, const Args &... args)
Definition: RobotLoader.h:75
Definition: RobotLoader.h:29