11 #if MRPT_VERSION<0x199 12 #include <mrpt/utils/utils_defs.h> 14 #include <mrpt/core/format.h> 17 #include <mrpt/system/filesystem.h> 30 using namespace mvsim;
39 const std::string& xml_text,
const std::string& fileNameForPath)
46 mrpt::system::trim(mrpt::system::extractFileDirectory(fileNameForPath));
49 std::lock_guard<std::mutex> csl(m_world_cs);
52 this->clear_all(
false );
56 char* input_str =
const_cast<char*
>(xml_text.c_str());
59 xml.
parse<0>(input_str);
64 static_cast<long>(std::count(input_str, e.
where<
char>(),
'\n') + 1);
65 throw std::runtime_error(
67 "XML parse error (Line %u): %s", static_cast<unsigned>(line),
75 "XML parse error: No root node found (empty file?)");
76 if (0 != strcmp(root->
name(),
"mvsim_world"))
79 "XML root element is '%s' ('mvsim_world' expected)",
84 int version_major = 1, version_min = 0;
88 attrb_version->
value(),
"%i.%i", &version_major, &version_min);
92 "Error parsing version attribute: '%s' ('%%i.%%i' " 94 attrb_version->
value()));
99 std::map<std::string, TParamEntry> other_world_params;
100 other_world_params[
"gravity"] =
TParamEntry(
"%lf", &this->m_gravity);
101 other_world_params[
"simul_timestep"] =
103 other_world_params[
"b2d_vel_iters"] =
105 other_world_params[
"b2d_pos_iters"] =
114 if (!strcmp(node->
name(),
"element"))
117 this->m_world_elements.push_back(we);
120 else if (!strcmp(node->
name(),
"vehicle"))
126 MRPT_TODO(
"Check for duplicated names")
127 m_vehicles.insert(TListVehicles::value_type(veh->
getName(), veh));
130 else if (!strcmp(node->
name(),
"vehicle:class"))
135 else if (!strcmp(node->
name(),
"block"))
142 m_blocks.insert(TListBlocks::value_type(block->
getName(), block));
145 else if (!strcmp(node->
name(),
"block:class"))
150 else if (!strcmp(node->
name(),
"gui"))
152 m_gui_options.parse_from(*node);
160 std::cerr <<
"[World::load_from_XML] *Warning* Ignoring " 161 "unknown XML node type '" 162 << node->
name() <<
"'\n";
This file contains rapidxml parser and DOM implementation.
static WorldElementBase * factory(World *parent, const rapidxml::xml_node< char > *xml_node, const char *class_name=NULL)
const std::string & getName() const
bool parse_xmlnode_as_param(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > ¶ms, const char *function_name_context="")
const std::string & getName() const
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
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)
void load_from_XML(const std::string &xml_text, const std::string &fileNameForPath=std::string("."))
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
static Block * factory(World *parent, const rapidxml::xml_node< char > *xml_node)
void setBlockIndex(size_t idx)
void setVehicleIndex(size_t idx)
This file contains rapidxml printer implementation.
static VehicleBase * factory(World *parent, const rapidxml::xml_node< char > *xml_node)