Added DocumentJanitor to avoid some catch(...) handlers.
authorScott Cantor <cantor.2@osu.edu>
Wed, 5 Jul 2006 01:29:22 +0000 (01:29 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 5 Jul 2006 01:29:22 +0000 (01:29 +0000)
xmltooling/util/XMLHelper.h

index ac6f240..9f2f6fe 100644 (file)
@@ -31,6 +31,33 @@ using namespace xercesc;
 namespace xmltooling {\r
     \r
     /**\r
+     * RAII wrapper for DOM Documents.\r
+     */\r
+    class XMLTOOL_API DocumentJanitor\r
+    {\r
+        MAKE_NONCOPYABLE(DocumentJanitor);\r
+        DOMDocument* m_doc;\r
+    public:\r
+        DocumentJanitor(DOMDocument* doc) : m_doc(doc) {}\r
+        \r
+        ~DocumentJanitor() {\r
+            if (m_doc)\r
+                m_doc->release();\r
+        }\r
+        \r
+        /**\r
+         * Returns any document held by this object and releases it to the caller.\r
+         * \r
+         * @return  the document held or NULL\r
+         */\r
+        DOMDocument* release() {\r
+            DOMDocument* ret=m_doc;\r
+            m_doc=NULL;\r
+            return ret;\r
+        }\r
+    };\r
+    \r
+    /**\r
      * A helper class for working with W3C DOM objects. \r
      */\r
     class XMLTOOL_API XMLHelper\r