From bcee3411a96ea8a82693e5640d1dd38412ca5956 Mon Sep 17 00:00:00 2001 From: cantor Date: Mon, 6 Mar 2006 00:25:16 +0000 Subject: [PATCH] Base classes for open content models. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@44 de75baf8-a10c-0410-a50a-987c0e22f00f --- .../AbstractAttributeExtensibleXMLObject.cpp | 61 +++++++++++++++ xmltooling/AbstractAttributeExtensibleXMLObject.h | 82 +++++++++++++++++++++ xmltooling/AbstractDOMCachingXMLObject.cpp | 29 +------- xmltooling/AbstractDOMCachingXMLObject.h | 15 +--- xmltooling/AbstractExtensibleXMLObject.cpp | 37 ++++++++++ xmltooling/AbstractExtensibleXMLObject.h | 86 ++++++++++++++++++++++ xmltooling/AbstractXMLObject.h | 1 + xmltooling/AttributeExtensibleXMLObject.h | 60 +++++++++++++++ xmltooling/ExtensibleXMLObject.h | 67 +++++++++++++++++ xmltooling/Makefile.am | 36 +++++---- xmltooling/util/XMLObjectChildrenList.h | 84 +++++++++++---------- xmltooling/xmltooling.vcproj | 24 ++++++ xmltoolingtest/MarshallingTest.h | 5 +- xmltoolingtest/UnmarshallingTest.h | 2 +- xmltoolingtest/XMLObjectBaseTestCase.h | 12 +-- 15 files changed, 496 insertions(+), 105 deletions(-) create mode 100644 xmltooling/AbstractAttributeExtensibleXMLObject.cpp create mode 100644 xmltooling/AbstractAttributeExtensibleXMLObject.h create mode 100644 xmltooling/AbstractExtensibleXMLObject.cpp create mode 100644 xmltooling/AbstractExtensibleXMLObject.h create mode 100644 xmltooling/AttributeExtensibleXMLObject.h create mode 100644 xmltooling/ExtensibleXMLObject.h diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp new file mode 100644 index 0000000..7362956 --- /dev/null +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp @@ -0,0 +1,61 @@ +/* + * 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. + */ + +/** + * AbstractAttributeExtensibleXMLObject.cpp + * + * Extension of AbstractDOMCachingXMLObject that implements an AttributeExtensibleXMLObject. + */ + +#include "internal.h" +#include "AbstractAttributeExtensibleXMLObject.h" + +#include +#include + +using namespace xmltooling; +using namespace std; + +class _release : public unary_function { +public: + void operator()(pair p) const { + XMLString::release(&(p.second)); + } +}; + +AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject() +{ + for_each(m_attributeMap.begin(),m_attributeMap.end(),_release()); +} + +void AbstractAttributeExtensibleXMLObject::setAttribute(QName& qualifiedName, const XMLCh* value) +{ + map::iterator i=m_attributeMap.find(qualifiedName); + if (i!=m_attributeMap.end()) { + releaseThisandParentDOM(); + XMLString::release(&(i->second)); + if (value) { + i->second=XMLString::replicate(value); + } + else { + m_attributeMap.erase(i); + } + } + else if (value) { + releaseThisandParentDOM(); + m_attributeMap[qualifiedName]=XMLString::replicate(value); + } +} diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.h b/xmltooling/AbstractAttributeExtensibleXMLObject.h new file mode 100644 index 0000000..c172b50 --- /dev/null +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.h @@ -0,0 +1,82 @@ +/* + * 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 AbstractAttributeExtensibleXMLObject.h + * + * An abstract implementation of a DOM-caching AttributeExtensibleXMLObject + */ + +#if !defined(__xmltooling_absattrextxmlobj_h__) +#define __xmltooling_absattrextxmlobj_h__ + +#include +#include +#include + +using namespace xercesc; + +#if defined (_MSC_VER) + #pragma warning( push ) + #pragma warning( disable : 4250 4251 ) +#endif + +namespace xmltooling { + + /** + * An abstract implementation of a DOM-caching AttributeExtensibleXMLObject. + */ + class XMLTOOL_API AbstractAttributeExtensibleXMLObject : public virtual AbstractDOMCachingXMLObject + { + public: + virtual ~AbstractAttributeExtensibleXMLObject(); + + /** + * @see AttributeExtensibleXMLObject::getAttribute() + */ + virtual const XMLCh* getAttribute(QName& qualifiedName) const { + std::map::const_iterator i=m_attributeMap.find(qualifiedName); + return (i==m_attributeMap.end()) ? NULL : i->second; + } + + /** + * @see AttributeExtensibleXMLObject::setAttribute() + */ + virtual void setAttribute(QName& qualifiedName, const XMLCh* value); + + protected: + /** + * Constructor + * + * @param namespaceURI the namespace the element is in + * @param elementLocalName the local name of the XML element this Object represents + * @param namespacePrefix the namespace prefix to use + */ + AbstractAttributeExtensibleXMLObject( + const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL + ) : AbstractDOMCachingXMLObject(namespaceURI,elementLocalName, namespacePrefix) {} + + private: + std::map m_attributeMap; + }; + +}; + +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + +#endif /* __xmltooling_absattrextxmlobj_h__ */ diff --git a/xmltooling/AbstractDOMCachingXMLObject.cpp b/xmltooling/AbstractDOMCachingXMLObject.cpp index c1cd6e2..655f22d 100644 --- a/xmltooling/AbstractDOMCachingXMLObject.cpp +++ b/xmltooling/AbstractDOMCachingXMLObject.cpp @@ -72,9 +72,9 @@ void AbstractDOMCachingXMLObject::releaseParentDOM(bool propagateRelease) propagateRelease ? "true" : "false" ); domCachingParent->releaseDOM(); + if (propagateRelease) + domCachingParent->releaseParentDOM(propagateRelease); } - if (propagateRelease) - domCachingParent->releaseParentDOM(propagateRelease); } } @@ -101,31 +101,6 @@ void AbstractDOMCachingXMLObject::releaseChildrenDOM(bool propagateRelease) } } -XMLObject* AbstractDOMCachingXMLObject::prepareForAssignment(const XMLObject* oldValue, XMLObject* newValue) { - - if (newValue && newValue->hasParent()) - throw XMLObjectException("Child XMLObject cannot be added - it is already the child of another XMLObject"); - - if (!oldValue) { - if (newValue) { - releaseThisandParentDOM(); - newValue->setParent(this); - return newValue; - } - else { - return NULL; - } - } - - if (oldValue != newValue) { - delete oldValue; - releaseThisandParentDOM(); - newValue->setParent(this); - } - - return newValue; -} - DOMElement* AbstractDOMCachingXMLObject::cloneDOM(DOMDocument* doc) const { if (getDOM()) { diff --git a/xmltooling/AbstractDOMCachingXMLObject.h b/xmltooling/AbstractDOMCachingXMLObject.h index 862f925..ce8d2c4 100644 --- a/xmltooling/AbstractDOMCachingXMLObject.h +++ b/xmltooling/AbstractDOMCachingXMLObject.h @@ -109,6 +109,7 @@ namespace xmltooling { * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents + * @param namespacePrefix the namespace prefix to use */ AbstractDOMCachingXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL) : AbstractXMLObject(namespaceURI,elementLocalName, namespacePrefix), m_dom(NULL), m_document(NULL) {} @@ -141,20 +142,6 @@ namespace xmltooling { return newString; } - /** - * 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 - * - * @param oldValue - current value - * @param newValue - proposed new value - * @return The value to assign to the saved Object. - * - * @throws IllegalArgumentException if the child already has a parent. - */ - XMLObject* prepareForAssignment(const XMLObject* oldValue, XMLObject* newValue); - private: DOMElement* m_dom; DOMDocument* m_document; diff --git a/xmltooling/AbstractExtensibleXMLObject.cpp b/xmltooling/AbstractExtensibleXMLObject.cpp new file mode 100644 index 0000000..8afac3b --- /dev/null +++ b/xmltooling/AbstractExtensibleXMLObject.cpp @@ -0,0 +1,37 @@ +/* + * 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. + */ + +/** + * AbstractExtensibleXMLObject.cpp + * + * Extension of AbstractDOMCachingXMLObject that implements an ExtensibleXMLObject. + */ + +#include "internal.h" +#include "AbstractExtensibleXMLObject.h" + +using namespace xmltooling; +using namespace std; + +void AbstractExtensibleXMLObject::setTextContent(const XMLCh* value) +{ + m_value=prepareForAssignment(m_value,value); +} + +ListOf(XMLObject) AbstractExtensibleXMLObject::getXMLObjects() +{ + return ListOf(XMLObject)(this,m_children,NULL,m_children.end()); +} diff --git a/xmltooling/AbstractExtensibleXMLObject.h b/xmltooling/AbstractExtensibleXMLObject.h new file mode 100644 index 0000000..fb96a9a --- /dev/null +++ b/xmltooling/AbstractExtensibleXMLObject.h @@ -0,0 +1,86 @@ +/* + * 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 AbstractExtensibleXMLObject.h + * + * An abstract implementation of a DOM-caching ExtensibleXMLObject + */ + +#if !defined(__xmltooling_absextxmlobj_h__) +#define __xmltooling_absextxmlobj_h__ + +#include +#include + +using namespace xercesc; + +#if defined (_MSC_VER) + #pragma warning( push ) + #pragma warning( disable : 4250 4251 ) +#endif + +namespace xmltooling { + + /** + * An abstract implementation of a DOM-caching ExtensibleXMLObject. + */ + class XMLTOOL_API AbstractExtensibleXMLObject : public virtual AbstractDOMCachingXMLObject + { + public: + virtual ~AbstractExtensibleXMLObject() {} + + /** + * @see ExtensibleXMLObject::getTextContent() + */ + virtual const XMLCh* getTextContent() const { + return m_value; + } + + /** + * @see ExtensibleXMLObject::setTextContent() + */ + virtual void setTextContent(const XMLCh* value); + + + /** + * @see ExtensibleXMLObject::getXMLObjects() + */ + virtual ListOf(XMLObject) getXMLObjects(); + + protected: + /** + * Constructor + * + * @param namespaceURI the namespace the element is in + * @param elementLocalName the local name of the XML element this Object represents + * @param namespacePrefix the namespace prefix to use + */ + AbstractExtensibleXMLObject( + const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL + ) : AbstractDOMCachingXMLObject(namespaceURI,elementLocalName, namespacePrefix), m_value(NULL) {} + + private: + XMLCh* m_value; + }; + +}; + +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + +#endif /* __xmltooling_absextxmlobj_h__ */ diff --git a/xmltooling/AbstractXMLObject.h b/xmltooling/AbstractXMLObject.h index c3aa289..fd51345 100644 --- a/xmltooling/AbstractXMLObject.h +++ b/xmltooling/AbstractXMLObject.h @@ -141,6 +141,7 @@ namespace xmltooling { * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents + * @param namespacePrefix the namespace prefix to use */ AbstractXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL) : m_elementQname(namespaceURI,elementLocalName, namespacePrefix), m_typeQname(NULL), m_parent(NULL) { diff --git a/xmltooling/AttributeExtensibleXMLObject.h b/xmltooling/AttributeExtensibleXMLObject.h new file mode 100644 index 0000000..2d1472f --- /dev/null +++ b/xmltooling/AttributeExtensibleXMLObject.h @@ -0,0 +1,60 @@ +/* + * 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 AttributeExtensibleXMLObject.h + * + * An XMLObject that supports arbitrary attributes + */ + +#if !defined(__xmltooling_attrextxmlobj_h__) +#define __xmltooling_attrextxmlobj_h__ + +#include + +using namespace xercesc; + +namespace xmltooling { + + /** + * An XMLObject that supports arbitrary attributes. + */ + class XMLTOOL_API AttributeExtensibleXMLObject : public virtual XMLObject + { + public: + AttributeExtensibleXMLObject() {} + virtual ~AttributeExtensibleXMLObject() {} + + /** + * Gets the value of an XML attribute of the object + * + * @param qualifiedName qualified name of the attribute + * @return the attribute value, or NULL + */ + virtual const XMLCh* getAttribute(QName& qualifiedName) const=0; + + /** + * Sets (or clears) an XML attribute of the object + * + * @param qualifiedName qualified name of the attribute + * @param value value to set, or NULL to clear + */ + virtual void setAttribute(QName& qualifiedName, const XMLCh* value)=0; + }; + +}; + +#endif /* __xmltooling_attrextxmlobj_h__ */ diff --git a/xmltooling/ExtensibleXMLObject.h b/xmltooling/ExtensibleXMLObject.h new file mode 100644 index 0000000..fb31320 --- /dev/null +++ b/xmltooling/ExtensibleXMLObject.h @@ -0,0 +1,67 @@ +/* + * 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 ExtensibleXMLObject.h + * + * An XMLObject with an open content model + */ + +#if !defined(__xmltooling_extxmlobj_h__) +#define __xmltooling_extxmlobj_h__ + +#include +#include + +using namespace xercesc; + +namespace xmltooling { + + /** + * An XMLObject with an open content model. + */ + class XMLTOOL_API ExtensibleXMLObject : public virtual XMLObject + { + public: + ExtensibleXMLObject() {} + virtual ~ExtensibleXMLObject() {} + + /** + * Gets the text content of the object + * + * @return the text content, or NULL + */ + virtual const XMLCh* getTextContent() const=0; + + /** + * Sets (or clears) the text content of the object + * + * @param value value to set, or NULL to clear + */ + virtual void setTextContent(const XMLCh* value)=0; + + + /** + * Gets a mutable list of child objects + * + * @return mutable list of child objects + */ + virtual ListOf(XMLObject) getXMLObjects()=0; + }; + +}; + +#endif /* __xmltooling_extxmlobj_h__ */ diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am index 7e79c2f..37f7c40 100644 --- a/xmltooling/Makefile.am +++ b/xmltooling/Makefile.am @@ -3,23 +3,27 @@ AUTOMAKE_OPTIONS = foreign lib_LTLIBRARIES = libxmltooling.la libxmltoolingincludedir = \ - $(includedir)/xmltooling + $(includedir)/xmltooling libxmltoolinginclude_HEADERS = \ - AbstractDOMCachingXMLObject.h \ - AbstractXMLObject.h \ - base.h \ - config_pub.h \ - DOMCachingXMLObject.h \ - exceptions.h \ - ILockable.h \ - Namespace.h \ - QName.h \ - unicode.h \ - version.h \ - XMLObject.h \ - XMLObjectBuilder.h \ - XMLToolingConfig.h + AbstractAttributeExtensibleXMLObject.h \ + AbstractDOMCachingXMLObject.h \ + AbstractExtensibleXMLObject.h \ + AbstractXMLObject.h \ + AttributeExtensibleXMLObject.h \ + base.h \ + config_pub.h \ + DOMCachingXMLObject.h \ + exceptions.h \ + ExtensibleXMLObject.h \ + ILockable.h \ + Namespace.h \ + QName.h \ + unicode.h \ + version.h \ + XMLObject.h \ + XMLObjectBuilder.h \ + XMLToolingConfig.h utilincludedir = \ $(includedir)/xmltooling/util @@ -44,7 +48,9 @@ noinst_HEADERS = \ impl/UnknownElement.h libxmltooling_la_SOURCES = \ + AbstractAttributeExtensibleXMLObject.cpp \ AbstractDOMCachingXMLObject.cpp \ + AbstractExtensibleXMLObject.cpp \ Namespace.cpp \ QName.cpp \ unicode.cpp \ diff --git a/xmltooling/util/XMLObjectChildrenList.h b/xmltooling/util/XMLObjectChildrenList.h index a494952..91cda64 100644 --- a/xmltooling/util/XMLObjectChildrenList.h +++ b/xmltooling/util/XMLObjectChildrenList.h @@ -26,7 +26,9 @@ #include #include -#define ListOf(type) xmltooling::XMLObjectChildrenList +#define VectorOf(type) xmltooling::XMLObjectChildrenList< std::vector > +#define ListOf(type) xmltooling::XMLObjectChildrenList< std::list > +#define DequeOf(type) xmltooling::XMLObjectChildrenList< std::deque > namespace xmltooling { @@ -62,8 +64,8 @@ namespace xmltooling { return *m_iter; } - pointer operator->() const { - return (&**this); + const_reference operator->() const { + return *(m_iter.operator->()); } XMLObjectChildrenIterator& operator++() { @@ -138,113 +140,119 @@ namespace xmltooling { /** * STL-compatible container that mediates access to underlying lists of typed XML children. - * @param _Tx the subtype to expose a container over + * @param _Tx the subtype container to encapsulate * @param _Ty the base type in the underlying list (defaults to XMLObject) */ - template + template class XMLObjectChildrenList { - typedef typename std::vector<_Tx*> container; - typename XMLObjectChildrenList::container& m_vector; - typename std::list<_Ty*>& m_list; + typename Container& m_container; + typename std::list<_Ty*>* m_list; typename std::list<_Ty*>::iterator m_fence; XMLObject* m_parent; public: - typedef typename container::value_type value_type; - typedef typename container::reference reference; - typedef typename container::const_reference const_reference; - typedef typename container::difference_type difference_type; - typedef typename container::size_type size_type; + typedef typename Container::value_type value_type; + typedef typename Container::reference reference; + typedef typename Container::const_reference const_reference; + typedef typename Container::difference_type difference_type; + typedef typename Container::size_type size_type; // We override the iterator types with our constrained wrapper. - typedef XMLObjectChildrenIterator iterator; - typedef const XMLObjectChildrenIterator const_iterator; + typedef XMLObjectChildrenIterator iterator; + typedef const XMLObjectChildrenIterator const_iterator; /** * Constructor to expose a typed collection of children backed by a list of a base type. * * @param parent parent object of the collection - * @param v underlying vector of iterators that reference the children - * @param backing backing list for children + * @param sublist underlying container to expose + * @param backing pointer to backing list for children, if any * @param ins_fence a marker designating where new children of this type should be added */ XMLObjectChildrenList( XMLObject* parent, - typename XMLObjectChildrenList::container& v, - typename std::list<_Ty*>& backing, + Container& sublist, + typename std::list<_Ty*>* backing, typename std::list<_Ty*>::iterator ins_fence - ) : m_parent(parent), m_vector(v), m_list(backing), m_fence(ins_fence) { + ) : m_parent(parent), m_container(sublist), m_list(backing), m_fence(ins_fence) { } size_type size() const { // return length of sequence - return m_vector.size(); + return m_container.size(); } bool empty() const { // test if sequence is empty - return m_vector.empty(); + return m_container.empty(); } iterator begin() { // return iterator for beginning of mutable sequence - return m_vector.begin(); + return m_container.begin(); } iterator end() { // return iterator for end of mutable sequence - return m_vector.end(); + return m_container.end(); } const_iterator begin() const { // return iterator for beginning of const sequence - return m_vector.begin(); + return m_container.begin(); } const_iterator end() const { // return iterator for end of const sequence - return m_vector.end(); + return m_container.end(); } const_reference at(size_type _Pos) const { // subscript nonmutable sequence with checking - return m_vector.at(_Pos); + return m_container.at(_Pos); } const_reference operator[](size_type _Pos) const { // subscript nonmutable sequence - return m_vector[_Pos]; + return m_container[_Pos]; } const_reference front() const { // return first element of nonmutable sequence - return (*begin()); + return m_container.front(); } const_reference back() const { // return last element of nonmutable sequence - return *(m_vector.back()); + return m_container.back(); } void push_back(const_reference _Val) { setParent(_Val); - m_list.insert(m_fence,_Val); - m_vector.push_back(_Val); + if (m_list) + m_list->insert(m_fence,_Val); + m_container.push_back(_Val); } iterator erase(iterator _Where) { removeParent(*_Where); - removeChild(*_Where); - return m_vector.erase(_Where.m_iter); + if (m_list) + removeChild(*_Where); + return m_container.erase(_Where.m_iter); } iterator erase(iterator _First, iterator _Last) { for (iterator i=_First; i!=_Last; i++) { removeParent(*i); - removeChild(*i); + if (m_list) + removeChild(*i); } - return m_vector.erase(_First,_Last); + return m_container.erase(_First,_Last); + } + + void clear() { + erase(begin(),end()); } private: @@ -269,9 +277,9 @@ namespace xmltooling { } void removeChild(const_reference _Val) { - for (typename std::list<_Ty*>::iterator i=m_list.begin(); i!=m_list.end(); i++) { + for (typename std::list<_Ty*>::iterator i=m_list->begin(); i!=m_list->end(); i++) { if ((*i)==_Val) { - m_list.erase(i); + m_list->erase(i); delete _Val; return; } diff --git a/xmltooling/xmltooling.vcproj b/xmltooling/xmltooling.vcproj index c2dff62..0418077 100644 --- a/xmltooling/xmltooling.vcproj +++ b/xmltooling/xmltooling.vcproj @@ -182,10 +182,18 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + + + @@ -260,14 +268,26 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + + + + + @@ -284,6 +304,10 @@ > + + diff --git a/xmltoolingtest/MarshallingTest.h b/xmltoolingtest/MarshallingTest.h index dd476c9..b5f0814 100644 --- a/xmltoolingtest/MarshallingTest.h +++ b/xmltoolingtest/MarshallingTest.h @@ -81,7 +81,7 @@ public: auto_ptr sxObject(dynamic_cast(b->buildObject())); TS_ASSERT(sxObject.get()!=NULL); - ListOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects(); + VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects(); kids.push_back(dynamic_cast(b->buildObject())); kids.push_back(dynamic_cast(b->buildObject())); kids.push_back(dynamic_cast(b->buildObject())); @@ -89,9 +89,10 @@ public: // Test some collection stuff auto_ptr_XMLCh foo("Foo"); auto_ptr_XMLCh bar("Bar"); - kids[0]->setId(foo.get()); + kids.begin()->setId(foo.get()); kids.at(2)->setValue(bar.get()); kids.erase(kids.begin()+1); + TS_ASSERT_SAME_DATA(kids.back()->getValue(), bar.get(), XMLString::stringLen(bar.get())); DOMElement* rootElement = Marshaller::getMarshaller(sxObject.get())->marshall(sxObject.get()); diff --git a/xmltoolingtest/UnmarshallingTest.h b/xmltoolingtest/UnmarshallingTest.h index a5c87a4..f361266 100644 --- a/xmltoolingtest/UnmarshallingTest.h +++ b/xmltoolingtest/UnmarshallingTest.h @@ -108,7 +108,7 @@ public: auto_ptr sxObject(dynamic_cast(u->unmarshall(doc->getDocumentElement(),true))); TS_ASSERT(sxObject.get()!=NULL); - ListOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects(); + VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects(); TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, kids.size()); } diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index d69e1c0..48aa272 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -46,7 +46,7 @@ public: static const XMLCh NAMESPACE_PREFIX[]; static const XMLCh LOCAL_NAME[]; static const XMLCh ID_ATTRIB_NAME[]; - + SimpleXMLObject() : AbstractDOMCachingXMLObject(NAMESPACE, LOCAL_NAME, NAMESPACE_PREFIX), m_id(NULL), m_value(NULL) {} virtual ~SimpleXMLObject() { XMLString::release(&m_id); @@ -59,9 +59,8 @@ public: const XMLCh* getValue() const { return m_value; } void setValue(const XMLCh* value) { m_value=prepareForAssignment(m_value,value); } - // TODO: Leave non-const, but wrap STL container to intercept adds. - ListOf(SimpleXMLObject) getSimpleXMLObjects() { - return ListOf(SimpleXMLObject)(this, m_simples, m_children, m_children.end()); + VectorOf(SimpleXMLObject) getSimpleXMLObjects() { + return VectorOf(SimpleXMLObject)(this, m_simples, &m_children, m_children.end()); } SimpleXMLObject* clone() const { @@ -83,8 +82,6 @@ private: XMLCh* m_id; XMLCh* m_value; vector m_simples; - - friend class SimpleXMLObjectUnmarshaller; }; class SimpleXMLObjectBuilder : public XMLObjectBuilder @@ -130,8 +127,7 @@ private: SimpleXMLObject* child = dynamic_cast(childXMLObject); if (child) { - simpleXMLObject.m_children.push_back(child); - simpleXMLObject.m_simples.push_back(child); + simpleXMLObject.getSimpleXMLObjects().push_back(child); } else { throw UnmarshallingException("Unknown child element cannot be added to parent object."); -- 2.1.4