Add code for non-covariant build.
authorScott Cantor <cantor.2@osu.edu>
Tue, 21 Nov 2006 16:47:45 +0000 (16:47 +0000)
committerScott Cantor <cantor.2@osu.edu>
Tue, 21 Nov 2006 16:47:45 +0000 (16:47 +0000)
xmltooling/base.h
xmltooling/config_pub.h.in
xmltooling/config_pub_win32.h
xmltooling/signature/Signature.h
xmltooling/signature/impl/XMLSecSignatureImpl.cpp
xmltoolingtest/MarshallingTest.h
xmltoolingtest/SignatureTest.h
xmltoolingtest/UnmarshallingTest.h
xmltoolingtest/XMLObjectBaseTestCase.h

index 8d5a370..6c6d359 100644 (file)
                 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
         return new cname##Impl(nsURI,localName,prefix,schemaType); \
     }
 
+#else   /* !HAVE_COVARIANT_RETURNS */\r
+
+/**
+ * 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<const cname##Builder*>( \
+            XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
+            ); \
+        if (b) \
+            return dynamic_cast<cname*>(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.
  * 
index 4b790f1..45c9e8d 100644 (file)
@@ -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
index 50af9d3..958211c 100644 (file)
@@ -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
index db95c20..f215100 100644 (file)
@@ -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<const SignatureBuilder*>(
                 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<Signature*>(b->buildObject());
+#endif
+            }
             throw xmltooling::XMLObjectException("Unable to obtain typed builder for Signature.");
         }
     };
index 4f33d90..6199613 100644 (file)
@@ -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();
 }
index 0414185..139b27d 100644 (file)
@@ -36,7 +36,7 @@ public:
 
     void testMarshallingWithAttributes() {
         QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);
-        auto_ptr<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject());
+        auto_ptr<SimpleXMLObject> 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<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject());
+        auto_ptr<SimpleXMLObject> 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<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(qname));
         TS_ASSERT(b!=NULL);
         
-        auto_ptr<SimpleXMLObject> sxObject(b->buildObject());
+        auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(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<SimpleXMLObject*>(b->buildObject()));
+        kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
+        kids.push_back(dynamic_cast<SimpleXMLObject*>(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<SimpleXMLObject*>(
+                b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX,&qtype)
+                )
             );
         kids.back()->setValue(baz.get());
         
index a733767..7e91f92 100644 (file)
@@ -109,11 +109,11 @@ public:
         const SimpleXMLObjectBuilder* b=dynamic_cast<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(qname));
         TS_ASSERT(b!=NULL);
         
-        auto_ptr<SimpleXMLObject> sxObject(b->buildObject());
+        auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(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<SimpleXMLObject*>(b->buildObject()));
+        kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
         
         // Test some collection stuff
         auto_ptr_XMLCh foo("Foo");
index 255168c..a00b655 100644 (file)
@@ -139,7 +139,7 @@ public:
         TS_ASSERT(sxObject.get()!=NULL);
 
         sxObject->releaseThisAndChildrenDOM();
-        auto_ptr<SimpleXMLObject> clonedObject(sxObject->clone());
+        auto_ptr<SimpleXMLObject> clonedObject(dynamic_cast<SimpleXMLObject*>(sxObject->clone()));
 
         VectorOf(SimpleXMLObject) kids=clonedObject->getSimpleXMLObjects();
         TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());
index 85d42b1..a0a8244 100644 (file)
@@ -60,7 +60,7 @@ protected:
 #endif
         VectorOf(SimpleXMLObject) mine=getSimpleXMLObjects();
         for (vector<SimpleXMLObject*>::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<SimpleXMLObject*>((*i)->clone()));
         }
     }
 
@@ -85,7 +85,7 @@ public:
         XMLString::release(&m_id);
     }
 
-    SimpleXMLObject* clone() const {
+    XMLObject* clone() const {
         auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());
         SimpleXMLObject* ret=dynamic_cast<SimpleXMLObject*>(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<const SimpleXMLObjectBuilder*>(
             XMLObjectBuilder::getBuilder(QName(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME))
             );
         if (b)
-            return b->buildObject();
+            return dynamic_cast<SimpleXMLObject*>(b->buildObject());
         throw XMLObjectException("Unable to obtain typed builder for SimpleXMLObject.");
     }
 };