WorldElementBase.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 
13 
14 #include <rapidxml.hpp>
15 #include <rapidxml_utils.hpp>
16 #include <rapidxml_print.hpp>
17 
18 #include <mrpt/version.h>
19 #if MRPT_VERSION<0x199
20 #include <mrpt/utils/utils_defs.h> // mrpt::format()
21 using namespace mrpt::utils;
22 #else
23 #include <mrpt/core/format.h>
24 using namespace mrpt;
25 #endif
26 
27 #include <sstream> // std::stringstream
28 #include <map>
29 #include <string>
30 
31 using namespace mvsim;
32 
34 
35 // Explicit registration calls seem to be one (the unique?) way to assure
36 // registration takes place:
38 {
39  static bool done = false;
40  if (done)
41  return;
42  else
43  done = true;
44 
45  REGISTER_WORLD_ELEMENT("ground_grid", GroundGrid)
46  REGISTER_WORLD_ELEMENT("occupancy_grid", OccupancyGridMap)
47  REGISTER_WORLD_ELEMENT("elevation_map", ElevationMap)
48 }
49 
50 WorldElementBase* WorldElementBase::factory(
51  World* parent, const rapidxml::xml_node<char>* root, const char* class_name)
52 {
54 
55  using namespace std;
56  using namespace rapidxml;
57 
58  string sName;
59  if (!root)
60  {
61  sName = string(class_name);
62  }
63  else
64  {
65  if (0 != strcmp(root->name(), "element"))
66  throw runtime_error(
67  mrpt::format(
68  "[WorldElementBase::factory] XML root element is '%s' "
69  "('<element>' expected)",
70  root->name()));
71 
72  // Get class name:
73  const xml_attribute<>* attrib_class = root->first_attribute("class");
74  if (!attrib_class || !attrib_class->value())
75  throw runtime_error(
76  "[WorldElementBase::factory] Missing mandatory attribute "
77  "'class' in node <element>");
78 
79  sName = string(attrib_class->value());
80  }
81  WorldElementBase* we =
82  classFactory_worldElements.create(sName, parent, root);
83 
84  if (!we)
85  throw runtime_error(
86  mrpt::format(
87  "[WorldElementBase::factory] Unknown world element type '%s'",
88  root->name()));
89 
90  return we;
91 }
This file contains rapidxml parser and DOM implementation.
Ch * value() const
Definition: rapidxml.hpp:692
TClassFactory_worldElements classFactory_worldElements
#define REGISTER_WORLD_ELEMENT(TEXTUAL_NAME, CLASS_NAME)
CLASS * create(const std::string &class_name, ARG1 a1) const
Definition: ClassFactory.h:36
Ch * name() const
Definition: rapidxml.hpp:673
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
void register_all_world_elements()
This file contains rapidxml printer implementation.


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