From 36769dc1d8419136e55dde51697b47683b376214 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Tue, 21 Nov 2006 16:47:45 +0000 Subject: [PATCH] Add code for non-covariant build. --- xmltooling/base.h | 71 ++++++++++++++++++++++- xmltooling/config_pub.h.in | 3 + xmltooling/config_pub_win32.h | 3 + xmltooling/signature/Signature.h | 12 +++- xmltooling/signature/impl/XMLSecSignatureImpl.cpp | 7 ++- xmltoolingtest/MarshallingTest.h | 16 ++--- xmltoolingtest/SignatureTest.h | 6 +- xmltoolingtest/UnmarshallingTest.h | 2 +- xmltoolingtest/XMLObjectBaseTestCase.h | 12 ++-- 9 files changed, 111 insertions(+), 21 deletions(-) diff --git a/xmltooling/base.h b/xmltooling/base.h index 8d5a370..6c6d359 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -1160,7 +1160,9 @@ xmltooling::AbstractDOMCachingXMLObject(src) {} \ IMPL_XMLOBJECT_CLONE(cname) \ } - + +#ifdef HAVE_COVARIANT_RETURNS + /** * Begins the declaration of an XMLObjectBuilder specialization. * Basic boilerplate includes an empty virtual destructor, and @@ -1224,6 +1226,73 @@ return new cname##Impl(nsURI,localName,prefix,schemaType); \ } +#else /* !HAVE_COVARIANT_RETURNS */ + +/** + * Begins the declaration of an XMLObjectBuilder specialization. + * Basic boilerplate includes an empty virtual destructor, and + * a default builder that defaults the element name. + * + * @param linkage linkage specifier for the class + * @param cname the name of the XMLObject specialization + * @param namespaceURI the XML namespace of the default associated element + * @param namespacePrefix the XML namespace prefix of the default associated element + */ +#define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \ + XMLTOOLING_DOXYGEN(Builder for cname objects.) \ + class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \ + public: \ + virtual ~cname##Builder() {} \ + XMLTOOLING_DOXYGEN(Default builder.) \ + virtual xmltooling::XMLObject* buildObject() const { \ + return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \ + } \ + XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \ + virtual xmltooling::XMLObject* buildObject( \ + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \ + ) const + +/** + * Ends the declaration of an XMLObjectBuilder specialization. + */ +#define END_XMLOBJECTBUILDER } + +/** + * Declares a generic XMLObjectBuilder specialization. + * + * @param linkage linkage specifier for the class + * @param cname the name of the XMLObject specialization + * @param namespaceURI the XML namespace of the default associated element + * @param namespacePrefix the XML namespace prefix of the default associated element + */ + #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \ + BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \ + XMLTOOLING_DOXYGEN(Singleton builder.) \ + static cname* build##cname() { \ + const cname##Builder* b = dynamic_cast( \ + XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \ + ); \ + if (b) \ + return dynamic_cast(b->buildObject()); \ + throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \ + } \ + END_XMLOBJECTBUILDER + +/** + * Implements the standard XMLObjectBuilder specialization function. + * + * @param cname the name of the XMLObject specialization + */ +#define IMPL_XMLOBJECTBUILDER(cname) \ + xmltooling::XMLObject* cname##Builder::buildObject( \ + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \ + ) const \ + { \ + return new cname##Impl(nsURI,localName,prefix,schemaType); \ + } + +#endif /* HAVE_COVARIANT_RETURNS */ + /** * Begins the declaration of a Schema Validator specialization. * diff --git a/xmltooling/config_pub.h.in b/xmltooling/config_pub.h.in index 4b790f1..45c9e8d 100644 --- a/xmltooling/config_pub.h.in +++ b/xmltooling/config_pub.h.in @@ -1,3 +1,6 @@ +/* Define if C++ compiler supports covariant virtual methods. */ +#undef HAVE_COVARIANT_RETURNS + /* Define to 1 if you have an STL implementation that supports useful string specialization. */ #undef HAVE_GOOD_STL diff --git a/xmltooling/config_pub_win32.h b/xmltooling/config_pub_win32.h index 50af9d3..958211c 100644 --- a/xmltooling/config_pub_win32.h +++ b/xmltooling/config_pub_win32.h @@ -1,3 +1,6 @@ +/* Define if C++ compiler supports covariant virtual methods. */ +#define HAVE_COVARIANT_RETURNS 1 + /* Define to 1 if you have an STL implementation that supports useful string specialization. */ #define HAVE_GOOD_STL 1 diff --git a/xmltooling/signature/Signature.h b/xmltooling/signature/Signature.h index db95c20..f215100 100644 --- a/xmltooling/signature/Signature.h +++ b/xmltooling/signature/Signature.h @@ -196,16 +196,24 @@ namespace xmlsignature { * * @return empty Signature object */ +#ifdef HAVE_COVARIANT_RETURNS virtual Signature* buildObject() const; - +#else + virtual xmltooling::XMLObject* buildObject() const; +#endif static Signature* buildSignature() { const SignatureBuilder* b = dynamic_cast( xmltooling::XMLObjectBuilder::getBuilder( xmltooling::QName(xmlconstants::XMLSIG_NS,Signature::LOCAL_NAME) ) ); - if (b) + if (b) { +#ifdef HAVE_COVARIANT_RETURNS return b->buildObject(); +#else + return dynamic_cast(b->buildObject()); +#endif + } throw xmltooling::XMLObjectException("Unable to obtain typed builder for Signature."); } }; diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index 4f33d90..6199613 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -408,7 +408,12 @@ Signature* SignatureBuilder::buildObject( return buildObject(); } -Signature* SignatureBuilder::buildObject() const +#ifdef HAVE_COVARIANT_RETURNS +Signature* +#else +XMLObject* +#endif +SignatureBuilder::buildObject() const { return new XMLSecSignatureImpl(); } diff --git a/xmltoolingtest/MarshallingTest.h b/xmltoolingtest/MarshallingTest.h index 0414185..139b27d 100644 --- a/xmltoolingtest/MarshallingTest.h +++ b/xmltoolingtest/MarshallingTest.h @@ -36,7 +36,7 @@ public: void testMarshallingWithAttributes() { QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME); - auto_ptr sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject()); + auto_ptr sxObject(SimpleXMLObjectBuilder::buildSimpleXMLObject()); TS_ASSERT(sxObject.get()!=NULL); auto_ptr_XMLCh expected("Firefly"); sxObject->setId(expected.get()); @@ -54,7 +54,7 @@ public: void testMarshallingWithElementContent() { QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME); - auto_ptr sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject()); + auto_ptr sxObject(SimpleXMLObjectBuilder::buildSimpleXMLObject()); TS_ASSERT(sxObject.get()!=NULL); auto_ptr_XMLCh expected("Sample Content"); sxObject->setValue(expected.get()); @@ -75,12 +75,12 @@ public: const SimpleXMLObjectBuilder* b=dynamic_cast(XMLObjectBuilder::getBuilder(qname)); TS_ASSERT(b!=NULL); - auto_ptr sxObject(b->buildObject()); + auto_ptr sxObject(dynamic_cast(b->buildObject())); TS_ASSERT(sxObject.get()!=NULL); VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects(); - kids.push_back(b->buildObject()); - kids.push_back(b->buildObject()); - kids.push_back(b->buildObject()); + kids.push_back(dynamic_cast(b->buildObject())); + kids.push_back(dynamic_cast(b->buildObject())); + kids.push_back(dynamic_cast(b->buildObject())); // Test some collection stuff auto_ptr_XMLCh foo("Foo"); @@ -93,7 +93,9 @@ public: QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME,SimpleXMLObject::NAMESPACE_PREFIX); kids.push_back( - b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX,&qtype) + dynamic_cast( + b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX,&qtype) + ) ); kids.back()->setValue(baz.get()); diff --git a/xmltoolingtest/SignatureTest.h b/xmltoolingtest/SignatureTest.h index a733767..7e91f92 100644 --- a/xmltoolingtest/SignatureTest.h +++ b/xmltoolingtest/SignatureTest.h @@ -109,11 +109,11 @@ public: const SimpleXMLObjectBuilder* b=dynamic_cast(XMLObjectBuilder::getBuilder(qname)); TS_ASSERT(b!=NULL); - auto_ptr sxObject(b->buildObject()); + auto_ptr sxObject(dynamic_cast(b->buildObject())); TS_ASSERT(sxObject.get()!=NULL); VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects(); - kids.push_back(b->buildObject()); - kids.push_back(b->buildObject()); + kids.push_back(dynamic_cast(b->buildObject())); + kids.push_back(dynamic_cast(b->buildObject())); // Test some collection stuff auto_ptr_XMLCh foo("Foo"); diff --git a/xmltoolingtest/UnmarshallingTest.h b/xmltoolingtest/UnmarshallingTest.h index 255168c..a00b655 100644 --- a/xmltoolingtest/UnmarshallingTest.h +++ b/xmltoolingtest/UnmarshallingTest.h @@ -139,7 +139,7 @@ public: TS_ASSERT(sxObject.get()!=NULL); sxObject->releaseThisAndChildrenDOM(); - auto_ptr clonedObject(sxObject->clone()); + auto_ptr clonedObject(dynamic_cast(sxObject->clone())); VectorOf(SimpleXMLObject) kids=clonedObject->getSimpleXMLObjects(); TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size()); diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index 85d42b1..a0a8244 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -60,7 +60,7 @@ protected: #endif VectorOf(SimpleXMLObject) mine=getSimpleXMLObjects(); for (vector::const_iterator i=src.m_simples.begin(); i!=src.m_simples.end(); i++) { - mine.push_back((*i) ? (*i)->clone() : NULL); + mine.push_back(dynamic_cast((*i)->clone())); } } @@ -85,7 +85,7 @@ public: XMLString::release(&m_id); } - SimpleXMLObject* clone() const { + XMLObject* clone() const { auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); SimpleXMLObject* ret=dynamic_cast(domClone.get()); if (ret) { @@ -165,22 +165,22 @@ private: class SimpleXMLObjectBuilder : public XMLObjectBuilder { public: - SimpleXMLObject* buildObject() const { + XMLObject* buildObject() const { return buildObject(SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME, SimpleXMLObject::NAMESPACE_PREFIX); } - SimpleXMLObject* buildObject( + XMLObject* buildObject( const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL ) const { return new SimpleXMLObject(nsURI, localName, prefix, schemaType); } - static SimpleXMLObject* newSimpleXMLObject() { + static SimpleXMLObject* buildSimpleXMLObject() { const SimpleXMLObjectBuilder* b = dynamic_cast( XMLObjectBuilder::getBuilder(QName(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME)) ); if (b) - return b->buildObject(); + return dynamic_cast(b->buildObject()); throw XMLObjectException("Unable to obtain typed builder for SimpleXMLObject."); } }; -- 2.1.4