gcc const fix, converted linefeeds
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.h
index 3f2e801..80f3871 100644 (file)
-/*\r
-*  Copyright 2001-2006 Internet2\r
- * \r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * @file AbstractXMLObject.h\r
- * \r
- * An abstract implementation of XMLObject.\r
- */\r
-\r
-#if !defined(__xmltooling_abstractxmlobj_h__)\r
-#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
-    #pragma warning( disable : 4250 4251 )\r
-#endif\r
-\r
-namespace xmltooling {\r
-\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
-            delete m_typeQname;\r
-            XMLString::release(&m_schemaLocation);\r
-        }\r
-\r
-        void detach();\r
-\r
-        const QName& getElementQName() const {\r
-            return m_elementQname;\r
-        }\r
-\r
-        const std::set<Namespace>& getNamespaces() const {\r
-            return m_namespaces;\r
-        }\r
-    \r
-        void addNamespace(const Namespace& ns) const {\r
-            std::set<Namespace>::iterator i = m_namespaces.find(ns);\r
-            if (i == m_namespaces.end())\r
-                m_namespaces.insert(ns);\r
-            else if (ns.alwaysDeclare())\r
-                i->setAlwaysDeclare(true);\r
-        }\r
-    \r
-        void removeNamespace(const Namespace& ns) {\r
-            m_namespaces.erase(ns);\r
-        }\r
-        \r
-        const QName* getSchemaType() const {\r
-            return m_typeQname;\r
-        }\r
-        \r
-        const XMLCh* getXMLID() const {\r
-            return NULL;\r
-        }\r
-    \r
-        bool hasParent() const {\r
-            return m_parent != NULL;\r
-        }\r
-     \r
-        XMLObject* getParent() const {\r
-            return m_parent;\r
-        }\r
-    \r
-        void setParent(XMLObject* parent) {\r
-            m_parent = parent;\r
-        }\r
-\r
-     protected:\r
-        /**\r
-         * Constructor\r
-         * \r
-         * @param nsURI         the namespace of the element\r
-         * @param localName     the local name of the XML element this Object represents\r
-         * @param prefix        the namespace prefix to use\r
-         * @param schemaType    the xsi:type to use\r
-         */\r
-        AbstractXMLObject(\r
-            const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
-            );\r
-\r
-        /** Copy constructor. */\r
-        AbstractXMLObject(const AbstractXMLObject& src);\r
-        \r
-        /**\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 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
-         * @param newValue - the new value\r
-         * \r
-         * @return the value that should be assigned\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
-         * 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 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
-         * Set of namespaces associated with the object.\r
-         */\r
-        mutable std::set<Namespace> m_namespaces;\r
-\r
-        /**\r
-         * Logging object.\r
-         */\r
-        void* m_log;\r
-\r
-        /**\r
-         * Stores off xsi:schemaLocation attribute.\r
-         */\r
-        XMLCh* m_schemaLocation;\r
-\r
-    private:\r
-        XMLObject* m_parent;\r
-        QName m_elementQname;\r
-        QName* m_typeQname;\r
-    };\r
-\r
-};\r
-\r
-#if defined (_MSC_VER)\r
-    #pragma warning( pop )\r
-#endif\r
-\r
-#endif /* __xmltooling_abstractxmlobj_h__ */\r
+/*
+*  Copyright 2001-2006 Internet2
+ * 
+* Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file AbstractXMLObject.h
+ * 
+ * An abstract implementation of XMLObject.
+ */
+
+#if !defined(__xmltooling_abstractxmlobj_h__)
+#define __xmltooling_abstractxmlobj_h__
+
+#include <xmltooling/XMLObject.h>
+#include <xmltooling/util/DateTime.h>
+
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4250 4251 )
+#endif
+
+namespace xmltooling {
+
+    /**
+     * An abstract implementation of XMLObject.
+     * This is the primary concrete base class, and supplies basic namespace,
+     * type, and parent handling. Most implementation classes should not
+     * directly inherit from this class, but rather from the various mixins
+     * that supply the rest of the XMLObject interface, as required.
+     */
+    class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
+    {
+    public:
+        virtual ~AbstractXMLObject() {
+            delete m_typeQname;
+            XMLString::release(&m_schemaLocation);
+        }
+
+        void detach();
+
+        const QName& getElementQName() const {
+            return m_elementQname;
+        }
+
+        const std::set<Namespace>& getNamespaces() const {
+            return m_namespaces;
+        }
+    
+        void addNamespace(const Namespace& ns) const {
+            std::set<Namespace>::iterator i = m_namespaces.find(ns);
+            if (i == m_namespaces.end())
+                m_namespaces.insert(ns);
+            else if (ns.alwaysDeclare())
+                const_cast<Namespace&>(*i).setAlwaysDeclare(true);
+        }
+    
+        void removeNamespace(const Namespace& ns) {
+            m_namespaces.erase(ns);
+        }
+        
+        const QName* getSchemaType() const {
+            return m_typeQname;
+        }
+        
+        const XMLCh* getXMLID() const {
+            return NULL;
+        }
+    
+        bool hasParent() const {
+            return m_parent != NULL;
+        }
+     
+        XMLObject* getParent() const {
+            return m_parent;
+        }
+    
+        void setParent(XMLObject* parent) {
+            m_parent = parent;
+        }
+
+     protected:
+        /**
+         * Constructor
+         * 
+         * @param nsURI         the namespace of the element
+         * @param localName     the local name of the XML element this Object represents
+         * @param prefix        the namespace prefix to use
+         * @param schemaType    the xsi:type to use
+         */
+        AbstractXMLObject(
+            const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
+            );
+
+        /** Copy constructor. */
+        AbstractXMLObject(const AbstractXMLObject& src);
+        
+        /**
+         * A helper function for derived classes, for assignment of strings.
+         *
+         * This 'normalizes' newString, and then if it is different from oldString,
+         * it invalidates the DOM, frees the old string, and returns the new.
+         * If not different, it frees the new string and just returns the old value.
+         * 
+         * @param oldValue - the current value
+         * @param newValue - the new value
+         * 
+         * @return the value that should be assigned
+         */
+        XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
+
+        /**
+         * A helper function for derived classes, for assignment of date/time data.
+         *
+         * It invalidates the DOM, frees the old object, and returns the new.
+         * 
+         * @param oldValue - the current value
+         * @param newValue - the new value
+         * 
+         * @return the value that should be assigned
+         */
+        DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
+
+        /**
+         * A helper function for derived classes, for assignment of date/time data.
+         *
+         * It invalidates the DOM, frees the old object, and returns the new.
+         * 
+         * @param oldValue - the current value
+         * @param newValue - the epoch to assign as the new value
+         * 
+         * @return the value that should be assigned
+         */
+        DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue);
+
+        /**
+         * A helper function for derived classes, for assignment of date/time data.
+         *
+         * It invalidates the DOM, frees the old object, and returns the new.
+         * 
+         * @param oldValue - the current value
+         * @param newValue - the new value in string form
+         * 
+         * @return the value that should be assigned
+         */
+        DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue);
+
+        /**
+         * A helper function for derived classes, for assignment of QName data.
+         *
+         * It invalidates the DOM, frees the old object, and returns the new.
+         * 
+         * @param oldValue - the current value
+         * @param newValue - the new value
+         * 
+         * @return the value that should be assigned
+         */
+        QName* prepareForAssignment(QName* oldValue, const QName* newValue);
+
+        /**
+         * A helper function for derived classes, for assignment of (singleton) XML objects.
+         * 
+         * It is indifferent to whether either the old or the new version of the value is null. 
+         * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
+         * Note that since the new value (even if NULL) is always returned, it may be more efficient
+         * to discard the return value and just assign independently if a dynamic cast would be involved.
+         * 
+         * @param oldValue - current value
+         * @param newValue - proposed new value
+         * @return the new value 
+         * 
+         * @throws XMLObjectException if the new child already has a parent.
+         */
+        XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
+
+        /**
+         * Set of namespaces associated with the object.
+         */
+        mutable std::set<Namespace> m_namespaces;
+
+        /**
+         * Logging object.
+         */
+        void* m_log;
+
+        /**
+         * Stores off xsi:schemaLocation attribute.
+         */
+        XMLCh* m_schemaLocation;
+
+    private:
+        XMLObject* m_parent;
+        QName m_elementQname;
+        QName* m_typeQname;
+    };
+
+};
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
+#endif /* __xmltooling_abstractxmlobj_h__ */