std:vector trumps std::list speed in all aspects: traversal, insertion
(at end) and Deletion. ..but we'll have to be careful about iterators..
#include <unordered_map>
#include <cstdio>
#include <cstdarg>
#include <unordered_map>
#include <cstdio>
#include <cstdarg>
class XMLNode;
class XMLProperty;
class XMLNode;
class XMLProperty;
-typedef std::list<XMLNode *> XMLNodeList;
-typedef std::list<boost::shared_ptr<XMLNode> > XMLSharedNodeList;
-typedef XMLNodeList::iterator XMLNodeIterator;
-typedef XMLNodeList::const_iterator XMLNodeConstIterator;
-typedef std::list<XMLProperty*> XMLPropertyList;
-typedef XMLPropertyList::iterator XMLPropertyIterator;
-typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
+typedef std::vector<XMLNode *> XMLNodeList;
+typedef std::vector<boost::shared_ptr<XMLNode> > XMLSharedNodeList;
+typedef XMLNodeList::iterator XMLNodeIterator;
+typedef XMLNodeList::const_iterator XMLNodeConstIterator;
+typedef std::vector<XMLProperty*> XMLPropertyList;
+typedef XMLPropertyList::iterator XMLPropertyIterator;
+typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
typedef std::unordered_map<std::string, XMLProperty*> XMLPropertyMap;
class LIBPBD_API XMLTree {
typedef std::unordered_map<std::string, XMLProperty*> XMLPropertyMap;
class LIBPBD_API XMLTree {
{
if (_propmap.find(n) != _propmap.end()) {
XMLProperty* p = _propmap[n];
{
if (_propmap.find(n) != _propmap.end()) {
XMLProperty* p = _propmap[n];
+ XMLPropertyIterator i = std::find(_proplist.begin(), _proplist.end(), p);
+ if (i != _proplist.end ()) {
+ _proplist.erase (i);
+ }
delete p;
_propmap.erase(n);
}
delete p;
_propmap.erase(n);
}
XMLNode::remove_nodes(const string& n)
{
XMLNodeIterator i = _children.begin();
XMLNode::remove_nodes(const string& n)
{
XMLNodeIterator i = _children.begin();
while (i != _children.end()) {
while (i != _children.end()) {
+ i = _children.erase (i);
+ } else {
+ ++i;
XMLNode::remove_nodes_and_delete(const string& n)
{
XMLNodeIterator i = _children.begin();
XMLNode::remove_nodes_and_delete(const string& n)
{
XMLNodeIterator i = _children.begin();
while (i != _children.end()) {
while (i != _children.end()) {
if ((*i)->name() == n) {
delete *i;
if ((*i)->name() == n) {
delete *i;
+ i = _children.erase (i);
+ } else {
+ ++i;
XMLNode::remove_nodes_and_delete(const string& propname, const string& val)
{
XMLNodeIterator i = _children.begin();
XMLNode::remove_nodes_and_delete(const string& propname, const string& val)
{
XMLNodeIterator i = _children.begin();
XMLProperty* prop;
while (i != _children.end()) {
XMLProperty* prop;
while (i != _children.end()) {
prop = (*i)->property(propname);
if (prop && prop->value() == val) {
delete *i;
prop = (*i)->property(propname);
if (prop && prop->value() == val) {
delete *i;
+ i = _children.erase(i);
+ } else {
+ ++i;