WorldElementBase.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2020 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>
14 #include <map>
15 #include <rapidxml.hpp>
16 #include <rapidxml_print.hpp>
17 #include <rapidxml_utils.hpp>
18 #include <sstream> // std::stringstream
19 #include <string>
20 
21 using namespace mvsim;
22 
24 
25 // Explicit registration calls seem to be one (the unique?) way to assure
26 // registration takes place:
28 {
29  static bool done = false;
30  if (done)
31  return;
32  else
33  done = true;
34 
35  REGISTER_WORLD_ELEMENT("ground_grid", GroundGrid)
36  REGISTER_WORLD_ELEMENT("occupancy_grid", OccupancyGridMap)
37  REGISTER_WORLD_ELEMENT("elevation_map", ElevationMap)
38 }
39 
41  World* parent, const rapidxml::xml_node<char>* root, const char* class_name)
42 {
44 
45  using namespace std;
46  using namespace rapidxml;
47 
48  string sName;
49  if (!root)
50  {
51  sName = string(class_name);
52  }
53  else
54  {
55  if (0 != strcmp(root->name(), "element"))
56  throw runtime_error(mrpt::format(
57  "[WorldElementBase::factory] XML root element is '%s' "
58  "('<element>' expected)",
59  root->name()));
60 
61  // Get class name:
62  const xml_attribute<>* attrib_class = root->first_attribute("class");
63  if (!attrib_class || !attrib_class->value())
64  throw runtime_error(
65  "[WorldElementBase::factory] Missing mandatory attribute "
66  "'class' in node <element>");
67 
68  sName = string(attrib_class->value());
69  }
70  auto we = classFactory_worldElements.create(sName, parent, root);
71 
72  if (!we)
73  throw runtime_error(mrpt::format(
74  "[WorldElementBase::factory] Unknown world element type '%s'",
75  root->name()));
76 
77  return we;
78 }
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)
Ch * value() const
Definition: rapidxml.hpp:692
TClassFactory_worldElements classFactory_worldElements
#define REGISTER_WORLD_ELEMENT(TEXTUAL_NAME, CLASS_NAME)
std::shared_ptr< WorldElementBase > Ptr
Ch * name() const
Definition: rapidxml.hpp:673
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
Ptr create(const std::string &class_name, ARG1 a1) const
Definition: ClassFactory.h:39
GLsizei const GLcharARB ** string
void register_all_world_elements()
This file contains rapidxml printer implementation.


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51