Macro adjustments, date/time class, typed XML attributes.
[shibboleth/xmltooling.git] / xmltooling / AbstractXMLObject.h
index 7a4ff1f..ba34176 100644 (file)
@@ -24,6 +24,7 @@
 #define __xmltooling_abstractxmlobj_h__\r
 \r
 #include <xmltooling/XMLObject.h>\r
+#include <xmltooling/util/DateTime.h>\r
 \r
 #if defined (_MSC_VER)\r
     #pragma warning( push )\r
@@ -34,11 +35,17 @@ namespace xmltooling {
 \r
     /**\r
      * An abstract implementation of XMLObject.\r
+     * This is the primary concrete base class, and supplies basic namespace,\r
+     * type, and parent handling. Most implementation classes should not\r
+     * directly inherit from this class, but rather from the various mixins\r
+     * that supply the rest of the XMLObject interface, as required.\r
      */\r
     class XMLTOOL_API AbstractXMLObject : public virtual XMLObject\r
     {\r
     public:\r
-        virtual ~AbstractXMLObject();\r
+        virtual ~AbstractXMLObject() {\r
+            delete m_typeQname;\r
+        }\r
 \r
         const QName& getElementQName() const {\r
             return m_elementQname;\r
@@ -74,14 +81,6 @@ namespace xmltooling {
             m_parent = parent;\r
         }\r
 \r
-        bool hasChildren() const {\r
-            return !m_children.empty();\r
-        }\r
-\r
-        const std::list<XMLObject*>& getOrderedChildren() const {\r
-            return m_children;\r
-        }\r
-\r
      protected:\r
         /**\r
          * Constructor\r
@@ -99,9 +98,10 @@ namespace xmltooling {
         AbstractXMLObject(const AbstractXMLObject& src);\r
         \r
         /**\r
-         * A helper function for derived classes.\r
+         * A helper function for derived classes, for assignment of strings.\r
+         *\r
          * This 'normalizes' newString, and then if it is different from oldString,\r
-         * it invalidates the DOM, frees the old string, and return the new.\r
+         * it invalidates the DOM, frees the old string, and returns the new.\r
          * If not different, it frees the new string and just returns the old value.\r
          * \r
          * @param oldValue - the current value\r
@@ -109,39 +109,73 @@ namespace xmltooling {
          * \r
          * @return the value that should be assigned\r
          */\r
-        XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue) {\r
-            XMLCh* newString = XMLString::replicate(newValue);\r
-            XMLString::trim(newString);\r
-            if (!XMLString::equals(oldValue,newValue)) {\r
-                releaseThisandParentDOM();\r
-                XMLString::release(&oldValue);\r
-                return newString;\r
-            }\r
-            XMLString::release(&newString);\r
-            return oldValue;            \r
-        }\r
+        XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);\r
+\r
+        /**\r
+         * A helper function for derived classes, for assignment of date/time data.\r
+         *\r
+         * It invalidates the DOM, frees the old object, and returns the new.\r
+         * \r
+         * @param oldValue - the current value\r
+         * @param newValue - the new value\r
+         * \r
+         * @return the value that should be assigned\r
+         */\r
+        DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);\r
+\r
+        /**\r
+         * A helper function for derived classes, for assignment of date/time data.\r
+         *\r
+         * It invalidates the DOM, frees the old object, and returns the new.\r
+         * \r
+         * @param oldValue - the current value\r
+         * @param newValue - the epoch to assign as the new value\r
+         * \r
+         * @return the value that should be assigned\r
+         */\r
+        DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue);\r
+\r
+        /**\r
+         * A helper function for derived classes, for assignment of date/time data.\r
+         *\r
+         * It invalidates the DOM, frees the old object, and returns the new.\r
+         * \r
+         * @param oldValue - the current value\r
+         * @param newValue - the new value in string form\r
+         * \r
+         * @return the value that should be assigned\r
+         */\r
+        DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue);\r
+\r
+        /**\r
+         * A helper function for derived classes, for assignment of QName data.\r
+         *\r
+         * It invalidates the DOM, frees the old object, and returns the new.\r
+         * \r
+         * @param oldValue - the current value\r
+         * @param newValue - the new value\r
+         * \r
+         * @return the value that should be assigned\r
+         */\r
+        QName* prepareForAssignment(QName* oldValue, const QName* newValue);\r
 \r
         /**\r
          * A helper function for derived classes, for assignment of (singleton) XML objects.\r
          * \r
          * It is indifferent to whether either the old or the new version of the value is null. \r
-         * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate\r
+         * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.\r
+         * Note that since the new value (even if NULL) is always returned, it may be more efficient\r
+         * to discard the return value and just assign independently if a dynamic cast would be involved.\r
          * \r
          * @param oldValue - current value\r
          * @param newValue - proposed new value\r
-         * @return the value to assign \r
+         * @return the new value \r
          * \r
          * @throws XMLObjectException if the new child already has a parent.\r
          */\r
         XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);\r
 \r
         /**\r
-         * Underlying list of child objects.\r
-         * Manages the lifetime of the children.\r
-         */\r
-        std::list<XMLObject*> m_children;\r
-\r
-        /**\r
          * Set of namespaces associated with the object.\r
          */\r
         mutable std::set<Namespace> m_namespaces;\r