world.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_WORLD_H_INCLUDED
2 #define SLAM_CTOR_CORE_WORLD_H_INCLUDED
3 
4 #include <memory>
5 
6 #include "robot_pose.h"
7 
8 template <typename SensorData>
10 public:
11  virtual void handle_sensor_data(SensorData &) = 0;
12  // No virtual dtor, since a descendant is not suppoused to be
13  // destroyed via a pointer to the class
14 };
15 
17 public:
18  virtual void on_pose_update(const RobotPose &rs) = 0;
19  // No virtual dtor, since a descendant is not suppoused to be
20  // destroyed via a pointer to the class
21 };
22 
23 template<typename MapType>
25 public:
26  virtual void on_map_update(const MapType &map) = 0;
27  // No virtual dtor, since a descendant is not suppoused to be
28  // destroyed via a pointer to the class
29 };
30 
31 template<typename MapType>
33 public:
34  void subscribe_map(std::shared_ptr<WorldMapObserver<MapType>> obs) {
35  _world_map_observers.push_back(obs);
36  }
37 
38  void subscribe_pose(std::shared_ptr<WorldPoseObserver> obs) {
39  _world_pose_observers.push_back(obs);
40  }
41 
42 protected: // methods
43 
44 #define NOTIFY_EACH_WOBSERVER(var) \
45  for (auto &raw_obs : _world_##var##_observers) { \
46  auto obs_ptr = raw_obs.lock(); \
47  if (obs_ptr) { \
48  obs_ptr->on_##var##_update(var); \
49  } \
50  }
51 
52  void notify_with_pose(const RobotPose &pose) {
54  }
55 
56  void notify_with_map(const MapType &map) {
58  }
59 
60 #undef NOTIFY_EACH_WOBSERVER
61 
62 private:
63  std::vector<std::weak_ptr<WorldMapObserver<MapType>>> _world_map_observers;
64  std::vector<std::weak_ptr<WorldPoseObserver>> _world_pose_observers;
65 };
66 
67 // TODO: try to simplify template params
68 template <typename ObservationType, typename MapT>
69 class World : public WorldObservable<MapT>
70  , public SensorDataObserver<ObservationType> {
71 public: // type aliases
72  using MapType = MapT;
73 public:
74  // data-in
75  virtual void update_robot_pose(const RobotPoseDelta& delta) {
76  _pose += delta;
77  }
78 
79  // data-out
80  virtual const World<ObservationType, MapType>& world() const { return *this; }
81  virtual const RobotPose& pose() const { return _pose; }
82  virtual const MapType& map() const = 0;
83 
84  MapType& map() {
85  return const_cast<MapType&>(
86  // TODO: try to use decltype
87  static_cast<const World<ObservationType, MapT>*>(this)->map()
88  );
89  }
90 protected:
91  virtual void handle_observation(ObservationType&) = 0;
92  virtual ~World() = default;
93 private:
95 };
96 
97 #endif
Definition: world.h:69
MapType & map()
Definition: world.h:84
#define NOTIFY_EACH_WOBSERVER(var)
Definition: world.h:44
virtual const RobotPose & pose() const
Definition: world.h:81
void subscribe_map(std::shared_ptr< WorldMapObserver< MapType >> obs)
Definition: world.h:34
RobotPose _pose
Definition: world.h:94
void subscribe_pose(std::shared_ptr< WorldPoseObserver > obs)
Definition: world.h:38
virtual void handle_sensor_data(SensorData &)=0
void notify_with_map(const MapType &map)
Definition: world.h:56
std::vector< std::weak_ptr< WorldMapObserver< MapType > > > _world_map_observers
Definition: world.h:63
virtual const World< ObservationType, MapType > & world() const
Definition: world.h:80
std::vector< std::weak_ptr< WorldPoseObserver > > _world_pose_observers
Definition: world.h:64
void notify_with_pose(const RobotPose &pose)
Definition: world.h:52
virtual void update_robot_pose(const RobotPoseDelta &delta)
Definition: world.h:75


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25