SensorBase.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under GNU General Public License version 3 |
7  | See <http://www.gnu.org/licenses/> |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mvsim/VehicleBase.h>
12 
13 #include <rapidxml.hpp>
14 #include <rapidxml_utils.hpp>
15 #include <rapidxml_print.hpp>
16 #if MRPT_VERSION>=0x199
17 #include <mrpt/core/format.h>
18 #else
19 #include <mrpt/utils/utils_defs.h> // mrpt::format()
20 #endif
21 
22 #include <sstream> // std::stringstream
23 #include <map>
24 #include <string>
25 
26 using namespace mvsim;
27 
29 
30 // Explicit registration calls seem to be one (the unique?) way to assure
31 // registration takes place:
33 {
34  static bool done = false;
35  if (done)
36  return;
37  else
38  done = true;
39 
41 }
42 
44  : VisualObject(vehicle.getWorldObject()),
45  m_sensor_period(0.1),
46  m_vehicle(vehicle),
47  m_sensor_last_timestamp(0)
48 {
49 }
50 
53  VehicleBase& parent, const rapidxml::xml_node<char>* root)
54 {
56 
57  using namespace std;
58  using namespace rapidxml;
59 
60  if (!root) throw runtime_error("[SensorBase::factory] XML node is NULL");
61  if (0 != strcmp(root->name(), "sensor"))
62  throw runtime_error(
63  mrpt::format(
64  "[SensorBase::factory] XML root element is '%s' ('sensor' "
65  "expected)",
66  root->name()));
67 
68  // Get "class" attrib:
69  const xml_attribute<>* sensor_class = root->first_attribute("class");
70  if (!sensor_class || !sensor_class->value())
71  throw runtime_error(
72  "[VehicleBase::factory] Missing mandatory attribute 'class' in "
73  "node <sensor>");
74 
75  const string sName = string(sensor_class->value());
76 
77  // Class factory:
78  SensorBase* we = classFactory_sensors.create(sName, parent, root);
79 
80  if (!we)
81  throw runtime_error(
82  mrpt::format(
83  "[SensorBase::factory] Unknown sensor type '%s'",
84  root->name()));
85 
86  return we;
87 }
This file contains rapidxml parser and DOM implementation.
Ch * value() const
Definition: rapidxml.hpp:692
SensorBase(VehicleBase &vehicle)
Definition: SensorBase.cpp:43
CLASS * create(const std::string &class_name, ARG1 a1) const
Definition: ClassFactory.h:36
Ch * name() const
Definition: rapidxml.hpp:673
void register_all_sensors()
Definition: SensorBase.cpp:32
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
virtual ~SensorBase()
which the sensor is attached.
Definition: SensorBase.cpp:51
TClassFactory_sensors classFactory_sensors
Definition: SensorBase.cpp:28
#define REGISTER_SENSOR(TEXTUAL_NAME, CLASS_NAME)
Definition: SensorBase.h:55
static SensorBase * factory(VehicleBase &parent, const rapidxml::xml_node< char > *xml_node)
Definition: SensorBase.cpp:52
This file contains rapidxml printer implementation.


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40