Implement content cloning via macros
authorscantor <scantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Wed, 21 Dec 2011 19:34:13 +0000 (19:34 +0000)
committerscantor <scantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Wed, 21 Dec 2011 19:34:13 +0000 (19:34 +0000)
git-svn-id: https://svn.shibboleth.net/cpp-xmltooling/branches/REL_1@944 de75baf8-a10c-0410-a50a-987c0e22f00f

xmltooling/base.h
xmltooling/encryption/impl/EncryptionImpl.cpp
xmltooling/signature/impl/KeyInfoImpl.cpp
xmltooling/soap/impl/SOAPImpl.cpp

index 4e80091..0f8bf1b 100644 (file)
     }
 
 /**
+ * Implements cloning of a child attribute, for use in copy constructor or
+ * deferred clone methods.
+ *
+ * proper   the proper name of the attribute to clone
+ */
+#define IMPL_CLONE_ATTRIB(proper) \
+    set##proper(src.get##proper())
+
+/**
+ * Implements cloning of a child object, for use in copy constructor or
+ * deferred clone methods.
+ *
+ * proper   the proper name of the child object to clone
+ */
+#define IMPL_CLONE_XMLOBJECT_CHILD(proper) \
+    if (src.get##proper()) \
+        set##proper(src.get##proper()->clone())
+
+/**
+ * Implements cloning of a typed child object, for use in copy constructor or
+ * deferred clone methods.
+ *
+ * proper   the proper name of the child type to clone
+ */
+#define IMPL_CLONE_TYPED_CHILD(proper) \
+    if (src.get##proper()) \
+        set##proper(src.get##proper()->clone##proper())
+
+/**
+ * Implements cloning of an untyped child collection, for use in copy constructor or
+ * deferred clone methods.
+ */
+#define IMPL_CLONE_XMLOBJECT_CHILDREN() \
+    static void (VectorOf(XMLObject)::* XMLObject_push_back)(XMLObject* const&) = &VectorOf(XMLObject)::push_back; \
+    VectorOf(XMLObject) cXMLObject = getUnknownXMLObjects(); \
+    std::for_each( \
+        src.m_UnknownXMLObjects.begin(), src.m_UnknownXMLObjects.end(), \
+        boost::lambda::if_(boost::lambda::_1 != ((XMLObject*)nullptr)) \
+            [boost::lambda::bind(XMLObject_push_back, boost::ref(cXMLObject), boost::lambda::bind(&XMLObject::clone, boost::lambda::_1))] \
+        )
+
+/**
+ * Implements cloning of a child collection, for use in copy constructor or
+ * deferred clone methods.
+ *
+ * proper   the proper name of the child type to clone
+ */
+#define IMPL_CLONE_TYPED_CHILDREN(proper) \
+    static void (VectorOf(proper)::* proper##_push_back)(proper* const&) = &VectorOf(proper)::push_back; \
+    VectorOf(proper) c##proper = get##proper##s(); \
+    std::for_each( \
+        src.m_##proper##s.begin(), src.m_##proper##s.end(), \
+        boost::lambda::if_(boost::lambda::_1 != ((proper*)nullptr)) \
+            [boost::lambda::bind(proper##_push_back, boost::ref(c##proper), boost::lambda::bind(&proper::clone##proper, boost::lambda::_1))] \
+        )
+
+/**
+ * Implements cloning of a child collection in a foreign namespace, for use in copy constructor or
+ * deferred clone methods.
+ *
+ * proper   the proper name of the child type to clone
+ * ns       the namespace of the child type
+ */
+#define IMPL_CLONE_TYPED_FOREIGN_CHILDREN(proper,ns) \
+    static void (VectorOf(ns::proper)::* proper##_push_back)(ns::proper* const&) = &VectorOf(ns::proper)::push_back; \
+    VectorOf(ns::proper) c##proper = get##proper##s(); \
+    std::for_each( \
+        src.m_##proper##s.begin(), src.m_##proper##s.end(), \
+        boost::lambda::if_(boost::lambda::_1 != ((ns::proper*)nullptr)) \
+            [boost::lambda::bind(proper##_push_back, boost::ref(c##proper), boost::lambda::bind(&ns::proper::clone##proper, boost::lambda::_1))] \
+        )
+
+/**
  * Declares an XMLObject specialization with a simple content model and type,
  * handling it as string data.
  *
index 5e25d72..439e031 100644 (file)
 #include "signature/KeyInfo.h"
 #include "util/XMLHelper.h"
 
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/casts.hpp>
+#include <boost/lambda/if.hpp>
+#include <boost/lambda/lambda.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace xmlencryption;
@@ -86,16 +90,10 @@ namespace xmlencryption {
         EncryptionMethodImpl(const EncryptionMethodImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            setAlgorithm(src.getAlgorithm());
-            if (src.getKeySize())
-                setKeySize(src.getKeySize()->cloneKeySize());
-            if (src.getOAEPparams())
-                setOAEPparams(src.getOAEPparams()->cloneOAEPparams());
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) {
-                if (*i) {
-                    getUnknownXMLObjects().push_back((*i)->clone());
-                }
-            }
+            IMPL_CLONE_ATTRIB(Algorithm);
+            IMPL_CLONE_TYPED_CHILD(KeySize);
+            IMPL_CLONE_TYPED_CHILD(OAEPparams);
+            IMPL_CLONE_XMLOBJECT_CHILDREN();
         }
         
         IMPL_XMLOBJECT_CLONE(EncryptionMethod);
@@ -144,11 +142,7 @@ namespace xmlencryption {
             
         TransformsImpl(const TransformsImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
-            for (vector<xmlsignature::Transform*>::const_iterator i=src.m_Transforms.begin(); i!=src.m_Transforms.end(); i++) {
-                if (*i) {
-                    getTransforms().push_back((*i)->cloneTransform());
-                }
-            }
+            IMPL_CLONE_TYPED_FOREIGN_CHILDREN(Transform,xmlsignature);
         }
         
         IMPL_XMLOBJECT_CLONE(Transforms);
@@ -187,9 +181,8 @@ namespace xmlencryption {
         CipherReferenceImpl(const CipherReferenceImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            setURI(src.getURI());
-            if (src.getTransforms())
-                setTransforms(src.getTransforms()->cloneTransforms());
+            IMPL_CLONE_ATTRIB(URI);
+            IMPL_CLONE_TYPED_CHILD(Transforms);
         }
         
         IMPL_XMLOBJECT_CLONE(CipherReference);
@@ -239,10 +232,8 @@ namespace xmlencryption {
         CipherDataImpl(const CipherDataImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getCipherValue())
-                setCipherValue(src.getCipherValue()->cloneCipherValue());
-            if (src.getCipherReference())
-                setCipherReference(src.getCipherReference()->cloneCipherReference());
+            IMPL_CLONE_TYPED_CHILD(CipherValue);
+            IMPL_CLONE_TYPED_CHILD(CipherReference);
         }
         
         IMPL_XMLOBJECT_CLONE(CipherData);
@@ -285,13 +276,9 @@ namespace xmlencryption {
                     AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
             init();
-            setId(src.getId());
-            setTarget(src.getTarget());
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) {
-                if (*i) {
-                    getUnknownXMLObjects().push_back((*i)->clone());
-                }
-            }
+            IMPL_CLONE_ATTRIB(Id);
+            IMPL_CLONE_ATTRIB(Target);
+            IMPL_CLONE_XMLOBJECT_CHILDREN();
         }
         
         IMPL_XMLOBJECT_CLONE(EncryptionProperty);
@@ -353,12 +340,8 @@ namespace xmlencryption {
         EncryptionPropertiesImpl(const EncryptionPropertiesImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            setId(src.getId());
-            for (vector<EncryptionProperty*>::const_iterator i=src.m_EncryptionPropertys.begin(); i!=src.m_EncryptionPropertys.end(); i++) {
-                if (*i) {
-                    getEncryptionPropertys().push_back((*i)->cloneEncryptionProperty());
-                }
-            }
+            IMPL_CLONE_ATTRIB(Id);
+            IMPL_CLONE_TYPED_CHILDREN(EncryptionProperty);
         }
         
         IMPL_XMLOBJECT_CLONE(EncryptionProperties);
@@ -406,12 +389,8 @@ namespace xmlencryption {
         }
 
         void _clone(const ReferenceTypeImpl& src) {
-            setURI(src.getURI());
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) {
-                if (*i) {
-                    getUnknownXMLObjects().push_back((*i)->clone());
-                }
-            }
+            IMPL_CLONE_ATTRIB(URI);
+            IMPL_CLONE_XMLOBJECT_CHILDREN();
         }
         
         IMPL_XMLOBJECT_CLONE_EX(ReferenceType);
@@ -474,19 +453,17 @@ namespace xmlencryption {
             
         ReferenceListImpl(const ReferenceListImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
-            for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
-                if (*i) {
-                    DataReference* data=dynamic_cast<DataReference*>(*i);
-                    if (data) {
-                        getDataReferences().push_back(data->cloneDataReference());
-                        continue;
-                    }
-
-                    KeyReference* key=dynamic_cast<KeyReference*>(*i);
-                    if (key) {
-                        getKeyReferences().push_back(key->cloneKeyReference());
-                        continue;
-                    }
+            for (list<XMLObject*>::const_iterator i = src.m_children.begin(); i != src.m_children.end(); ++i) {
+                DataReference* data=dynamic_cast<DataReference*>(*i);
+                if (data) {
+                    getDataReferences().push_back(data->cloneDataReference());
+                    continue;
+                }
+
+                KeyReference* key=dynamic_cast<KeyReference*>(*i);
+                if (key) {
+                    getKeyReferences().push_back(key->cloneKeyReference());
+                    continue;
                 }
             }
         }
@@ -552,18 +529,14 @@ namespace xmlencryption {
         }
 
         void _clone(const EncryptedTypeImpl& src) {
-            setId(src.getId());
-            setType(src.getType());
-            setMimeType(src.getMimeType());
-            setEncoding(src.getEncoding());
-            if (src.getEncryptionMethod())
-                setEncryptionMethod(src.getEncryptionMethod()->cloneEncryptionMethod());
-            if (src.getKeyInfo())
-                setKeyInfo(src.getKeyInfo()->cloneKeyInfo());
-            if (src.getCipherData())
-                setCipherData(src.getCipherData()->cloneCipherData());
-            if (src.getEncryptionProperties())
-                setEncryptionProperties(src.getEncryptionProperties()->cloneEncryptionProperties());
+            IMPL_CLONE_ATTRIB(Id);
+            IMPL_CLONE_ATTRIB(Type);
+            IMPL_CLONE_ATTRIB(MimeType);
+            IMPL_CLONE_ATTRIB(Encoding);
+            IMPL_CLONE_TYPED_CHILD(EncryptionMethod);
+            IMPL_CLONE_TYPED_CHILD(KeyInfo);
+            IMPL_CLONE_TYPED_CHILD(CipherData);
+            IMPL_CLONE_TYPED_CHILD(EncryptionProperties);
         }
         
         IMPL_XMLOBJECT_CLONE_EX(EncryptedType);
@@ -644,11 +617,9 @@ namespace xmlencryption {
         
         void _clone(const EncryptedKeyImpl& src) {
             EncryptedTypeImpl::_clone(src);
-            setRecipient(src.getRecipient());
-            if (src.getReferenceList())
-                setReferenceList(src.getReferenceList()->cloneReferenceList());
-            if (src.getCarriedKeyName())
-                setCarriedKeyName(src.getCarriedKeyName()->cloneCarriedKeyName());
+            IMPL_CLONE_ATTRIB(Recipient);
+            IMPL_CLONE_TYPED_CHILD(ReferenceList);
+            IMPL_CLONE_TYPED_CHILD(CarriedKeyName);
         }
 
         IMPL_XMLOBJECT_CLONE_EX(EncryptedKey);
index ef7283b..df20b66 100644 (file)
 #include "signature/KeyInfo.h"
 #include "util/XMLHelper.h"
 
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/casts.hpp>
+#include <boost/lambda/if.hpp>
+#include <boost/lambda/lambda.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace xmlsignature;
@@ -96,20 +100,13 @@ namespace xmlsignature {
         DSAKeyValueImpl(const DSAKeyValueImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getP())
-                setP(src.getP()->cloneP());
-            if (src.getQ())
-                setQ(src.getQ()->cloneQ());
-            if (src.getG())
-                setG(src.getG()->cloneG());
-            if (src.getY())
-                setY(src.getY()->cloneY());
-            if (src.getJ())
-                setJ(src.getJ()->cloneJ());
-            if (src.getSeed())
-                setSeed(src.getSeed()->cloneSeed());
-            if (src.getPgenCounter())
-                setPgenCounter(src.getPgenCounter()->clonePgenCounter());
+            IMPL_CLONE_TYPED_CHILD(P);
+            IMPL_CLONE_TYPED_CHILD(Q);
+            IMPL_CLONE_TYPED_CHILD(G);
+            IMPL_CLONE_TYPED_CHILD(Y);
+            IMPL_CLONE_TYPED_CHILD(J);
+            IMPL_CLONE_TYPED_CHILD(Seed);
+            IMPL_CLONE_TYPED_CHILD(PgenCounter);
         }
                 
         IMPL_XMLOBJECT_CLONE(DSAKeyValue);
@@ -161,10 +158,8 @@ namespace xmlsignature {
         RSAKeyValueImpl(const RSAKeyValueImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getModulus())
-                setModulus(src.getModulus()->cloneModulus());
-            if (src.getExponent())
-                setExponent(src.getExponent()->cloneExponent());
+            IMPL_CLONE_TYPED_CHILD(Modulus);
+            IMPL_CLONE_TYPED_CHILD(Exponent);
         }
         
         IMPL_XMLOBJECT_CLONE(RSAKeyValue);
@@ -196,7 +191,7 @@ namespace xmlsignature {
 
         NamedCurveImpl(const NamedCurveImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src), m_URI(nullptr) {
-            setURI(src.getURI());
+            IMPL_CLONE_ATTRIB(URI);
         }
 
         IMPL_XMLOBJECT_CLONE(NamedCurve);
@@ -247,13 +242,10 @@ namespace xmlsignature {
         ECKeyValueImpl(const ECKeyValueImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            setId(src.getId());
-            if (src.getECParameters())
-                setECParameters(src.getECParameters()->clone());
-            if (src.getNamedCurve())
-                setNamedCurve(src.getNamedCurve()->cloneNamedCurve());
-            if (src.getPublicKey())
-                setPublicKey(src.getPublicKey()->clonePublicKey());
+            IMPL_CLONE_ATTRIB(Id);
+            IMPL_CLONE_XMLOBJECT_CHILD(ECParameters);
+            IMPL_CLONE_TYPED_CHILD(NamedCurve);
+            IMPL_CLONE_TYPED_CHILD(PublicKey);
         }
         
         IMPL_XMLOBJECT_CLONE(ECKeyValue);
@@ -322,14 +314,10 @@ namespace xmlsignature {
         KeyValueImpl(const KeyValueImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getDSAKeyValue())
-                setDSAKeyValue(src.getDSAKeyValue()->cloneDSAKeyValue());
-            if (src.getRSAKeyValue())
-                setRSAKeyValue(src.getRSAKeyValue()->cloneRSAKeyValue());
-            if (src.getECKeyValue())
-                setECKeyValue(src.getECKeyValue()->cloneECKeyValue());
-            if (src.getUnknownXMLObject())
-                setUnknownXMLObject(src.getUnknownXMLObject()->clone());
+            IMPL_CLONE_TYPED_CHILD(DSAKeyValue);
+            IMPL_CLONE_TYPED_CHILD(RSAKeyValue);
+            IMPL_CLONE_TYPED_CHILD(ECKeyValue);
+            IMPL_CLONE_XMLOBJECT_CHILD(UnknownXMLObject);
         }
                 
         IMPL_XMLOBJECT_CLONE(KeyValue);
@@ -372,7 +360,7 @@ namespace xmlsignature {
 
         DEREncodedKeyValueImpl(const DEREncodedKeyValueImpl& src)
                 : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src), m_Id(nullptr) {
-            setId(src.getId());
+            IMPL_CLONE_ATTRIB(Id);
         }
 
         IMPL_XMLOBJECT_CLONE(DEREncodedKeyValue);
@@ -406,18 +394,16 @@ namespace xmlsignature {
             
         TransformImpl(const TransformImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src), m_Algorithm(nullptr) {
-            setAlgorithm(src.getAlgorithm());
-            for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
+            IMPL_CLONE_ATTRIB(Algorithm);
+            for (list<XMLObject*>::const_iterator i = src.m_children.begin(); i != src.m_children.end(); ++i) {
+                XPath* x=dynamic_cast<XPath*>(*i);
+                if (x) {
+                    getXPaths().push_back(x->cloneXPath());
+                    continue;
+                }
+
                 if (*i) {
-                    XPath* x=dynamic_cast<XPath*>(*i);
-                    if (x) {
-                        getXPaths().push_back(x->cloneXPath());
-                        continue;
-                    }
-
-                    if (*i) {
-                        getUnknownXMLObjects().push_back((*i)->clone());
-                    }
+                    getUnknownXMLObjects().push_back((*i)->clone());
                 }
             }
         }
@@ -466,11 +452,7 @@ namespace xmlsignature {
             
         TransformsImpl(const TransformsImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
-            for (vector<Transform*>::const_iterator i=src.m_Transforms.begin(); i!=src.m_Transforms.end(); i++) {
-                if (*i) {
-                    getTransforms().push_back((*i)->cloneTransform());
-                }
-            }
+            IMPL_CLONE_TYPED_CHILDREN(Transform);
         }
         
         IMPL_XMLOBJECT_CLONE(Transforms);
@@ -510,10 +492,9 @@ namespace xmlsignature {
         RetrievalMethodImpl(const RetrievalMethodImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            setURI(src.getURI());
-            setType(src.getType());
-            if (src.getTransforms())
-                setTransforms(src.getTransforms()->cloneTransforms());
+            IMPL_CLONE_ATTRIB(URI);
+            IMPL_CLONE_ATTRIB(Type);
+            IMPL_CLONE_TYPED_CHILD(Transforms);
         }
         
         IMPL_XMLOBJECT_CLONE(RetrievalMethod);
@@ -566,10 +547,8 @@ namespace xmlsignature {
         X509IssuerSerialImpl(const X509IssuerSerialImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getX509IssuerName())
-                setX509IssuerName(src.getX509IssuerName()->cloneX509IssuerName());
-            if (src.getX509SerialNumber())
-                setX509SerialNumber(src.getX509SerialNumber()->cloneX509SerialNumber());
+            IMPL_CLONE_TYPED_CHILD(X509IssuerName);
+            IMPL_CLONE_TYPED_CHILD(X509SerialNumber);
         }
         
         IMPL_XMLOBJECT_CLONE(X509IssuerSerial);
@@ -601,7 +580,7 @@ namespace xmlsignature {
 
         X509DigestImpl(const X509DigestImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src), m_Algorithm(nullptr) {
-            setAlgorithm(src.getAlgorithm());
+            IMPL_CLONE_ATTRIB(Algorithm);
         }
 
         IMPL_XMLOBJECT_CLONE(X509Digest);
@@ -634,53 +613,51 @@ namespace xmlsignature {
             
         X509DataImpl(const X509DataImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
-            for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
+            for (list<XMLObject*>::const_iterator i = src.m_children.begin(); i != src.m_children.end(); ++i) {
+                X509Certificate* xcert=dynamic_cast<X509Certificate*>(*i);
+                if (xcert) {
+                    getX509Certificates().push_back(xcert->cloneX509Certificate());
+                    continue;
+                }
+
+                X509CRL* xcrl=dynamic_cast<X509CRL*>(*i);
+                if (xcrl) {
+                    getX509CRLs().push_back(xcrl->cloneX509CRL());
+                    continue;
+                }
+
+                X509SubjectName* xsn=dynamic_cast<X509SubjectName*>(*i);
+                if (xsn) {
+                    getX509SubjectNames().push_back(xsn->cloneX509SubjectName());
+                    continue;
+                }
+
+                X509IssuerSerial* xis=dynamic_cast<X509IssuerSerial*>(*i);
+                if (xis) {
+                    getX509IssuerSerials().push_back(xis->cloneX509IssuerSerial());
+                    continue;
+                }
+
+                X509SKI* xski=dynamic_cast<X509SKI*>(*i);
+                if (xski) {
+                    getX509SKIs().push_back(xski->cloneX509SKI());
+                    continue;
+                }
+
+                X509Digest* xdig=dynamic_cast<X509Digest*>(*i);
+                if (xdig) {
+                    getX509Digests().push_back(xdig->cloneX509Digest());
+                    continue;
+                }
+
+                OCSPResponse* ocsp=dynamic_cast<OCSPResponse*>(*i);
+                if (ocsp) {
+                    getOCSPResponses().push_back(ocsp->cloneOCSPResponse());
+                    continue;
+                }
+
                 if (*i) {
-                    X509Certificate* xcert=dynamic_cast<X509Certificate*>(*i);
-                    if (xcert) {
-                        getX509Certificates().push_back(xcert->cloneX509Certificate());
-                        continue;
-                    }
-
-                    X509CRL* xcrl=dynamic_cast<X509CRL*>(*i);
-                    if (xcrl) {
-                        getX509CRLs().push_back(xcrl->cloneX509CRL());
-                        continue;
-                    }
-
-                    X509SubjectName* xsn=dynamic_cast<X509SubjectName*>(*i);
-                    if (xsn) {
-                        getX509SubjectNames().push_back(xsn->cloneX509SubjectName());
-                        continue;
-                    }
-
-                    X509IssuerSerial* xis=dynamic_cast<X509IssuerSerial*>(*i);
-                    if (xis) {
-                        getX509IssuerSerials().push_back(xis->cloneX509IssuerSerial());
-                        continue;
-                    }
-
-                    X509SKI* xski=dynamic_cast<X509SKI*>(*i);
-                    if (xski) {
-                        getX509SKIs().push_back(xski->cloneX509SKI());
-                        continue;
-                    }
-
-                    X509Digest* xdig=dynamic_cast<X509Digest*>(*i);
-                    if (xdig) {
-                        getX509Digests().push_back(xdig->cloneX509Digest());
-                        continue;
-                    }
-
-                    OCSPResponse* ocsp=dynamic_cast<OCSPResponse*>(*i);
-                    if (ocsp) {
-                        getOCSPResponses().push_back(ocsp->cloneOCSPResponse());
-                        continue;
-                    }
-
-                    if (*i) {
-                        getUnknownXMLObjects().push_back((*i)->clone());
-                    }
+                    getUnknownXMLObjects().push_back((*i)->clone());
                 }
             }
         }
@@ -733,7 +710,7 @@ namespace xmlsignature {
             
         SPKIDataImpl(const SPKIDataImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
-            for (vector< pair<SPKISexp*,XMLObject*> >::const_iterator i=src.m_SPKISexps.begin(); i!=src.m_SPKISexps.end(); i++) {
+            for (vector< pair<SPKISexp*,XMLObject*> >::const_iterator i = src.m_SPKISexps.begin(); i != src.m_SPKISexps.end(); ++i) {
                 if (i->first) {
                     getSPKISexps().push_back(make_pair(i->first->cloneSPKISexp(),(i->second ? i->second->clone() : (XMLObject*)nullptr)));
                 }
@@ -805,15 +782,9 @@ namespace xmlsignature {
         PGPDataImpl(const PGPDataImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getPGPKeyID())
-                setPGPKeyID(src.getPGPKeyID()->clonePGPKeyID());
-            if (src.getPGPKeyPacket())
-                setPGPKeyPacket(src.getPGPKeyPacket()->clonePGPKeyPacket());
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) {
-                if (*i) {
-                    getUnknownXMLObjects().push_back((*i)->clone());
-                }
-            }
+            IMPL_CLONE_TYPED_CHILD(PGPKeyID);
+            IMPL_CLONE_TYPED_CHILD(PGPKeyPacket);
+            IMPL_CLONE_XMLOBJECT_CHILDREN();
         }
         
         IMPL_XMLOBJECT_CLONE(PGPData);
@@ -861,8 +832,8 @@ namespace xmlsignature {
         KeyInfoReferenceImpl(const KeyInfoReferenceImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            setId(src.getId());
-            setURI(src.getURI());
+            IMPL_CLONE_ATTRIB(Id);
+            IMPL_CLONE_ATTRIB(URI);
         }
 
         IMPL_XMLOBJECT_CLONE(KeyInfoReference);
@@ -899,66 +870,64 @@ namespace xmlsignature {
             
         KeyInfoImpl(const KeyInfoImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src), m_Id(nullptr) {
-            setId(src.getId());
-            for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
+            IMPL_CLONE_ATTRIB(Id);
+            for (list<XMLObject*>::const_iterator i = src.m_children.begin(); i != src.m_children.end(); ++i) {
+                X509Data* xd=dynamic_cast<X509Data*>(*i);
+                if (xd) {
+                    getX509Datas().push_back(xd->cloneX509Data());
+                    continue;
+                }
+
+                KeyName* kn=dynamic_cast<KeyName*>(*i);
+                if (kn) {
+                    getKeyNames().push_back(kn->cloneKeyName());
+                    continue;
+                }
+
+                KeyValue* kv=dynamic_cast<KeyValue*>(*i);
+                if (kv) {
+                    getKeyValues().push_back(kv->cloneKeyValue());
+                    continue;
+                }
+
+                DEREncodedKeyValue* ekv=dynamic_cast<DEREncodedKeyValue*>(*i);
+                if (ekv) {
+                    getDEREncodedKeyValues().push_back(ekv->cloneDEREncodedKeyValue());
+                    continue;
+                }
+
+                RetrievalMethod* rm=dynamic_cast<RetrievalMethod*>(*i);
+                if (rm) {
+                    getRetrievalMethods().push_back(rm->cloneRetrievalMethod());
+                    continue;
+                }
+
+                MgmtData* md=dynamic_cast<MgmtData*>(*i);
+                if (md) {
+                    getMgmtDatas().push_back(md->cloneMgmtData());
+                    continue;
+                }
+
+                SPKIData* sd=dynamic_cast<SPKIData*>(*i);
+                if (sd) {
+                    getSPKIDatas().push_back(sd->cloneSPKIData());
+                    continue;
+                }
+
+                PGPData* pd=dynamic_cast<PGPData*>(*i);
+                if (pd) {
+                    getPGPDatas().push_back(pd->clonePGPData());
+                    continue;
+                }
+
+                KeyInfoReference* kref=dynamic_cast<KeyInfoReference*>(*i);
+                if (kref) {
+                    getKeyInfoReferences().push_back(kref->cloneKeyInfoReference());
+                    continue;
+                }
+
                 if (*i) {
-                    X509Data* xd=dynamic_cast<X509Data*>(*i);
-                    if (xd) {
-                        getX509Datas().push_back(xd->cloneX509Data());
-                        continue;
-                    }
-
-                    KeyName* kn=dynamic_cast<KeyName*>(*i);
-                    if (kn) {
-                        getKeyNames().push_back(kn->cloneKeyName());
-                        continue;
-                    }
-
-                    KeyValue* kv=dynamic_cast<KeyValue*>(*i);
-                    if (kv) {
-                        getKeyValues().push_back(kv->cloneKeyValue());
-                        continue;
-                    }
-
-                    DEREncodedKeyValue* ekv=dynamic_cast<DEREncodedKeyValue*>(*i);
-                    if (ekv) {
-                        getDEREncodedKeyValues().push_back(ekv->cloneDEREncodedKeyValue());
-                        continue;
-                    }
-
-                    RetrievalMethod* rm=dynamic_cast<RetrievalMethod*>(*i);
-                    if (rm) {
-                        getRetrievalMethods().push_back(rm->cloneRetrievalMethod());
-                        continue;
-                    }
-
-                    MgmtData* md=dynamic_cast<MgmtData*>(*i);
-                    if (md) {
-                        getMgmtDatas().push_back(md->cloneMgmtData());
-                        continue;
-                    }
-
-                    SPKIData* sd=dynamic_cast<SPKIData*>(*i);
-                    if (sd) {
-                        getSPKIDatas().push_back(sd->cloneSPKIData());
-                        continue;
-                    }
-
-                    PGPData* pd=dynamic_cast<PGPData*>(*i);
-                    if (pd) {
-                        getPGPDatas().push_back(pd->clonePGPData());
-                        continue;
-                    }
-
-                    KeyInfoReference* kref=dynamic_cast<KeyInfoReference*>(*i);
-                    if (kref) {
-                        getKeyInfoReferences().push_back(kref->cloneKeyInfoReference());
-                        continue;
-                    }
-
-                    if (*i) {
-                        getUnknownXMLObjects().push_back((*i)->clone());
-                    }
+                    getUnknownXMLObjects().push_back((*i)->clone());
                 }
             }
         }
index 866fbb8..dc9f1d6 100644 (file)
@@ -34,6 +34,9 @@
 #include "soap/SOAP.h"
 #include "util/XMLHelper.h"
 
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/if.hpp>
+#include <boost/lambda/lambda.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace soap11;
@@ -71,7 +74,7 @@ namespace {
             
         FaultcodeImpl(const FaultcodeImpl& src)
                 : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src), m_qname(nullptr) {
-            setCode(src.getCode());
+            IMPL_CLONE_ATTRIB(Code);
         }
         
         const xmltooling::QName* getCode() const {
@@ -114,11 +117,7 @@ namespace {
                     AbstractAttributeExtensibleXMLObject(src),
                     AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) {
-                if (*i) {
-                    getUnknownXMLObjects().push_back((*i)->clone());
-                }
-            }
+            IMPL_CLONE_XMLOBJECT_CHILDREN();
         }
         
         IMPL_XMLOBJECT_CLONE(Detail);
@@ -178,14 +177,10 @@ namespace {
         FaultImpl(const FaultImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getFaultcode())
-                setFaultcode(src.getFaultcode()->cloneFaultcode());
-            if (src.getFaultstring())
-                setFaultstring(src.getFaultstring()->cloneFaultstring());
-            if (src.getFaultactor())
-                setFaultactor(src.getFaultactor()->cloneFaultactor());
-            if (src.getDetail())
-                setDetail(src.getDetail()->cloneDetail());
+            IMPL_CLONE_TYPED_CHILD(Faultcode);
+            IMPL_CLONE_TYPED_CHILD(Faultstring);
+            IMPL_CLONE_TYPED_CHILD(Faultactor);
+            IMPL_CLONE_TYPED_CHILD(Detail);
         }
         
         IMPL_XMLOBJECT_CLONE(Fault);
@@ -224,11 +219,7 @@ namespace {
                     AbstractAttributeExtensibleXMLObject(src),
                     AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) {
-                if (*i) {
-                    getUnknownXMLObjects().push_back((*i)->clone());
-                }
-            }
+            IMPL_CLONE_XMLOBJECT_CHILDREN();
         }
         
         IMPL_XMLOBJECT_CLONE(Body);
@@ -268,11 +259,7 @@ namespace {
                     AbstractAttributeExtensibleXMLObject(src),
                     AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) {
-                if (*i) {
-                    getUnknownXMLObjects().push_back((*i)->clone());
-                }
-            }
+            IMPL_CLONE_XMLOBJECT_CHILDREN();
         }
         
         IMPL_XMLOBJECT_CLONE(Header);
@@ -320,15 +307,13 @@ namespace {
         EnvelopeImpl(const EnvelopeImpl& src)
                 : AbstractXMLObject(src), AbstractAttributeExtensibleXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getHeader())
-                setHeader(src.getHeader()->cloneHeader());
-            if (src.getBody())
-                setBody(src.getBody()->cloneBody());
+            IMPL_CLONE_TYPED_CHILD(Header);
+            IMPL_CLONE_TYPED_CHILD(Body);
         }
         
+        IMPL_XMLOBJECT_CLONE(Envelope);
         IMPL_TYPED_CHILD(Header);
         IMPL_TYPED_CHILD(Body);
-        IMPL_XMLOBJECT_CLONE(Envelope);
 
     protected:
         void marshallAttributes(DOMElement* domElement) const {