Began to implement collection handling.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / XMLObjectBaseTestCase.h
index a6e999d..d69e1c0 100644 (file)
@@ -22,6 +22,7 @@
 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>\r
 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>\r
 #include <xmltooling/util/ParserPool.h>\r
+#include <xmltooling/util/XMLObjectChildrenList.h>\r
 #include <xmltooling/util/XMLHelper.h>\r
 \r
 using namespace xmltooling;\r
@@ -50,7 +51,6 @@ public:
     virtual ~SimpleXMLObject() {\r
         XMLString::release(&m_id);\r
         XMLString::release(&m_value);\r
-        for_each(m_children.begin(), m_children.end(), cleanup<SimpleXMLObject>());\r
     }\r
     \r
     const XMLCh* getId() const { return m_id; }\r
@@ -60,15 +60,19 @@ public:
     void setValue(const XMLCh* value) { m_value=prepareForAssignment(m_value,value); }\r
     \r
     // TODO: Leave non-const, but wrap STL container to intercept adds. \r
-    list<SimpleXMLObject*>& getSimpleXMLObjects() { return m_children; }\r
-    \r
-    bool hasChildren() const { return !m_children.empty(); }\r
-    size_t getOrderedChildren(vector<XMLObject*>& children) const {\r
-        children.assign(m_children.begin(),m_children.end());\r
-        return children.size();\r
+    ListOf(SimpleXMLObject) getSimpleXMLObjects() {\r
+        return ListOf(SimpleXMLObject)(this, m_simples, m_children, m_children.end());\r
     }\r
+    \r
     SimpleXMLObject* clone() const {\r
-        SimpleXMLObject* ret=new SimpleXMLObject();\r
+        auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());\r
+        SimpleXMLObject* ret=dynamic_cast<SimpleXMLObject*>(domClone.get());\r
+        if (ret) {\r
+            domClone.release();\r
+            return ret;\r
+        }\r
+\r
+        ret=new SimpleXMLObject();\r
         ret->setId(m_id);\r
         ret->setValue(m_value);\r
         xmltooling::clone(m_children, ret->m_children);\r
@@ -78,7 +82,7 @@ public:
 private:\r
     XMLCh* m_id;\r
     XMLCh* m_value;\r
-    list<SimpleXMLObject*> m_children;\r
+    vector<SimpleXMLObject*> m_simples;\r
     \r
     friend class SimpleXMLObjectUnmarshaller;\r
 };\r
@@ -127,6 +131,7 @@ private:
         SimpleXMLObject* child = dynamic_cast<SimpleXMLObject*>(childXMLObject);\r
         if (child) {\r
             simpleXMLObject.m_children.push_back(child);\r
+            simpleXMLObject.m_simples.push_back(child);\r
         }\r
         else {\r
             throw UnmarshallingException("Unknown child element cannot be added to parent object.");\r