LEMUR Packages: ompl_lemur or_lemur pr_bgl prpy_lemur
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Groups Pages
rvstate_map_string_adaptor.h
Go to the documentation of this file.
1 
7 namespace ompl_lemur
8 {
9 
10 // treat ompl state values as space-separated strings
11 // when putting, allocs a new state (does not free existing!)
12 template <class StateMap>
14 {
15 public:
16  typedef boost::read_write_property_map_tag category;
17  typedef typename boost::property_traits<StateMap>::key_type key_type;
18  typedef std::string value_type;
19  typedef std::string reference;
20  const StateMap state_map;
22  const unsigned int dim;
23  rvstate_map_string_adaptor(StateMap state_map, ompl::base::RealVectorStateSpace * rvspace):
24  state_map(state_map), rvspace(rvspace), dim(rvspace->getDimension())
25  {
26  }
27 };
28 
29 template <class StateMap>
30 inline std::string
31 get(const rvstate_map_string_adaptor<StateMap> & adaptor,
32  const typename rvstate_map_string_adaptor<StateMap>::key_type & k)
33 {
35  = (ompl::base::RealVectorStateSpace::StateType *)get(adaptor.state_map, k);
36  if (!rvstate)
37  return std::string();
38  std::string s;
39  for (unsigned int ui=0; ui<adaptor.dim; ui++)
40  {
41  if (ui) s += " ";
42  std::string component_repr;
43  pr_bgl::stringify_from_x(component_repr, rvstate->values[ui]);
44  s += component_repr;
45  }
46  return s;
47 }
48 
49 template <class StateMap>
50 inline void
51 put(const rvstate_map_string_adaptor<StateMap> & adaptor,
52  const typename rvstate_map_string_adaptor<StateMap>::key_type & k,
53  const std::string s)
54 {
56  if (s.length() == 0)
57  {
58  rvstate = 0;
59  }
60  else
61  {
62  rvstate = (ompl::base::RealVectorStateSpace::StateType *)adaptor.rvspace->allocState();
63  std::stringstream ss(s);
64  for (unsigned int ui=0; ui<adaptor.dim; ui++)
65  ss >> rvstate->values[ui];
66  }
67  put(adaptor.state_map, k, rvstate);
68 }
69 
70 template <class StateMap>
71 rvstate_map_string_adaptor<StateMap>
72 make_rvstate_map_string_adaptor(StateMap state_map, ompl::base::RealVectorStateSpace * rvspace)
73 {
74  return rvstate_map_string_adaptor<StateMap>(state_map, rvspace);
75 }
76 
77 } // namespace ompl_lemur
Definition: rvstate_map_string_adaptor.h:13
virtual unsigned int getDimension() const