c++ style / delay std::string creation in xml loading

This commit is contained in:
Dane Springmeyer 2014-10-03 16:27:24 -07:00
parent b09df2fa13
commit 2925a70046
4 changed files with 17 additions and 20 deletions

View file

@ -88,7 +88,7 @@ public:
bool is_text() const;
bool is(std::string const& name) const;
xml_node & add_child(std::string && name, unsigned line=0, bool is_text = false);
xml_node & add_child(const char * name, unsigned line=0, bool is_text = false);
void add_attribute(const char * name, const char * value);
attribute_map const& get_attributes() const;

View file

@ -154,7 +154,8 @@ private:
{
for (; attributes; attributes = attributes->next )
{
node.add_attribute((const char *)attributes->name,(const char *)attributes->children->content);
node.add_attribute(reinterpret_cast<const char *>(attributes->name),
reinterpret_cast<const char *>(attributes->children->content));
}
}
@ -166,18 +167,17 @@ private:
{
case XML_ELEMENT_NODE:
{
std::string name((const char *)cur_node->name);
xml_node &new_node = node.add_child(std::move(name), cur_node->line, false);
xml_node &new_node = node.add_child(reinterpret_cast<const char *>(cur_node->name), cur_node->line, false);
append_attributes(cur_node->properties, new_node);
populate_tree(cur_node->children, new_node);
}
break;
case XML_TEXT_NODE:
{
std::string trimmed((const char*)cur_node->content);
std::string trimmed(reinterpret_cast<const char *>(cur_node->content));
mapnik::util::trim(trimmed);
if (trimmed.empty()) break; //Don't add empty text nodes
node.add_child(std::move(trimmed), cur_node->line, true);
node.add_child(trimmed.c_str(), cur_node->line, true);
}
break;
case XML_COMMENT_NODE:

View file

@ -119,7 +119,7 @@ private:
{
case rapidxml::node_element:
{
xml_node &new_node = node.add_child((char *)cur_node->name(), 0, false);
xml_node & new_node = node.add_child(cur_node->name(), 0, false);
// Copy attributes
for (rapidxml::xml_attribute<char> *attr = cur_node->first_attribute();
attr; attr = attr->next_attribute())

View file

@ -126,10 +126,7 @@ const xml_node &xml_tree::root() const
xml_attribute::xml_attribute(const char * value_)
: value(value_),
processed(false)
{
}
processed(false) {}
node_not_found::node_not_found(std::string const& node_name)
: node_name_(node_name) {}
@ -221,9 +218,9 @@ bool xml_node::is(std::string const& name) const
return false;
}
xml_node &xml_node::add_child(std::string && name, unsigned line, bool is_text)
xml_node & xml_node::add_child(const char * name, unsigned line, bool is_text)
{
children_.emplace_back(tree_, std::move(name), line, is_text);
children_.emplace_back(tree_, name, line, is_text);
return children_.back();
}