More boostisms
authorScott Cantor <cantor.2@osu.edu>
Thu, 8 Dec 2011 05:20:11 +0000 (05:20 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 8 Dec 2011 05:20:11 +0000 (05:20 +0000)
xmltooling/AbstractAttributeExtensibleXMLObject.cpp
xmltooling/AbstractComplexElement.cpp
xmltooling/AbstractXMLObject.cpp
xmltooling/AbstractXMLObject.h
xmltooling/security/impl/InlineKeyResolver.cpp
xmltooling/util/XMLHelper.cpp

index c144fa9..1f819f6 100644 (file)
 
 #include <algorithm>
 #include <functional>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace xmltooling;
+using namespace xercesc;
+using namespace boost::lambda;
+using namespace boost;
 using namespace std;
-using xercesc::chColon;
 
-using xercesc::DOMAttr;
-using xercesc::DOMElement;
-using xercesc::XMLString;
 
 ElementExtensibleXMLObject::ElementExtensibleXMLObject()
 {
@@ -57,7 +58,7 @@ ElementProxy::~ElementProxy()
 {
 }
 
-set<QName> AttributeExtensibleXMLObject::m_idAttributeSet;
+set<xmltooling::QName> AttributeExtensibleXMLObject::m_idAttributeSet;
 
 AttributeExtensibleXMLObject::AttributeExtensibleXMLObject()
 {
@@ -67,22 +68,22 @@ AttributeExtensibleXMLObject::~AttributeExtensibleXMLObject()
 {
 }
 
-const set<QName>& AttributeExtensibleXMLObject::getRegisteredIDAttributes()
+const set<xmltooling::QName>& AttributeExtensibleXMLObject::getRegisteredIDAttributes()
 {
     return m_idAttributeSet;
 }
 
-bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const QName& name)
+bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const xmltooling::QName& name)
 {
     return m_idAttributeSet.find(name)!=m_idAttributeSet.end();
 }
 
-void AttributeExtensibleXMLObject::registerIDAttribute(const QName& name)
+void AttributeExtensibleXMLObject::registerIDAttribute(const xmltooling::QName& name)
 {
     m_idAttributeSet.insert(name);
 }
 
-void AttributeExtensibleXMLObject::deregisterIDAttribute(const QName& name)
+void AttributeExtensibleXMLObject::deregisterIDAttribute(const xmltooling::QName& name)
 {
     m_idAttributeSet.erase(name);
 }
@@ -101,7 +102,7 @@ AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const
     : AbstractXMLObject(src)
 {
     m_idAttribute = m_attributeMap.end();
-    for (map<QName,XMLCh*>::const_iterator i=src.m_attributeMap.begin(); i!=src.m_attributeMap.end(); i++) {
+    for (map<xmltooling::QName,XMLCh*>::const_iterator i = src.m_attributeMap.begin(); i != src.m_attributeMap.end(); ++i) {
         m_attributeMap[i->first] = XMLString::replicate(i->second);
     }
     if (src.m_idAttribute != src.m_attributeMap.end()) {
@@ -111,36 +112,43 @@ AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const
 
 AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject()
 {
-    for (map<QName,XMLCh*>::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++)
-        XMLString::release(&(i->second));
+    static void (*release)(XMLCh**,MemoryManager*) = &XMLString::release;
+    for_each(
+        m_attributeMap.begin(), m_attributeMap.end(),
+        lambda::bind(
+            release,
+            &lambda::bind(&map<xmltooling::QName,XMLCh*>::value_type::second, boost::ref(_1)),
+            XMLPlatformUtils::fgMemoryManager
+            )
+        );
 }
 
-const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const QName& qualifiedName) const
+const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const xmltooling::QName& qualifiedName) const
 {
-    map<QName,XMLCh*>::const_iterator i=m_attributeMap.find(qualifiedName);
-    return (i==m_attributeMap.end()) ? nullptr : i->second;
+    map<xmltooling::QName,XMLCh*>::const_iterator i = m_attributeMap.find(qualifiedName);
+    return (i != m_attributeMap.end()) ? i->second : nullptr;
 }
 
-void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID)
+void AbstractAttributeExtensibleXMLObject::setAttribute(const xmltooling::QName& qualifiedName, const XMLCh* value, bool ID)
 {
-    map<QName,XMLCh*>::iterator i=m_attributeMap.find(qualifiedName);
-    if (i!=m_attributeMap.end()) {
+    map<xmltooling::QName,XMLCh*>::iterator i=m_attributeMap.find(qualifiedName);
+    if (i != m_attributeMap.end()) {
         releaseThisandParentDOM();
         XMLString::release(&(i->second));
         if (value && *value) {
-            i->second=XMLString::replicate(value);
+            i->second = XMLString::replicate(value);
             if (ID)
-                m_idAttribute=i;
+                m_idAttribute = i;
         }
         else {
-            if (m_idAttribute==i)
-                m_idAttribute=m_attributeMap.end();
+            if (m_idAttribute == i)
+                m_idAttribute = m_attributeMap.end();
             m_attributeMap.erase(i);
         }
     }
     else if (value && *value) {
         releaseThisandParentDOM();
-        m_attributeMap[qualifiedName]=XMLString::replicate(value);
+        m_attributeMap[qualifiedName] = XMLString::replicate(value);
         if (ID)
             m_idAttribute = m_attributeMap.find(qualifiedName);
         Namespace newNamespace(qualifiedName.getNamespaceURI(), qualifiedName.getPrefix(), false, Namespace::VisiblyUsed);
@@ -148,7 +156,7 @@ void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedNa
     }
 }
 
-void AttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const QName& value)
+void AttributeExtensibleXMLObject::setAttribute(const xmltooling::QName& qualifiedName, const xmltooling::QName& value)
 {
     if (!value.hasLocalPart())
         return;
@@ -166,18 +174,18 @@ void AttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, cons
     addNamespace(newNamespace);
 }
 
-const map<QName,XMLCh*>& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const
+const map<xmltooling::QName,XMLCh*>& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const
 {
     return m_attributeMap;
 }
 const XMLCh* AbstractAttributeExtensibleXMLObject::getXMLID() const
 {
-    return (m_idAttribute == m_attributeMap.end()) ? nullptr : m_idAttribute->second;
+    return (m_idAttribute != m_attributeMap.end()) ? m_idAttribute->second : nullptr;
 }
 
 void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute)
 {
-    QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix());
+    xmltooling::QName q(attribute->getNamespaceURI(), attribute->getLocalName(), attribute->getPrefix());
     bool ID = attribute->isId() || isRegisteredIDAttribute(q);
     setAttribute(q,attribute->getNodeValue(),ID);
     if (ID) {
@@ -191,13 +199,13 @@ void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DO
 
 void AbstractAttributeExtensibleXMLObject::marshallExtensionAttributes(DOMElement* domElement) const
 {
-    for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
-        DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
+    for (map<xmltooling::QName,XMLCh*>::const_iterator i = m_attributeMap.begin(); i != m_attributeMap.end(); ++i) {
+        DOMAttr* attr = domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(), i->first.getLocalPart());
         if (i->first.hasPrefix())
             attr->setPrefix(i->first.getPrefix());
         attr->setNodeValue(i->second);
         domElement->setAttributeNodeNS(attr);
-        if (m_idAttribute==i) {
+        if (m_idAttribute == i) {
 #ifdef XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE
             domElement->setIdAttributeNode(attr, true);
 #else
index 7448602..fa1e6ef 100644 (file)
 #include "AbstractComplexElement.h"
 
 #include <algorithm>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
 
 using namespace xmltooling;
+using namespace xercesc;
+using namespace boost::lambda;
+using namespace boost;
 using namespace std;
 
-using xercesc::XMLString;
-
-namespace {
-    bool _nonnull(const XMLObject* ptr) {
-        return (ptr!=nullptr);
-    }
-}
 
 AbstractComplexElement::AbstractComplexElement()
 {
@@ -46,21 +44,27 @@ AbstractComplexElement::AbstractComplexElement()
 
 AbstractComplexElement::AbstractComplexElement(const AbstractComplexElement& src)
 {
-    for (vector<XMLCh*>::const_iterator i=src.m_text.begin(); i!=src.m_text.end(); ++i)
-        m_text.push_back(XMLString::replicate(*i));
+    static void (vector<XMLCh*>::* push_back)(XMLCh* const&) = &vector<XMLCh*>::push_back;
+    static XMLCh* (*replicate)(const XMLCh*,MemoryManager*) = &XMLString::replicate;
+
+    for_each(
+        src.m_text.begin(), src.m_text.end(),
+        lambda::bind(push_back, boost::ref(m_text), lambda::bind(replicate, _1, XMLPlatformUtils::fgMemoryManager))
+        );
 }
 
 AbstractComplexElement::~AbstractComplexElement() {
+    static void (*release)(XMLCh**,MemoryManager*) = &XMLString::release;
+
     for_each(m_children.begin(), m_children.end(), cleanup<XMLObject>());
-    for (vector<XMLCh*>::iterator i=m_text.begin(); i!=m_text.end(); ++i)
-        XMLString::release(&(*i));
+    for_each(m_text.begin(), m_text.end(), lambda::bind(release, &_1, XMLPlatformUtils::fgMemoryManager));
 }
 
 bool AbstractComplexElement::hasChildren() const
 {
     if (m_children.empty())
         return false;
-    return (find_if(m_children.begin(), m_children.end(), _nonnull) != m_children.end());
+    return (find_if(m_children.begin(), m_children.end(), (_1 != nullptr)) != m_children.end());
 }
 
 const list<XMLObject*>& AbstractComplexElement::getOrderedChildren() const
@@ -87,5 +91,5 @@ void AbstractComplexElement::setTextContent(const XMLCh* value, unsigned int pos
         m_text.push_back(nullptr);
         ++size;
     }
-    m_text[position]=prepareForAssignment(m_text[position],value);
+    m_text[position] = prepareForAssignment(m_text[position], value);
 }
index 33f6cd5..cb2d7f4 100644 (file)
@@ -59,11 +59,11 @@ void XMLObject::releaseThisAndChildrenDOM() const
 AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
     : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")),
        m_schemaLocation(nullptr), m_noNamespaceSchemaLocation(nullptr), m_nil(xmlconstants::XML_BOOL_NULL),
-        m_parent(nullptr), m_elementQname(nsURI, localName, prefix), m_typeQname(nullptr)
+        m_parent(nullptr), m_elementQname(nsURI, localName, prefix)
 {
     addNamespace(Namespace(nsURI, prefix, false, Namespace::VisiblyUsed));
     if (schemaType) {
-        m_typeQname = new QName(*schemaType);
+        m_typeQname.reset(new QName(*schemaType));
         addNamespace(Namespace(m_typeQname->getNamespaceURI(), m_typeQname->getPrefix(), false, Namespace::NonVisiblyUsed));
     }
 }
@@ -71,15 +71,13 @@ AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName,
 AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src)
     : m_namespaces(src.m_namespaces), m_log(src.m_log), m_schemaLocation(XMLString::replicate(src.m_schemaLocation)),
         m_noNamespaceSchemaLocation(XMLString::replicate(src.m_noNamespaceSchemaLocation)), m_nil(src.m_nil),
-        m_parent(nullptr), m_elementQname(src.m_elementQname), m_typeQname(nullptr)
+        m_parent(nullptr), m_elementQname(src.m_elementQname),
+        m_typeQname(src.m_typeQname.get() ? new QName(*src.m_typeQname) : nullptr)
 {
-    if (src.m_typeQname)
-        m_typeQname=new QName(*src.m_typeQname);
 }
 
 AbstractXMLObject::~AbstractXMLObject()
 {
-    delete m_typeQname;
     xercesc::XMLString::release(&m_schemaLocation);
     xercesc::XMLString::release(&m_noNamespaceSchemaLocation);
 }
@@ -168,7 +166,7 @@ void AbstractXMLObject::removeNamespace(const Namespace& ns)
 
 const QName* AbstractXMLObject::getSchemaType() const
 {
-    return m_typeQname;
+    return m_typeQname.get();
 }
 
 const XMLCh* AbstractXMLObject::getXMLID() const
index 946b167..49a0bbf 100644 (file)
@@ -190,7 +190,7 @@ namespace xmltooling {
     private:
         XMLObject* m_parent;
         QName m_elementQname;
-        QName* m_typeQname;
+        std::auto_ptr<QName> m_typeQname;
     };
 
 };
index 1fab308..0246cb8 100644 (file)
@@ -38,6 +38,7 @@
 #include "util/XMLConstants.h"
 #include "validation/ValidatorSuite.h"
 
+#include <boost/iterator/indirect_iterator.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xsec/dsig/DSIGKeyInfoX509.hpp>
 #include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
@@ -54,6 +55,7 @@ using namespace xmlsignature;
 using namespace xmltooling::logging;
 using namespace xmltooling;
 using namespace xercesc;
+using namespace boost;
 using namespace std;
 
 namespace xmltooling {
@@ -203,10 +205,11 @@ void InlineCredential::resolve(const KeyInfo* keyInfo, int types, bool followRef
     const XMLCh* n;
     char* kn;
     const vector<KeyName*>& knames=keyInfo->getKeyNames();
-    for (vector<KeyName*>::const_iterator kn_i=knames.begin(); kn_i!=knames.end(); ++kn_i) {
-        n=(*kn_i)->getName();
+    for (indirect_iterator<vector<KeyName*>::const_iterator> kn_i = make_indirect_iterator(knames.begin());
+            kn_i != make_indirect_iterator(knames.end()); ++kn_i) {
+        n = kn_i->getName();
         if (n && *n) {
-            kn=toUTF8(n);
+            kn = toUTF8(n);
             m_keyNames.insert(kn);
             delete[] kn;
         }
@@ -249,10 +252,11 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo, bool followRefs)
 
     // Check for ds:KeyValue
     const vector<KeyValue*>& keyValues = keyInfo->getKeyValues();
-    for (vector<KeyValue*>::const_iterator i = keyValues.begin(); i != keyValues.end(); ++i) {
+    for (indirect_iterator<vector<KeyValue*>::const_iterator> i = make_indirect_iterator(keyValues.begin());
+            i != make_indirect_iterator(keyValues.end()); ++i) {
         try {
-            SchemaValidators.validate(*i);    // see if it's a "valid" key
-            RSAKeyValue* rsakv = (*i)->getRSAKeyValue();
+            SchemaValidators.validate(*(i.base()));    // see if it's a "valid" key
+            RSAKeyValue* rsakv = i->getRSAKeyValue();
             if (rsakv) {
                 log.debug("resolving ds:RSAKeyValue");
                 auto_ptr_char mod(rsakv->getModulus()->getValue());
@@ -263,7 +267,7 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo, bool followRefs)
                 m_key = rsa.release();
                 return true;
             }
-            DSAKeyValue* dsakv = (*i)->getDSAKeyValue();
+            DSAKeyValue* dsakv = i->getDSAKeyValue();
             if (dsakv) {
                 log.debug("resolving ds:DSAKeyValue");
                 auto_ptr<XSECCryptoKeyDSA> dsa(XSECPlatformUtils::g_cryptoProvider->keyDSA());
@@ -285,7 +289,7 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo, bool followRefs)
                 return true;
             }
 #ifdef XMLTOOLING_XMLSEC_ECC
-            ECKeyValue* eckv = (*i)->getECKeyValue();
+            ECKeyValue* eckv = i->getECKeyValue();
             if (eckv && eckv->getNamedCurve() && eckv->getPublicKey()) {
                 log.warn("resolving ds11:ECKeyValue");
                 auto_ptr<XSECCryptoKeyEC> ec(XSECPlatformUtils::g_cryptoProvider->keyEC());
@@ -313,9 +317,10 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo, bool followRefs)
 
     // Check for ds11:DEREncodedKeyValue
     const vector<DEREncodedKeyValue*>& derValues = keyInfo->getDEREncodedKeyValues();
-    for (vector<DEREncodedKeyValue*>::const_iterator j = derValues.begin(); j != derValues.end(); ++j) {
+    for (indirect_iterator<vector<DEREncodedKeyValue*>::const_iterator> j = make_indirect_iterator(derValues.begin());
+            j != make_indirect_iterator(derValues.end()); ++j) {
         log.debug("resolving ds11:DEREncodedKeyValue");
-        m_key = SecurityHelper::fromDEREncoding((*j)->getValue());
+        m_key = SecurityHelper::fromDEREncoding(j->getValue());
         if (m_key)
             return true;
         log.warn("failed to resolve ds11:DEREncodedKeyValue");
@@ -327,8 +332,9 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo, bool followRefs)
         const XMLCh* fragID=nullptr;
         const XMLObject* treeRoot=nullptr;
         const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
-        for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
-            fragID = (*ref)->getURI();
+        for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+                ref != make_indirect_iterator(refs.end()); ++ref) {
+            fragID = ref->getURI();
             if (!fragID || *fragID != chPound || !*(fragID+1)) {
                 log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
                 continue;
@@ -357,11 +363,12 @@ bool InlineCredential::resolveCerts(const KeyInfo* keyInfo, bool followRefs)
 
     // Check for ds:X509Data
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
-    for (vector<X509Data*>::const_iterator j=x509Datas.begin(); m_xseccerts.empty() && j!=x509Datas.end(); ++j) {
+    for (vector<X509Data*>::const_iterator j = x509Datas.begin(); m_xseccerts.empty() && j != x509Datas.end(); ++j) {
         const vector<X509Certificate*> x509Certs=const_cast<const X509Data*>(*j)->getX509Certificates();
-        for (vector<X509Certificate*>::const_iterator k=x509Certs.begin(); k!=x509Certs.end(); ++k) {
+        for (indirect_iterator<vector<X509Certificate*>::const_iterator> k = make_indirect_iterator(x509Certs.begin());
+                k != make_indirect_iterator(x509Certs.end()); ++k) {
             try {
-                auto_ptr_char x((*k)->getValue());
+                auto_ptr_char x(k->getValue());
                 if (!x.get()) {
                     log.warn("skipping empty ds:X509Certificate");
                 }
@@ -387,8 +394,9 @@ bool InlineCredential::resolveCerts(const KeyInfo* keyInfo, bool followRefs)
         const XMLCh* fragID=NULL;
         const XMLObject* treeRoot=NULL;
         const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
-        for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
-            fragID = (*ref)->getURI();
+        for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+                ref != make_indirect_iterator(refs.end()); ++ref) {
+            fragID = ref->getURI();
             if (!fragID || *fragID != chPound || !*(fragID+1)) {
                 log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
                 continue;
@@ -421,9 +429,10 @@ bool InlineCredential::resolveCRLs(const KeyInfo* keyInfo, bool followRefs)
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
     for (vector<X509Data*>::const_iterator j=x509Datas.begin(); j!=x509Datas.end(); ++j) {
         const vector<X509CRL*> x509CRLs=const_cast<const X509Data*>(*j)->getX509CRLs();
-        for (vector<X509CRL*>::const_iterator k=x509CRLs.begin(); k!=x509CRLs.end(); ++k) {
+        for (indirect_iterator<vector<X509CRL*>::const_iterator> k = make_indirect_iterator(x509CRLs.begin());
+                k != make_indirect_iterator(x509CRLs.end()); ++k) {
             try {
-                auto_ptr_char x((*k)->getValue());
+                auto_ptr_char x(k->getValue());
                 if (!x.get()) {
                     log.warn("skipping empty ds:X509CRL");
                 }
@@ -449,8 +458,9 @@ bool InlineCredential::resolveCRLs(const KeyInfo* keyInfo, bool followRefs)
         const XMLCh* fragID=NULL;
         const XMLObject* treeRoot=NULL;
         const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
-        for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
-            fragID = (*ref)->getURI();
+        for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+                ref != make_indirect_iterator(refs.end()); ++ref) {
+            fragID = ref->getURI();
             if (!fragID || *fragID != chPound || !*(fragID+1)) {
                 log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
                 continue;
index f257b8c..be7401d 100644 (file)
 #include "util/XMLHelper.h"
 #include "util/XMLConstants.h"
 
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/if.hpp>
+#include <boost/lambda/lambda.hpp>
 #include <xercesc/framework/MemBufFormatTarget.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace xmltooling;
 using namespace xercesc;
+using namespace boost::lambda;
+using namespace boost;
 using namespace std;
 
 static const XMLCh type[]={chLatin_t, chLatin_y, chLatin_p, chLatin_e, chNull };
@@ -77,7 +82,7 @@ DOMAttr* XMLHelper::getIdAttribute(const DOMElement* domElement)
     
     DOMNamedNodeMap* attributes = domElement->getAttributes();
     DOMAttr* attribute;
-    for(XMLSize_t i = 0; i < attributes->getLength(); i++) {
+    for(XMLSize_t i = 0; i < attributes->getLength(); ++i) {
         attribute = static_cast<DOMAttr*>(attributes->item(i));
         if(attribute->isId()) {
             return attribute;
@@ -94,7 +99,7 @@ const XMLObject* XMLHelper::getXMLObjectById(const XMLObject& tree, const XMLCh*
     
     const XMLObject* ret;
     const list<XMLObject*>& children = tree.getOrderedChildren();
-    for (list<XMLObject*>::const_iterator i=children.begin(); i!=children.end(); ++i) {
+    for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
         if (*i) {
             ret = getXMLObjectById(*(*i), id);
             if (ret)
@@ -109,10 +114,10 @@ XMLObject* XMLHelper::getXMLObjectById(XMLObject& tree, const XMLCh* id)
 {
     if (XMLString::equals(id, tree.getXMLID()))
         return &tree;
-    
+
     XMLObject* ret;
     const list<XMLObject*>& children = tree.getOrderedChildren();
-    for (list<XMLObject*>::const_iterator i=children.begin(); i!=children.end(); ++i) {
+    for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
         if (*i) {
             ret = getXMLObjectById(*(*i), id);
             if (ret)
@@ -126,11 +131,10 @@ XMLObject* XMLHelper::getXMLObjectById(XMLObject& tree, const XMLCh* id)
 void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& prefixes)
 {
     map<xstring,xstring> child_prefixes;
-    const list<XMLObject*>& children = tree.getOrderedChildren();
-    for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
-        if (*i)
-            getNonVisiblyUsedPrefixes(*(*i), child_prefixes);
-    }
+    for_each(
+        tree.getOrderedChildren().begin(), tree.getOrderedChildren().end(),
+        if_(_1 != nullptr)[lambda::bind(&getNonVisiblyUsedPrefixes, boost::ref(*_1), boost::ref(child_prefixes))]
+        );
     const set<Namespace>& nsset = tree.getNamespaces();
     for (set<Namespace>::const_iterator ns = nsset.begin(); ns != nsset.end(); ++ns) {
         // Check for xmlns:xml.