Vrep.hpp
Go to the documentation of this file.
1 #ifndef GRL_VREP_HPP_
2 #define GRL_VREP_HPP_
3 
4 #include <string>
5 #include <boost/range/algorithm/transform.hpp>
6 #include "v_repLib.h"
7 
8 namespace grl { namespace vrep {
9 
10 int getHandle(const std::string& param)
11 {
12  int handle = simGetObjectHandle( param.c_str() );
13  if(handle == -1){
14  BOOST_THROW_EXCEPTION(std::runtime_error(std::string("getHandleFromParam: Handle ") + param + " is not valid. Make sure the object you are looking for actually exists."));
15  }
16  return handle;
17 }
18 
19 template<typename SinglePassRange, typename OutputIterator>
20 OutputIterator getHandles(const SinglePassRange inputRange, OutputIterator out)
21 {
22 return boost::range::transform(
23  inputRange,
24  out,
25  [](const std::string& element)
26  {
27  return getHandle(element);
28  }
29  );
30 }
31 
32 template<std::size_t I, typename Param>
33 int getHandleFromParam(const Param& params_){
34  std::string param(std::get<I> (params_).c_str());
35  return getHandle(param);
36 };
37 
38 /// @param params_ Params range of handles such as std::vector<std::String>
39 template<std::size_t I, typename Params, typename OutputIterator>
40 OutputIterator getHandleFromParam(const Params params_, OutputIterator out){
41  auto& inputRange = std::get<I>(params_);
42  return getHandles(inputRange,out);
43 }
44 
45 }} // grl::vrep
46 
47 #endif
int getHandleFromParam(const Param &params_)
Definition: Vrep.hpp:33
int getHandle(const std::string &param)
Definition: Vrep.hpp:10
ptrSimGetObjectHandle simGetObjectHandle
Definition: v_repLib.cpp:62
OutputIterator getHandles(const SinglePassRange inputRange, OutputIterator out)
Definition: Vrep.hpp:20