WorldElementBase.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2023 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mrpt/core/format.h>
18 
19 #include <map>
20 #include <rapidxml.hpp>
21 #include <rapidxml_print.hpp>
22 #include <rapidxml_utils.hpp>
23 #include <sstream> // std::stringstream
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 
40  REGISTER_WORLD_ELEMENT("ground_grid", GroundGrid)
41  REGISTER_WORLD_ELEMENT("occupancy_grid", OccupancyGridMap)
42  REGISTER_WORLD_ELEMENT("elevation_map", ElevationMap)
43  REGISTER_WORLD_ELEMENT("horizontal_plane", HorizontalPlane)
44  REGISTER_WORLD_ELEMENT("vertical_plane", VerticalPlane)
45  REGISTER_WORLD_ELEMENT("pointcloud", PointCloud)
47 }
48 
50  World* parent, const rapidxml::xml_node<char>* root, const char* class_name)
51 {
53 
54  using namespace std;
55  using namespace rapidxml;
56 
57  string sName;
58  if (!root)
59  {
60  sName = string(class_name);
61  }
62  else
63  {
64  if (0 != strcmp(root->name(), "element"))
65  throw runtime_error(mrpt::format(
66  "[WorldElementBase::factory] XML root element is '%s' "
67  "('<element>' expected)",
68  root->name()));
69 
70  // Get class name:
71  const xml_attribute<>* attrib_class = root->first_attribute("class");
72  if (!attrib_class || !attrib_class->value())
73  throw runtime_error(
74  "[WorldElementBase::factory] Missing mandatory attribute "
75  "'class' in node <element>");
76 
77  sName = string(attrib_class->value());
78  }
79  auto we = classFactory_worldElements.create(sName, parent, root);
80 
81  if (!we)
82  throw runtime_error(mrpt::format(
83  "[WorldElementBase::factory] Unknown world element type '%s'",
84  root ? root->name() : "(root=nullptr)"));
85 
86  return we;
87 }
This file contains rapidxml parser and DOM implementation.
static Ptr factory(World *parent, const rapidxml::xml_node< char > *xml_node, const char *class_name=nullptr)
TClassFactory_worldElements classFactory_worldElements
Ch * name() const
Definition: rapidxml.hpp:673
#define REGISTER_WORLD_ELEMENT(TEXTUAL_NAME, CLASS_NAME)
std::shared_ptr< WorldElementBase > Ptr
Ch * value() const
Definition: rapidxml.hpp:692
Ptr create(const std::string &class_name, ARG1 a1) const
Definition: ClassFactory.h:40
void register_all_world_elements()
This file contains rapidxml printer implementation.
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:22