9 #include <mrpt/core/format.h> 10 #include <mrpt/core/lock_helper.h> 23 using namespace mvsim;
26 MRPT_TODO(
"Replace if-else chain with a node load registry")
29 const
std::
string& xml_text, const
std::
string& fileNameForPath)
39 auto lck = mrpt::lockHelper(m_world_cs);
46 char* input_str =
const_cast<char*
>(xml_text.c_str());
49 xml.
parse<0>(input_str);
54 static_cast<long>(std::count(input_str, e.
where<
char>(),
'\n') + 1);
56 "XML parse error (Line %u): %s", static_cast<unsigned>(line),
64 "XML parse error: No root node found (empty file?)");
65 if (0 != strcmp(root->
name(),
"mvsim_world"))
67 "XML root element is '%s' ('mvsim_world' expected)", root->
name()));
71 int version_major = 1, version_min = 0;
75 attrb_version->
value(),
"%i.%i", &version_major, &version_min);
78 "Error parsing version attribute: '%s' ('%%i.%%i' " 80 attrb_version->
value()));
89 if (!strcmp(node->
name(),
"element"))
92 m_world_elements.emplace_back(e);
93 m_simulableObjects.insert(
94 m_simulableObjects.end(),
96 e->getName(), std::dynamic_pointer_cast<
Simulable>(e)));
99 else if (!strcmp(node->
name(),
"vehicle"))
103 veh->setVehicleIndex(m_vehicles.size());
106 m_vehicles.insert(VehicleList::value_type(veh->getName(), veh));
107 m_simulableObjects.insert(
108 m_simulableObjects.end(),
110 veh->getName(), std::dynamic_pointer_cast<
Simulable>(veh)));
113 else if (!strcmp(node->
name(),
"vehicle:class"))
118 else if (!strcmp(node->
name(),
"block"))
124 else if (!strcmp(node->
name(),
"block:class"))
129 else if (!strcmp(node->
name(),
"gui"))
131 m_gui_options.parse_from(*node);
134 else if (!strcmp(node->
name(),
"walls"))
136 process_load_walls(*node);
145 "[World::load_from_XML] *Warning* Ignoring " 146 "unknown XML node type '" 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)
static Ptr factory(World *parent, const rapidxml::xml_node< char > *xml_node)
bool parse_xmlnode_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
static Ptr factory(World *parent, const rapidxml::xml_node< char > *xml_node)
#define MRPT_LOG_WARN_STREAM(__CONTENTS)
static void register_block_class(const rapidxml::xml_node< char > *xml_node)
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
std::shared_ptr< Block > Ptr
MRPT_TODO("Modify ping to run on Windows + Test this")
std::shared_ptr< WorldElementBase > Ptr
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
std::shared_ptr< VehicleBase > Ptr
virtual const char * what() const
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
static void register_vehicle_class(const rapidxml::xml_node< char > *xml_node)
T root(const T v0, const T v1)
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
std::string BASE_IMPEXP trim(const std::string &str)
This file contains rapidxml printer implementation.
std::string BASE_IMPEXP extractFileDirectory(const std::string &filePath)