Began to implement collection handling.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractDOMCachingXMLObject.h
index dc57831..862f925 100644 (file)
 #include <xmltooling/AbstractXMLObject.h>\r
 #include <xmltooling/DOMCachingXMLObject.h>\r
 \r
-#pragma warning( push )\r
-#pragma warning( disable : 4250 4251 )\r
+#if defined (_MSC_VER)\r
+    #pragma warning( push )\r
+    #pragma warning( disable : 4250 4251 )\r
+#endif\r
 \r
 namespace xmltooling {\r
 \r
     /**\r
      * Extension of AbstractXMLObject that implements a DOMCachingXMLObject.\r
+     * This is the primary base class for XMLObject implementation classes to use.\r
      */\r
-    class XMLTOOL_API AbstractDOMCachingXMLObject : public virtual AbstractXMLObject, public virtual DOMCachingXMLObject\r
+    class XMLTOOL_API AbstractDOMCachingXMLObject : public AbstractXMLObject, public DOMCachingXMLObject\r
     {\r
     public:\r
         virtual ~AbstractDOMCachingXMLObject();\r
@@ -42,40 +45,38 @@ namespace xmltooling {
         /**\r
          * @see DOMCachingXMLObject::getDOM()\r
          */\r
-        const DOMElement* getDOM() const {\r
+        DOMElement* getDOM() const {\r
             return m_dom;\r
         }\r
         \r
         /**\r
          * @see DOMCachingXMLObject::setDOM()\r
          */\r
-        void setDOM(DOMElement* dom) {\r
-            m_dom=dom;\r
-        }\r
+        void setDOM(DOMElement* dom, bool bindDocument=false);\r
         \r
         /**\r
          * @see DOMCachingXMLObject::setDocument()\r
          */\r
-        DOMDocument* setDocument(DOMDocument* doc) {\r
-            DOMDocument* ret=m_document;\r
+        void setDocument(DOMDocument* doc) {\r
+            if (m_document)\r
+                m_document->release();\r
             m_document=doc;\r
-            return ret;\r
         }\r
     \r
         /**\r
          * @see DOMCachingXMLObject::releaseDOM()\r
          */\r
-        void releaseDOM();\r
+        virtual void releaseDOM();\r
         \r
         /**\r
          * @see DOMCachingXMLObject::releaseParentDOM()\r
          */\r
-        void releaseParentDOM(bool propagateRelease=true);\r
+        virtual void releaseParentDOM(bool propagateRelease=true);\r
         \r
         /**\r
          * @see DOMCachingXMLObject::releaseChildrenDOM()\r
          */\r
-        void releaseChildrenDOM(bool propagateRelease=true);\r
+        virtual void releaseChildrenDOM(bool propagateRelease=true);\r
     \r
         /**\r
          * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true).\r
@@ -88,17 +89,39 @@ namespace xmltooling {
         }\r
     \r
         /**\r
-         * A convenience method that is equal to calling releaseDOM() then releaseChildrenDOM(true).\r
+         * A convenience method that is equal to calling releaseChildrenDOM(true) then releaseDOM().\r
          */\r
         void releaseThisAndChildrenDOM() {\r
             if (m_dom) {\r
-                releaseDOM();\r
                 releaseChildrenDOM(true);\r
+                releaseDOM();\r
             }\r
         }\r
     \r
+        /**\r
+         * @see XMLObject::clone()\r
+         */\r
+        XMLObject* clone() const;\r
+\r
      protected:\r
         /**\r
+         * Constructor\r
+         * \r
+         * @param namespaceURI the namespace the element is in\r
+         * @param elementLocalName the local name of the XML element this Object represents\r
+         */\r
+        AbstractDOMCachingXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL)\r
+            : AbstractXMLObject(namespaceURI,elementLocalName, namespacePrefix), m_dom(NULL), m_document(NULL) {}\r
+\r
+        /**\r
+         * If a DOM representation exists, this clones it into a new document.\r
+         * \r
+         * @param doc   the document to clone into, or NULL, in which case a new document is created\r
+         * @return  the cloned DOM\r
+         */\r
+        DOMElement* cloneDOM(DOMDocument* doc=NULL) const;\r
+\r
+        /**\r
          * A helper function for derived classes.\r
          * This 'normalizes' newString and then if it is different from oldString\r
          * invalidates the DOM. It returns the normalized value.\r
@@ -112,7 +135,7 @@ namespace xmltooling {
             XMLCh* newString = XMLString::replicate(newValue);\r
             XMLString::trim(newString);\r
 \r
-            if (oldValue && !newValue || !oldValue && newValue || XMLString::compareString(oldValue,newValue))\r
+            if (!XMLString::equals(oldValue,newValue))\r
                 releaseThisandParentDOM();\r
     \r
             return newString;\r
@@ -132,15 +155,6 @@ namespace xmltooling {
          */\r
         XMLObject* prepareForAssignment(const XMLObject* oldValue, XMLObject* newValue);\r
 \r
-        /**\r
-         * Constructor\r
-         * \r
-         * @param namespaceURI the namespace the element is in\r
-         * @param elementLocalName the local name of the XML element this Object represents\r
-         */\r
-        explicit AbstractDOMCachingXMLObject(const XMLCh* namespaceURI, const XMLCh* elementLocalName)\r
-            : AbstractXMLObject(namespaceURI,elementLocalName), m_dom(NULL), m_document(NULL) {}\r
-\r
     private:\r
         DOMElement* m_dom;\r
         DOMDocument* m_document;\r
@@ -148,6 +162,8 @@ namespace xmltooling {
     \r
 };\r
 \r
-#pragma warning( pop )\r
+#if defined (_MSC_VER)\r
+    #pragma warning( pop )\r
+#endif\r
 \r
 #endif /* __xmltooling_abstractdomxmlobj_h__ */\r