From 90685582ea6a9485b5459a66eceb6f69a2831d5f Mon Sep 17 00:00:00 2001 From: jez <> Date: Fri, 7 Sep 2007 22:03:27 +0000 Subject: [PATCH] working on DOM template params - build is currently broken --- include/DOM/Attr.hpp | 39 ++--- include/DOM/CDATASection.hpp | 24 +-- include/DOM/CharacterData.hpp | 28 ++-- include/DOM/Comment.hpp | 20 +-- include/DOM/DOMImplementation.hpp | 30 ++-- include/DOM/Document.hpp | 138 +++++++++--------- include/DOM/DocumentFragment.hpp | 20 +-- include/DOM/DocumentType.hpp | 43 +++--- include/DOM/Element.hpp | 63 ++++---- include/DOM/Entity.hpp | 26 ++-- include/DOM/EntityReference.hpp | 24 +-- include/DOM/NamedNodeMap.hpp | 50 ++++--- include/DOM/Node.hpp | 108 +++++++------- include/DOM/NodeList.hpp | 16 +- include/DOM/Notation.hpp | 26 ++-- include/DOM/ProcessingInstruction.hpp | 24 +-- include/DOM/Simple/AttrImpl.hpp | 42 +++--- include/DOM/Simple/AttrMap.hpp | 82 ++++++----- include/DOM/Simple/AttrNSImpl.hpp | 39 ++--- include/DOM/Simple/CDATASectionImpl.hpp | 25 ++-- include/DOM/Simple/ElementByTagImpl.hpp | 26 ++-- include/DOM/Simple/ElementImpl.hpp | 79 +++++----- include/DOM/Simple/NamedNodeMapImpl.hpp | 53 ++++--- include/DOM/Text.hpp | 29 ++-- include/DOM/Traversal/DocumentTraversal.hpp | 84 ++++++----- .../DOM/Traversal/DocumentTraversalImpl.hpp | 34 +++-- include/DOM/Traversal/NodeFilter.hpp | 9 +- include/DOM/Traversal/NodeIterator.hpp | 36 +++-- include/DOM/Traversal/TreeWalker.hpp | 65 +++++---- include/DOM/Traversal/TreeWalkerImpl.hpp | 14 +- 30 files changed, 694 insertions(+), 602 deletions(-) diff --git a/include/DOM/Attr.hpp b/include/DOM/Attr.hpp index 89256451..a4f3931f 100644 --- a/include/DOM/Attr.hpp +++ b/include/DOM/Attr.hpp @@ -14,20 +14,24 @@ namespace Arabica namespace DOM { -template class Element; -template class Attr_impl; +template class Element; +template class Attr_impl; -template -class Attr : public Node +template +class Attr : public Node { - typedef Node NodeT; public: - Attr() : Node() { } - explicit Attr(Attr_impl* impl) : Node(impl) { } - Attr(const Attr& rhs) : Node(rhs) { } - explicit Attr(const Node& rhs) : Node(rhs) + typedef Node NodeT; + typedef Element ElementT; + typedef Attr_impl Attr_implT; + + Attr() : NodeT() { } + + explicit Attr(Attr_implT* impl) : NodeT(impl) { } + Attr(const Attr& rhs) : NodeT(rhs) { } + explicit Attr(const NodeT& rhs) : NodeT(rhs) { - if(rhs.getNodeType() != Node::ATTRIBUTE_NODE) + if(rhs.getNodeType() != NodeT::ATTRIBUTE_NODE) throw std::bad_cast(); } // Attr @@ -38,21 +42,20 @@ class Attr : public Node const stringT& getValue() const { return attrImpl()->getValue(); } void setValue(const stringT& value) { attrImpl()->setValue(value); } - Element getOwnerElement() const { return Element(attrImpl()->getOwnerElement()); } + ElementT getOwnerElement() const { return ElementT(attrImpl()->getOwnerElement()); } private: - Attr_impl* attrImpl() const { return dynamic_cast*>(*NodeT::impl_); } + Attr_implT* attrImpl() const { return dynamic_cast(*NodeT::impl_); } - typedef Element ElementT; - friend class Element; + friend class Element; }; // class Attr ////////////////////////////////////////////////////////// -template class Element_impl; +template class Element_impl; -template -class Attr_impl : virtual public Node_impl +template +class Attr_impl : virtual public Node_impl { public: virtual ~Attr_impl() { } @@ -66,7 +69,7 @@ class Attr_impl : virtual public Node_impl virtual const stringT& getValue() const = 0; virtual void setValue(const stringT& value) = 0; - virtual Element_impl* getOwnerElement() const = 0; + virtual Element_impl* getOwnerElement() const = 0; }; // class Attr_impl } // namespace DOM diff --git a/include/DOM/CDATASection.hpp b/include/DOM/CDATASection.hpp index 9f7debed..51eb2791 100644 --- a/include/DOM/CDATASection.hpp +++ b/include/DOM/CDATASection.hpp @@ -13,33 +13,33 @@ namespace Arabica { namespace DOM { -template class CDATASection_impl; +template class CDATASection_impl; -template -class CDATASection : public Text +template +class CDATASection : public Text { - typedef Text TextT; + typedef Text TextT; public: - CDATASection() : Text() { } - explicit CDATASection(CDATASection_impl* impl) : Text(impl) { } - CDATASection(const CDATASection& rhs) : Text(rhs) { } - explicit CDATASection(const Node& rhs) : Text(rhs, 0) + CDATASection() : Text() { } + explicit CDATASection(CDATASection_impl* impl) : Text(impl) { } + CDATASection(const CDATASection& rhs) : Text(rhs) { } + explicit CDATASection(const Node& rhs) : Text(rhs, 0) { if(rhs.getNodeType() != Node_base::CDATA_SECTION_NODE) //throw std::runtime_error("bad_cast: Cannot convert Node to CDATA section"); throw std::bad_cast(); } // CDATASection - CDATASection splitText(int offset) + CDATASection splitText(int offset) { TextT::tImpl()->throwIfReadOnly(); - return static_cast >(TextT::tImpl()->splitText(offset)); + return static_cast >(TextT::tImpl()->splitText(offset)); } // splitText }; // class CDATASection //////////////////////////////////////////////////////////////////// -template -class CDATASection_impl : public virtual Text_impl +template +class CDATASection_impl : public virtual Text_impl { public: virtual ~CDATASection_impl() { } diff --git a/include/DOM/CharacterData.hpp b/include/DOM/CharacterData.hpp index 82d99653..6df6c9d9 100644 --- a/include/DOM/CharacterData.hpp +++ b/include/DOM/CharacterData.hpp @@ -13,17 +13,19 @@ namespace Arabica { namespace DOM { -template class CharacterData_impl; +template class CharacterData_impl; -template -class CharacterData : public Node +template +class CharacterData : public Node { - typedef Node NodeT; + typedef CharacterData_impl CharacterData_implT; public: - CharacterData() : Node() { } - explicit CharacterData(CharacterData_impl* impl) : Node(impl) { } - CharacterData(const CharacterData& rhs) : Node(rhs) { } - explicit CharacterData(const Node& rhs) : Node(rhs) + typedef Node NodeT; + + CharacterData() : NodeT() { } + explicit CharacterData(CharacterData_implT* impl) : NodeT(impl) { } + CharacterData(const CharacterData& rhs) : NodeT(rhs) { } + explicit CharacterData(const NodeT& rhs) : NodeT(rhs) { typename NodeT::Type type = rhs.getNodeType(); if((type != NodeT::TEXT_NODE) && (type != NodeT::CDATA_SECTION_NODE)) @@ -31,7 +33,7 @@ class CharacterData : public Node } // CharacterData protected: - CharacterData(const Node& rhs, int dummy) : Node(rhs) { } + CharacterData(const NodeT& rhs, int dummy) : NodeT(rhs) { } public: const stringT& getData() const { return cdImpl()->getData(); } @@ -62,13 +64,13 @@ class CharacterData : public Node } // replaceData private: - CharacterData_impl* cdImpl() { return dynamic_cast*>(*NodeT::impl_); } - const CharacterData_impl* cdImpl() const { return dynamic_cast*>(*NodeT::impl_); } + CharacterData_implT* cdImpl() { return dynamic_cast(*NodeT::impl_); } + const CharacterData_implT* cdImpl() const { return dynamic_cast(*NodeT::impl_); } }; // class CharacterData //////////////////////////////////////////////////////////////////// -template -class CharacterData_impl : virtual public Node_impl +template +class CharacterData_impl : virtual public Node_impl { public: virtual ~CharacterData_impl () { } diff --git a/include/DOM/Comment.hpp b/include/DOM/Comment.hpp index db7316af..8d642dbd 100644 --- a/include/DOM/Comment.hpp +++ b/include/DOM/Comment.hpp @@ -13,25 +13,25 @@ namespace Arabica { namespace DOM { -template class Comment_impl; +template class Comment_impl; -template -class Comment : public CharacterData +template +class Comment : public CharacterData { public: - Comment() : CharacterData() { } - explicit Comment(Comment_impl* impl) : CharacterData(dynamic_cast*>(impl)) { } - Comment(const Comment& rhs) : CharacterData(rhs) { } - explicit Comment(const Node& rhs) : CharacterData(rhs) + Comment() : CharacterData() { } + explicit Comment(Comment_impl* impl) : CharacterData(dynamic_cast*>(impl)) { } + Comment(const Comment& rhs) : CharacterData(rhs) { } + explicit Comment(const Node& rhs) : CharacterData(rhs) { - if(dynamic_cast*>(rhs.impl()) == 0) + if(dynamic_cast*>(rhs.impl()) == 0) throw std::bad_cast(); } // Comment }; // class Comment //////////////////////////////////////////////////////////////////// -template -class Comment_impl : virtual public CharacterData_impl +template +class Comment_impl : virtual public CharacterData_impl { public: virtual ~Comment_impl() { } diff --git a/include/DOM/DOMImplementation.hpp b/include/DOM/DOMImplementation.hpp index 3ec91ac5..933288e9 100644 --- a/include/DOM/DOMImplementation.hpp +++ b/include/DOM/DOMImplementation.hpp @@ -14,16 +14,16 @@ namespace Arabica namespace DOM { -template class Document; -template class DocumentType; -template class DOMImplementation_impl; +template class Document; +template class DocumentType; +template class DOMImplementation_impl; -template +template class DOMImplementation { public: DOMImplementation() : impl_(0) { } - DOMImplementation(DOMImplementation_impl* impl) : impl_(impl) { } + DOMImplementation(DOMImplementation_impl* impl) : impl_(impl) { } DOMImplementation(const DOMImplementation& rhs) : impl_(rhs.impl_) { } operator bool() const { return impl_; } @@ -43,31 +43,31 @@ class DOMImplementation return impl_->hasFeature(feature, version); } // hasFeature - DocumentType createDocumentType(const stringT& qualifiedName, + DocumentType createDocumentType(const stringT& qualifiedName, const stringT& publicId, const stringT& systemId) { return impl_->createDocumentType(qualifiedName, publicId, systemId); } // createDocumentType - Document createDocument(const stringT& namespaceURI, + Document createDocument(const stringT& namespaceURI, const stringT& qualifiedName, - DocumentType docType) + DocumentType docType) { return impl_->createDocument(namespaceURI, qualifiedName, docType.dtImpl()); } // createDocument private: - Proxy > impl_; + Proxy > impl_; }; // class DOMImplementation ///////////////////////////////////////////////// -template class Document_impl; -template class DocumentType_impl; +template class Document_impl; +template class DocumentType_impl; // derive from this class to implement your own // DOM provider -template +template class DOMImplementation_impl { public: @@ -80,13 +80,13 @@ class DOMImplementation_impl // DOM implementation methods virtual bool hasFeature(const stringT& feature, const stringT& version) const = 0; - virtual DocumentType_impl* createDocumentType(const stringT& qualifiedName, + virtual DocumentType_impl* createDocumentType(const stringT& qualifiedName, const stringT& publicId, const stringT& systemId) = 0; - virtual Document_impl* createDocument(const stringT& namespaceURI, + virtual Document_impl* createDocument(const stringT& namespaceURI, const stringT& qualifiedName, - DocumentType_impl* docType) = 0; + DocumentType_impl* docType) = 0; protected: DOMImplementation_impl() { } diff --git a/include/DOM/Document.hpp b/include/DOM/Document.hpp index dcf30415..075eb4e3 100644 --- a/include/DOM/Document.hpp +++ b/include/DOM/Document.hpp @@ -30,146 +30,146 @@ namespace DOM { namespace Events { - template class DocumentEvent; + template class DocumentEvent; } // namespace Events -template class Document_impl; +template class Document_impl; -template -class Document : public Node +template +class Document : public Node { - typedef Node NodeT; + typedef Node NodeT; public: - Document() : Node() { } - Document(Document_impl* impl) : Node(impl) { } - Document(const Document& rhs) : Node(rhs) { } - explicit Document(const Node& rhs) : Node(rhs) + Document() : Node() { } + Document(Document_impl* impl) : Node(impl) { } + Document(const Document& rhs) : Node(rhs) { } + explicit Document(const Node& rhs) : Node(rhs) { - if(rhs.getNodeType() != Node::DOCUMENT_NODE) + if(rhs.getNodeType() != Node::DOCUMENT_NODE) throw std::bad_cast(); } // Document ~Document() { } Document& operator=(const Document& rhs) { - Node::operator=(rhs); + Node::operator=(rhs); return *this; } // operator - DocumentType getDoctype() const { return dImpl()->getDoctype(); } + DocumentType getDoctype() const { return dImpl()->getDoctype(); } - DOMImplementation getImplementation() const { return DOMImplementation(dImpl()->getImplementation()); } + DOMImplementation getImplementation() const { return DOMImplementation(dImpl()->getImplementation()); } - Element getDocumentElement() const { return Element(dImpl()->getDocumentElement()); } + Element getDocumentElement() const { return Element(dImpl()->getDocumentElement()); } - Element createElement(const stringT& tagName) const { return Element(dImpl()->createElement(tagName)); } + Element createElement(const stringT& tagName) const { return Element(dImpl()->createElement(tagName)); } - DocumentFragment createDocumentFragment() const { return DocumentFragment(dImpl()->createDocumentFragment()); } + DocumentFragment createDocumentFragment() const { return DocumentFragment(dImpl()->createDocumentFragment()); } - Text createTextNode(const stringT& data) const { return Text(dImpl()->createTextNode(data)); } + Text createTextNode(const stringT& data) const { return Text(dImpl()->createTextNode(data)); } - Comment createComment(const stringT& data) const { return Comment(dImpl()->createComment(data)); } + Comment createComment(const stringT& data) const { return Comment(dImpl()->createComment(data)); } - CDATASection createCDATASection(const stringT& data) const { return CDATASection(dImpl()->createCDATASection(data)); } + CDATASection createCDATASection(const stringT& data) const { return CDATASection(dImpl()->createCDATASection(data)); } - ProcessingInstruction createProcessingInstruction(const stringT& target, const stringT& data) const + ProcessingInstruction createProcessingInstruction(const stringT& target, const stringT& data) const { - return ProcessingInstruction(dImpl()->createProcessingInstruction(target, data)); + return ProcessingInstruction(dImpl()->createProcessingInstruction(target, data)); } // createProcessingInstruction - Attr createAttribute(const stringT& name) const { return Attr(dImpl()->createAttribute(name)); } + Attr createAttribute(const stringT& name) const { return Attr(dImpl()->createAttribute(name)); } - EntityReference createEntityReference(const stringT& name) const { return EntityReference(dImpl()->createEntityReference(name)); } + EntityReference createEntityReference(const stringT& name) const { return EntityReference(dImpl()->createEntityReference(name)); } - NodeList getElementsByTagName(const stringT& tagname) const { return NodeList(dImpl()->getElementsByTagName(tagname)); } + NodeList getElementsByTagName(const stringT& tagname) const { return NodeList(dImpl()->getElementsByTagName(tagname)); } - Node importNode(const Node& importedNode, bool deep) const { return Node(dImpl()->importNode(*importedNode.impl_, deep)); } + Node importNode(const Node& importedNode, bool deep) const { return Node(dImpl()->importNode(*importedNode.impl_, deep)); } - Element createElementNS(const stringT& namespaceURI, const stringT& qualifiedName) const + Element createElementNS(const stringT& namespaceURI, const stringT& qualifiedName) const { - return Element(dImpl()->createElementNS(namespaceURI, qualifiedName)); + return Element(dImpl()->createElementNS(namespaceURI, qualifiedName)); } // createElementNS - Attr createAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName) const + Attr createAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName) const { - return Attr(dImpl()->createAttributeNS(namespaceURI, qualifiedName)); + return Attr(dImpl()->createAttributeNS(namespaceURI, qualifiedName)); } // createAttributeNS - NodeList getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const + NodeList getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const { - return NodeList(dImpl()->getElementsByTagNameNS(namespaceURI, localName)); + return NodeList(dImpl()->getElementsByTagNameNS(namespaceURI, localName)); } // getElementsByTagNameNS - Element getElementById(const stringT& elementId) const { return Element(dImpl()->getElementById(elementId)); } + Element getElementById(const stringT& elementId) const { return Element(dImpl()->getElementById(elementId)); } - Traversal::DocumentTraversal createDocumentTraversal() + Traversal::DocumentTraversal createDocumentTraversal() { - Traversal::DocumentTraversal docTraversal(new Traversal::DocumentTraversalImpl()); + Traversal::DocumentTraversal docTraversal(new Traversal::DocumentTraversalImpl()); return docTraversal; } private: - Document_impl* dImpl() const { return dynamic_cast*>(*NodeT::impl_); } + Document_impl* dImpl() const { return dynamic_cast*>(*NodeT::impl_); } - typedef class Traversal::DocumentTraversal DocumentTraversalT; - friend class Traversal::DocumentTraversal; - typedef class Events::DocumentEvent DocumentEventT; - friend class Events::DocumentEvent; + typedef class Traversal::DocumentTraversal DocumentTraversalT; + friend class Traversal::DocumentTraversal; + typedef class Events::DocumentEvent DocumentEventT; + friend class Events::DocumentEvent; }; // class DocumentFragment ////////////////////////////////////////////////////////// -template class DocumentType_impl; -template class DOMImplementation_impl; -template class Element_impl; -template class DocumentFragment_impl; -template class Text_impl; -template class Comment_impl; -template class CDATASection_impl; -template class ProcessingInstruction_impl; -template class Attr_impl; -template class EntityReference_impl; -template class NodeList_impl; +template class DocumentType_impl; +template class DOMImplementation_impl; +template class Element_impl; +template class DocumentFragment_impl; +template class Text_impl; +template class Comment_impl; +template class CDATASection_impl; +template class ProcessingInstruction_impl; +template class Attr_impl; +template class EntityReference_impl; +template class NodeList_impl; -template -class Document_impl : virtual public Node_impl +template +class Document_impl : virtual public Node_impl { public: virtual ~Document_impl() { } - virtual DocumentType_impl* getDoctype() const = 0; + virtual DocumentType_impl* getDoctype() const = 0; - virtual DOMImplementation getImplementation() const = 0; + virtual DOMImplementation getImplementation() const = 0; - virtual Element_impl* getDocumentElement() const = 0; + virtual Element_impl* getDocumentElement() const = 0; - virtual Element_impl* createElement(const stringT& tagName) const = 0; + virtual Element_impl* createElement(const stringT& tagName) const = 0; - virtual DocumentFragment_impl* createDocumentFragment() const = 0; + virtual DocumentFragment_impl* createDocumentFragment() const = 0; - virtual Text_impl* createTextNode(const stringT& data) const = 0; + virtual Text_impl* createTextNode(const stringT& data) const = 0; - virtual Comment_impl* createComment(const stringT& data) const = 0; + virtual Comment_impl* createComment(const stringT& data) const = 0; - virtual CDATASection_impl* createCDATASection(const stringT& data) const = 0; + virtual CDATASection_impl* createCDATASection(const stringT& data) const = 0; - virtual ProcessingInstruction_impl* createProcessingInstruction(const stringT& target, const stringT& data) const = 0; + virtual ProcessingInstruction_impl* createProcessingInstruction(const stringT& target, const stringT& data) const = 0; - virtual Attr_impl* createAttribute(const stringT& name) const = 0; + virtual Attr_impl* createAttribute(const stringT& name) const = 0; - virtual EntityReference_impl* createEntityReference(const stringT& name) const = 0; + virtual EntityReference_impl* createEntityReference(const stringT& name) const = 0; - virtual NodeList_impl* getElementsByTagName(const stringT& tagname) const = 0; + virtual NodeList_impl* getElementsByTagName(const stringT& tagname) const = 0; - virtual Node_impl* importNode(Node_impl* importedNode, bool deep) const = 0; + virtual Node_impl* importNode(Node_impl* importedNode, bool deep) const = 0; - virtual Element_impl* createElementNS(const stringT& namespaceURI, const stringT& qualifiedName) const = 0; + virtual Element_impl* createElementNS(const stringT& namespaceURI, const stringT& qualifiedName) const = 0; - virtual Attr_impl* createAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName) const = 0; + virtual Attr_impl* createAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName) const = 0; - virtual NodeList_impl* getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const = 0; + virtual NodeList_impl* getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const = 0; - virtual Element_impl* getElementById(const stringT& elementId) const = 0; + virtual Element_impl* getElementById(const stringT& elementId) const = 0; }; // class Document_impl } // namespace DOM diff --git a/include/DOM/DocumentFragment.hpp b/include/DOM/DocumentFragment.hpp index 4e75b1bb..4ba2d942 100644 --- a/include/DOM/DocumentFragment.hpp +++ b/include/DOM/DocumentFragment.hpp @@ -15,25 +15,25 @@ namespace Arabica namespace DOM { -template class DocumentFragment_impl; +template class DocumentFragment_impl; -template -class DocumentFragment : public Node +template +class DocumentFragment : public Node { public: - DocumentFragment() : Node() { } - explicit DocumentFragment(DocumentFragment_impl* impl) : Node(impl) { } - DocumentFragment(const DocumentFragment& rhs) : Node(rhs) { } - explicit DocumentFragment(const Node& rhs) : Node(rhs) + DocumentFragment() : Node() { } + explicit DocumentFragment(DocumentFragment_impl* impl) : Node(impl) { } + DocumentFragment(const DocumentFragment& rhs) : Node(rhs) { } + explicit DocumentFragment(const Node& rhs) : Node(rhs) { - if(rhs.getNodeType() != Node::DOCUMENT_FRAGMENT_NODE) + if(rhs.getNodeType() != Node::DOCUMENT_FRAGMENT_NODE) throw std::bad_cast(); } }; // class DocumentFragment ////////////////////////////////////////////////////////// -template -class DocumentFragment_impl : virtual public Node_impl +template +class DocumentFragment_impl : virtual public Node_impl { public: virtual ~DocumentFragment_impl() { } diff --git a/include/DOM/DocumentType.hpp b/include/DOM/DocumentType.hpp index 216c963c..0cd4a63a 100644 --- a/include/DOM/DocumentType.hpp +++ b/include/DOM/DocumentType.hpp @@ -16,28 +16,32 @@ namespace Arabica namespace DOM { -template class Document_impl; -template class DocumentType_impl; +template class Document_impl; +template class DocumentType_impl; -template -class DocumentType : public Node +template +class DocumentType : public Node { - typedef Node NodeT; + typedef DocumentType_impl DocumentType_implT; public: - DocumentType() : Node(0) { } - DocumentType(DocumentType_impl* impl) : Node(impl) { } - DocumentType(const DocumentType& rhs) : Node(rhs) { } - explicit DocumentType(const Node& rhs) : Node(rhs) + typedef Node NodeT; + typedef NamedNodeMap NamedNodeMapT; + typedef DOMImplementation DOMImplementationT; + + DocumentType() : NodeT(0) { } + DocumentType(DocumentType_implT* impl) : NodeT(impl) { } + DocumentType(const DocumentType& rhs) : NodeT(rhs) { } + explicit DocumentType(const NodeT& rhs) : NodeT(rhs) { - if(rhs.getNodeType() != Node::DOCUMENT_TYPE_NODE) + if(rhs.getNodeType() != NodeT::DOCUMENT_TYPE_NODE) throw std::bad_cast(); } // DocumentType const stringT& getName() const { return dtImpl()->getName(); } - const NamedNodeMap getEntities() const { return NamedNodeMap(dtImpl()->getEntities()); } + const NamedNodeMapT getEntities() const { return NamedNodeMapT(dtImpl()->getEntities()); } - const NamedNodeMap getNotations() const { return NamedNodeMap(dtImpl()->getNotations()); } + const NamedNodeMapT getNotations() const { return NamedNodeMapT(dtImpl()->getNotations()); } stringT getPublicId() const { return dtImpl()->getPublicId(); } @@ -46,26 +50,27 @@ class DocumentType : public Node stringT getInternalSubset() const { return dtImpl()->getInternalSubset(); } protected: - DocumentType_impl* dtImpl() const { return dynamic_cast*>(*NodeT::impl_); } + DocumentType_implT* dtImpl() const { return dynamic_cast(*NodeT::impl_); } - typedef DOMImplementation DOMImplementationT; - friend class DOMImplementation; + friend class DOMImplementation; }; // class DocumentType ////////////////////////////////////////////////////////// -template -class DocumentType_impl : virtual public Node_impl +template +class DocumentType_impl : virtual public Node_impl { public: + typedef NamedNodeMap_impl NamedNodeMap_implT; + virtual ~DocumentType_impl() { } ///////////////////////////////////////////// // DOM::DocumentType methods virtual const stringT& getName() const = 0; - virtual NamedNodeMap_impl* getEntities() = 0; + virtual NamedNodeMap_implT* getEntities() = 0; - virtual NamedNodeMap_impl* getNotations() = 0; + virtual NamedNodeMap_implT* getNotations() = 0; virtual stringT getPublicId() const = 0; diff --git a/include/DOM/Element.hpp b/include/DOM/Element.hpp index 844439af..fcbc63b1 100644 --- a/include/DOM/Element.hpp +++ b/include/DOM/Element.hpp @@ -16,21 +16,25 @@ namespace Arabica namespace DOM { -template class Attr; -template class NodeList; -template class Element_impl; +template class Attr; +template class NodeList; +template class Element_impl; -template -class Element : public Node +template +class Element : public Node { - typedef Node NodeT; + typedef Element_impl Element_implT; public: - Element() : Node() { } - explicit Element(Element_impl* impl) : Node(impl) { } - Element(const Element& rhs) : Node(rhs) { } - explicit Element(const Node& rhs) : Node(rhs) + typedef Node NodeT; + typedef NodeList NodeListT; + typedef Attr AttrT; + + Element() : NodeT() { } + explicit Element(Element_implT* impl) : NodeT(impl) { } + Element(const Element& rhs) : NodeT(rhs) { } + explicit Element(const NodeT& rhs) : NodeT(rhs) { - if(rhs.getNodeType() != Node::ELEMENT_NODE) + if(rhs.getNodeType() != NodeT::ELEMENT_NODE) throw std::bad_cast(); } // Element @@ -40,34 +44,37 @@ class Element : public Node void setAttribute(const stringT& name, const stringT& value) { eImpl()->setAttribute(name, value); } void removeAttribute(const stringT& name) { eImpl()->removeAttribute(name); } - Attr getAttributeNode(const stringT& name) const { return Attr(eImpl()->getAttributeNode(name)); } - Attr setAttributeNode(const Attr& newAttr) { return Attr(eImpl()->setAttributeNode(newAttr.attrImpl())); } - Attr removeAttributeNode(const Attr& oldAttr) { return Attr(eImpl()->removeAttributeNode(oldAttr.attrImpl())); } + AttrT getAttributeNode(const stringT& name) const { return AttrT(eImpl()->getAttributeNode(name)); } + AttrT setAttributeNode(const AttrT& newAttr) { return AttrT(eImpl()->setAttributeNode(newAttr.attrImpl())); } + AttrT removeAttributeNode(const AttrT& oldAttr) { return AttrT(eImpl()->removeAttributeNode(oldAttr.attrImpl())); } - NodeList getElementsByTagName(const stringT& tagName) const { return NodeList(eImpl()->getElementsByTagName(tagName)); } + NodeListT getElementsByTagName(const stringT& tagName) const { return NodeListT(eImpl()->getElementsByTagName(tagName)); } stringT getAttributeNS(const stringT& namespaceURI, const stringT& localName) const { return eImpl()->getAttributeNS(namespaceURI, localName); } void setAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName, const stringT& value) { eImpl()->setAttributeNS(namespaceURI, qualifiedName, value); } void removeAttributeNS(const stringT& namespaceURI, const stringT& localName) { return eImpl()->removeAttributeNS(namespaceURI, localName); } - Attr getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const { return Attr(eImpl()->getAttributeNodeNS(namespaceURI, localName)); } - Attr setAttributeNodeNS(const Attr& newAttr) { return Attr(eImpl()->getAttributeNodeNS(newAttr)); } + AttrT getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const { return AttrT(eImpl()->getAttributeNodeNS(namespaceURI, localName)); } + AttrT setAttributeNodeNS(const AttrT& newAttr) { return AttrT(eImpl()->getAttributeNodeNS(newAttr)); } - NodeList getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const { return NodeList(eImpl()->getElementsByTagNameNS(namespaceURI, localName)); } + NodeListT getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const { return NodeListT(eImpl()->getElementsByTagNameNS(namespaceURI, localName)); } bool hasAttribute(const stringT& name) const { return eImpl()->hasAttribute(name); } bool hasAttributeNS(const stringT& namespaceURI, const stringT& localName) const { return eImpl()->hasAttributeNS(namespaceURI, localName); } private: - Element_impl* eImpl() const { return dynamic_cast*>(*NodeT::impl_); } + Element_implT* eImpl() const { return dynamic_cast(*NodeT::impl_); } }; // class Element /////////////////////////////////////////////////////////// -template -class Element_impl : virtual public Node_impl +template +class Element_impl : virtual public Node_impl { public: + typedef NodeList_impl NodeList_implT; + typedef Attr_impl Attr_implT; + virtual ~Element_impl () { } //////////////////////////////////////////////////////// @@ -78,20 +85,20 @@ class Element_impl : virtual public Node_impl virtual void setAttribute(const stringT& name, const stringT& value) = 0; virtual void removeAttribute(const stringT& name) = 0; - virtual Attr_impl* getAttributeNode(const stringT& name) const = 0; - virtual Attr_impl* setAttributeNode(Attr_impl* newAttr) = 0; - virtual Attr_impl* removeAttributeNode(Attr_impl* oldAttr) = 0; + virtual Attr_implT* getAttributeNode(const stringT& name) const = 0; + virtual Attr_implT* setAttributeNode(Attr_implT* newAttr) = 0; + virtual Attr_implT* removeAttributeNode(Attr_implT* oldAttr) = 0; - virtual NodeList_impl* getElementsByTagName(const stringT& tagName) const = 0; + virtual NodeList_implT* getElementsByTagName(const stringT& tagName) const = 0; virtual stringT getAttributeNS(const stringT& namespaceURI, const stringT& localName) const = 0; virtual void setAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName, const stringT& value) = 0; virtual void removeAttributeNS(const stringT& namespaceURI, const stringT& localName) = 0; - virtual Attr_impl* getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const = 0; - virtual Attr_impl* setAttributeNodeNS(Attr_impl* newAttr) = 0; + virtual Attr_implT* getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const = 0; + virtual Attr_implT* setAttributeNodeNS(Attr_implT* newAttr) = 0; - virtual NodeList_impl* getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const = 0; + virtual NodeList_implT* getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const = 0; virtual bool hasAttribute(const stringT& name) const = 0; diff --git a/include/DOM/Entity.hpp b/include/DOM/Entity.hpp index 40684ec9..09f269d5 100644 --- a/include/DOM/Entity.hpp +++ b/include/DOM/Entity.hpp @@ -14,19 +14,19 @@ namespace Arabica namespace DOM { -template class Entity_impl; +template class Entity_impl; -template -class Entity : public Node +template +class Entity : public Node { - typedef Node NodeT; + typedef Node NodeT; public: - Entity() : Node() { } - explicit Entity(Entity_impl* impl) : Node(impl) { } - Entity(const Entity& rhs) : Node(rhs) { } - explicit Entity(const Node& rhs) : Node(rhs) + Entity() : Node() { } + explicit Entity(Entity_impl* impl) : Node(impl) { } + Entity(const Entity& rhs) : Node(rhs) { } + explicit Entity(const Node& rhs) : Node(rhs) { - if(rhs.getNodeType() != Node::Entity_NODE) + if(rhs.getNodeType() != Node::Entity_NODE) throw std::bad_cast(); } @@ -37,14 +37,14 @@ class Entity : public Node stringT getNotationName() const { nImpl()->getNotationName(); } private: - Entity_impl* nImpl() { return dynamic_cast*>(NodeT::impl()); } + Entity_impl* nImpl() { return dynamic_cast*>(NodeT::impl()); } }; // class Entity ////////////////////////////////////////////////////////// -template class NamedNodeMap_impl; +template class NamedNodeMap_impl; -template -class Entity_impl : virtual public Node_impl +template +class Entity_impl : virtual public Node_impl { public: virtual ~Entity_impl () { } diff --git a/include/DOM/EntityReference.hpp b/include/DOM/EntityReference.hpp index 6e9807a1..c7e5a897 100644 --- a/include/DOM/EntityReference.hpp +++ b/include/DOM/EntityReference.hpp @@ -13,25 +13,29 @@ namespace Arabica { namespace DOM { -template class EntityReference_impl; +template class EntityReference_impl; -template -class EntityReference : public Node +template +class EntityReference : public Node { + typedef EntityReference_impl EntityReference_implT; + public: - EntityReference() : Node() { } - explicit EntityReference(EntityReference_impl* impl) : Node(impl) { } - EntityReference(const EntityReference& rhs) : Node(rhs) { } - explicit EntityReference(const Node& rhs) : Node(rhs) + typedef Node NodeT; + + EntityReference() : NodeT() { } + explicit EntityReference(EntityReference_implT* impl) : NodeT(impl) { } + EntityReference(const EntityReference& rhs) : NodeT(rhs) { } + explicit EntityReference(const NodeT& rhs) : NodeT(rhs) { - if(dynamic_cast*>(rhs.impl()) == 0) + if(dynamic_cast(rhs.impl()) == 0) throw std::bad_cast(); } // EntityReference }; // class EntityReference //////////////////////////////////////////////////////////////////// -template -class EntityReference_impl : virtual public Node_impl +template +class EntityReference_impl : virtual public Node_impl { public: virtual ~EntityReference_impl () { } diff --git a/include/DOM/NamedNodeMap.hpp b/include/DOM/NamedNodeMap.hpp index f48edb42..170fd22e 100644 --- a/include/DOM/NamedNodeMap.hpp +++ b/include/DOM/NamedNodeMap.hpp @@ -14,15 +14,17 @@ namespace Arabica namespace DOM { -template class Node; -template class NamedNodeMap_impl; +template class Node; +template class NamedNodeMap_impl; -template +template class NamedNodeMap { public: + typedef Node NodeT; + NamedNodeMap() : impl_(0) { } - explicit NamedNodeMap(NamedNodeMap_impl* impl) : impl_(impl) { } + explicit NamedNodeMap(NamedNodeMap_impl* impl) : impl_(impl) { } NamedNodeMap(const NamedNodeMap& rhs) : impl_(rhs.impl_) { } virtual ~NamedNodeMap() { } @@ -37,40 +39,42 @@ class NamedNodeMap return *this; } // operator= - Node getNamedItem(const stringT& name) const { return Node(impl_->getNamedItem(name)); } + NodeT getNamedItem(const stringT& name) const { return NodeT(impl_->getNamedItem(name)); } - Node setNamedItem(const Node& arg) { return Node(impl_->setNamedItem(arg)); } + NodeT setNamedItem(const NodeT& arg) { return NodeT(impl_->setNamedItem(arg)); } - Node removeNamedItem(const stringT& name) const { return Node(impl_->removeNamedItem(name)); } + NodeT removeNamedItem(const stringT& name) const { return NodeT(impl_->removeNamedItem(name)); } - Node item(unsigned int index) const { return Node(impl_->item(index)); } + NodeT item(unsigned int index) const { return NodeT(impl_->item(index)); } unsigned int getLength() const { return impl_->getLength(); } - Node getNamedItemNS(const stringT& namespaceURI, const stringT& localName) const + NodeT getNamedItemNS(const stringT& namespaceURI, const stringT& localName) const { - return Node(impl_->getNamedItemNS(namespaceURI, localName)); + return NodeT(impl_->getNamedItemNS(namespaceURI, localName)); } // getNamedItemNS - Node setNamedItemNS(const Node& arg) { return Node(impl_->setNamedItemNS(arg)); } + NodeT setNamedItemNS(const NodeT& arg) { return NodeT(impl_->setNamedItemNS(arg)); } - Node removeNamedItemNS(const stringT& namespaceURI, const stringT& localName) const + NodeT removeNamedItemNS(const stringT& namespaceURI, const stringT& localName) const { - return Node(impl_->removeNamedItem(namespaceURI, localName)); + return NodeT(impl_->removeNamedItem(namespaceURI, localName)); } // removeNamedItemNS private: - Proxy > impl_; + Proxy > impl_; }; // class NamedNodeMap //////////////////////////////////////////////////// // NamedNodeMap_impl -template class Node_impl; +template class Node_impl; -template +template class NamedNodeMap_impl { public: + typedef Node_impl Node_implT; + virtual ~NamedNodeMap_impl() { } /////////////////////////////////////////////////////// @@ -80,17 +84,17 @@ class NamedNodeMap_impl /////////////////////////////////////////////////////// // NamedNodeMap methods - virtual Node_impl* getNamedItem(const stringT& name) const = 0; - virtual Node_impl* setNamedItem(Node_impl* arg) = 0; - virtual Node_impl* removeNamedItem(const stringT& name) = 0; + virtual Node_implT* getNamedItem(const stringT& name) const = 0; + virtual Node_implT* setNamedItem(Node_implT* arg) = 0; + virtual Node_implT* removeNamedItem(const stringT& name) = 0; - virtual Node_impl* item(unsigned int index) const = 0; + virtual Node_implT* item(unsigned int index) const = 0; virtual unsigned int getLength() const = 0; - virtual Node_impl* getNamedItemNS(const stringT& namespaceURI, const stringT& localName) const = 0; - virtual Node_impl* setNamedItemNS(Node_impl* arg) = 0; - virtual Node_impl* removeNamedItemNS(const stringT& namespaceURI, const stringT& localName) = 0; + virtual Node_implT* getNamedItemNS(const stringT& namespaceURI, const stringT& localName) const = 0; + virtual Node_implT* setNamedItemNS(Node_implT* arg) = 0; + virtual Node_implT* removeNamedItemNS(const stringT& namespaceURI, const stringT& localName) = 0; }; // class NamedNodeMap_impl } // namespace DOM diff --git a/include/DOM/Node.hpp b/include/DOM/Node.hpp index 79667806..100d21a3 100644 --- a/include/DOM/Node.hpp +++ b/include/DOM/Node.hpp @@ -17,13 +17,13 @@ namespace DOM { namespace Events { - template class EventTarget; + template class EventTarget; } // namespace Events -template class Document; -template class NodeList; -template class NamedNodeMap; -template class Node_impl; +template class Document; +template class NodeList; +template class NamedNodeMap; +template class Node_impl; class Node_base { @@ -47,14 +47,12 @@ class Node_base }; // class Node_base ///////////////////////////////////////////////// -template +template class Node : public Node_base { public: - typedef node_string_type string_type; - Node() : impl_() { } - Node(Node_impl* const impl) : impl_(impl) { } + Node(Node_impl* const impl) : impl_(impl) { } Node(const Node& rhs) : impl_(rhs.impl_) { } virtual ~Node() { } @@ -70,25 +68,25 @@ class Node : public Node_base return *this; } // operator= - const string_type& getNodeName() const { return impl_->getNodeName(); } + const stringT& getNodeName() const { return impl_->getNodeName(); } - const string_type& getNodeValue() const { return impl_->getNodeValue(); } - void setNodeValue(const string_type& nodeValue) { impl_->setNodeValue(nodeValue); } + const stringT& getNodeValue() const { return impl_->getNodeValue(); } + void setNodeValue(const stringT& nodeValue) { impl_->setNodeValue(nodeValue); } Type getNodeType() const { return impl_->getNodeType(); } Node getParentNode() const { return impl_->getParentNode(); } - const NodeList getChildNodes() const { return NodeList(impl_->getChildNodes()); } + const NodeList getChildNodes() const { return NodeList(impl_->getChildNodes()); } Node getFirstChild() const { return impl_->getFirstChild(); } Node getLastChild() const { return impl_->getLastChild(); } Node getPreviousSibling() const { return impl_->getPreviousSibling(); } Node getNextSibling() const { return impl_->getNextSibling(); } - const NamedNodeMap getAttributes() const { return NamedNodeMap(impl_->getAttributes()); } + const NamedNodeMap getAttributes() const { return NamedNodeMap(impl_->getAttributes()); } - Document getOwnerDocument() const { return impl_->getOwnerDocument(); } + Document getOwnerDocument() const { return impl_->getOwnerDocument(); } Node insertBefore(const Node& newChild, const Node& refChild) { return impl_->insertBefore(*newChild.impl_, *refChild.impl_); } Node replaceChild(const Node& newChild, const Node& oldChild) { return impl_->replaceChild(*newChild.impl_, *oldChild.impl_); } @@ -96,7 +94,7 @@ class Node : public Node_base Node appendChild(const Node& newChild) { return impl_->appendChild(*newChild.impl_); } void purgeChild(Node& oldChild) { - Node_impl* child = *oldChild.impl_; + Node_impl* child = *oldChild.impl_; oldChild = 0; try { @@ -115,15 +113,15 @@ class Node : public Node_base void normalize() { impl_->normalize(); } - bool isSupported(const string_type& feature, const string_type& version) const { return impl_->isSupported(feature, version); } + bool isSupported(const stringT& feature, const stringT& version) const { return impl_->isSupported(feature, version); } - const string_type& getNamespaceURI() const { return impl_->getNamespaceURI(); } - const string_type& getPrefix() const { return impl_->getPrefix(); } - void setPrefix(const string_type& prefix) const { impl_->setPrefix(prefix); } - const string_type& getLocalName() const { return impl_->getLocalName(); } + const stringT& getNamespaceURI() const { return impl_->getNamespaceURI(); } + const stringT& getPrefix() const { return impl_->getPrefix(); } + void setPrefix(const stringT& prefix) const { impl_->setPrefix(prefix); } + const stringT& getLocalName() const { return impl_->getLocalName(); } // additional three methods - since C++ std::string (and by implication - // string_type) don't differenciate between a null string and an empty string, + // stringT) don't differenciate between a null string and an empty string, // but the DOM recommendation does, I have to introduce these three methods // to disambiguate. If they return false, the corresponding attribute should be // considered null. If they return true, the attribute has been set EVEN IF @@ -134,25 +132,25 @@ class Node : public Node_base bool hasAttributes() const { return impl_->hasAttributes(); } // you almost certainly don't need to use this function - Node_impl* unlying_impl() const { return *impl_; } + Node_impl* unlying_impl() const { return *impl_; } protected: - Proxy > impl_; + Proxy > impl_; - typedef class Document DocumentT; - friend class Document; - typedef class Events::EventTarget EventTargetT; - friend class Events::EventTarget; + typedef class Document DocumentT; + friend class Document; + typedef class Events::EventTarget EventTargetT; + friend class Events::EventTarget; }; // class Node //////////////////////////////////////////////////////////////////// // derive from this class to implement your own // DOM provider -template class Document_impl; -template class NodeList_impl; -template class NamedNodeMap_impl; +template class Document_impl; +template class NodeList_impl; +template class NamedNodeMap_impl; -template +template class Node_impl { public: @@ -165,48 +163,48 @@ class Node_impl /////////////////////////////////////////////////////// // Node methods - virtual const string_type& getNodeName() const = 0; + virtual const stringT& getNodeName() const = 0; - virtual const string_type& getNodeValue() const = 0; - virtual void setNodeValue(const string_type& nodeValue) = 0; + virtual const stringT& getNodeValue() const = 0; + virtual void setNodeValue(const stringT& nodeValue) = 0; virtual Node_base::Type getNodeType() const = 0; - virtual Node_impl* getParentNode() const = 0; + virtual Node_impl* getParentNode() const = 0; - virtual NodeList_impl* getChildNodes() const = 0; + virtual NodeList_impl* getChildNodes() const = 0; - virtual Node_impl* getFirstChild() const = 0; - virtual Node_impl* getLastChild() const = 0; + virtual Node_impl* getFirstChild() const = 0; + virtual Node_impl* getLastChild() const = 0; - virtual Node_impl* getPreviousSibling() const = 0; - virtual Node_impl* getNextSibling() const = 0; + virtual Node_impl* getPreviousSibling() const = 0; + virtual Node_impl* getNextSibling() const = 0; - virtual NamedNodeMap_impl* getAttributes() const = 0; + virtual NamedNodeMap_impl* getAttributes() const = 0; - virtual Document_impl* getOwnerDocument() const = 0; + virtual Document_impl* getOwnerDocument() const = 0; - virtual Node_impl* insertBefore(Node_impl* newChild, Node_impl* refChild) = 0; - virtual Node_impl* replaceChild(Node_impl* newChild, Node_impl* oldChild) = 0; - virtual Node_impl* removeChild(Node_impl* oldChild) = 0; - virtual Node_impl* appendChild(Node_impl* newChild) = 0; - virtual void purgeChild(Node_impl* oldChild) = 0; + virtual Node_impl* insertBefore(Node_impl* newChild, Node_impl* refChild) = 0; + virtual Node_impl* replaceChild(Node_impl* newChild, Node_impl* oldChild) = 0; + virtual Node_impl* removeChild(Node_impl* oldChild) = 0; + virtual Node_impl* appendChild(Node_impl* newChild) = 0; + virtual void purgeChild(Node_impl* oldChild) = 0; virtual bool hasChildNodes() const = 0; - virtual Node_impl* cloneNode(bool deep) const = 0; + virtual Node_impl* cloneNode(bool deep) const = 0; virtual void normalize() = 0; - virtual bool isSupported(const string_type& feature, const string_type& version) const = 0; + virtual bool isSupported(const stringT& feature, const stringT& version) const = 0; - virtual const string_type& getNamespaceURI() const = 0; - virtual const string_type& getPrefix() const = 0; - virtual void setPrefix(const string_type& prefix) = 0; - virtual const string_type& getLocalName() const = 0; + virtual const stringT& getNamespaceURI() const = 0; + virtual const stringT& getPrefix() const = 0; + virtual void setPrefix(const stringT& prefix) = 0; + virtual const stringT& getLocalName() const = 0; // additional methods - since C++ std::string (and by implication - // string_type) don't differenciate between a null string and an empty string, + // stringT) don't differenciate between a null string and an empty string, // but the DOM recommendation does, I have to introduce these three methods // to disambiguate. If they return false, the corresponding attribute should be // considered null. If they return true, the attribute has been set EVEN IF diff --git a/include/DOM/NodeList.hpp b/include/DOM/NodeList.hpp index 43caefb6..6b8661cf 100644 --- a/include/DOM/NodeList.hpp +++ b/include/DOM/NodeList.hpp @@ -14,15 +14,15 @@ namespace Arabica namespace DOM { -template class Node; -template class NodeList_impl; +template class Node; +template class NodeList_impl; -template +template class NodeList { public: NodeList() : impl_(0) { } - explicit NodeList(NodeList_impl* const impl) : impl_(impl) { } + explicit NodeList(NodeList_impl* const impl) : impl_(impl) { } NodeList(const NodeList& rhs) : impl_(rhs.impl_) { } virtual ~NodeList() { } @@ -37,16 +37,16 @@ class NodeList return *this; } // operator= - Node item(unsigned int index) const { return impl_->item(index); } + Node item(unsigned int index) const { return impl_->item(index); } unsigned int getLength() const { return impl_->getLength(); } private: - Proxy > impl_; + Proxy > impl_; }; // class NodeList ///////////////////////////////////////////////////////// -template +template class NodeList_impl { public: @@ -59,7 +59,7 @@ class NodeList_impl /////////////////////////////////////////////////////// // NodeList methods - virtual Node_impl* item(unsigned int index) const = 0; + virtual Node_impl* item(unsigned int index) const = 0; virtual unsigned int getLength() const = 0; }; // class NodeList_impl diff --git a/include/DOM/Notation.hpp b/include/DOM/Notation.hpp index 3e7d9127..21b9c704 100644 --- a/include/DOM/Notation.hpp +++ b/include/DOM/Notation.hpp @@ -15,19 +15,19 @@ namespace Arabica namespace DOM { -template class Notation_impl; +template class Notation_impl; -template -class Notation : public Node +template +class Notation : public Node { - typedef Node NodeT; + typedef Node NodeT; public: - Notation() : Node() { } - explicit Notation(Notation_impl* impl) : Node(dynamic_cast*>(impl)) { } - Notation(const Notation& rhs) : Node(rhs) { } - explicit Notation(const Node& rhs) : Node(rhs) + Notation() : Node() { } + explicit Notation(Notation_impl* impl) : Node(dynamic_cast*>(impl)) { } + Notation(const Notation& rhs) : Node(rhs) { } + explicit Notation(const Node& rhs) : Node(rhs) { - if(rhs.getNodeType() != Node::NOTATION_NODE) + if(rhs.getNodeType() != Node::NOTATION_NODE) throw std::bad_cast(); } @@ -36,14 +36,14 @@ class Notation : public Node stringT getSystemId() const { nImpl()->getSystemId(); } private: - Notation_impl* nImpl() { return dynamic_cast*>(NodeT::impl()); } + Notation_impl* nImpl() { return dynamic_cast*>(NodeT::impl()); } }; // class Notation ////////////////////////////////////////////////////////// -template class NamedNodeMap_impl; +template class NamedNodeMap_impl; -template -class Notation_impl : virtual public Node_impl +template +class Notation_impl : virtual public Node_impl { public: virtual ~Notation_impl () { } diff --git a/include/DOM/ProcessingInstruction.hpp b/include/DOM/ProcessingInstruction.hpp index 9393ebe6..d4423192 100644 --- a/include/DOM/ProcessingInstruction.hpp +++ b/include/DOM/ProcessingInstruction.hpp @@ -14,19 +14,19 @@ namespace Arabica namespace DOM { -template class ProcessingInstruction_impl; +template class ProcessingInstruction_impl; -template -class ProcessingInstruction : public Node +template +class ProcessingInstruction : public Node { - typedef Node NodeT; + typedef Node NodeT; public: - ProcessingInstruction() : Node(0) { } - explicit ProcessingInstruction(ProcessingInstruction_impl* impl) : Node(dynamic_cast*>(impl)) { } - ProcessingInstruction(const ProcessingInstruction& rhs) : Node(rhs) { } - explicit ProcessingInstruction(const Node& rhs) : Node(rhs) + ProcessingInstruction() : Node(0) { } + explicit ProcessingInstruction(ProcessingInstruction_impl* impl) : Node(dynamic_cast*>(impl)) { } + ProcessingInstruction(const ProcessingInstruction& rhs) : Node(rhs) { } + explicit ProcessingInstruction(const Node& rhs) : Node(rhs) { - if(rhs.getNodeType() != Node::PROCESSING_INSTRUCTION_NODE) + if(rhs.getNodeType() != Node::PROCESSING_INSTRUCTION_NODE) throw std::bad_cast(); } @@ -36,13 +36,13 @@ class ProcessingInstruction : public Node void setData(const stringT& data) { piImpl()->setData(data); } private: - ProcessingInstruction_impl* piImpl() const { return dynamic_cast*>(*NodeT::impl_); } + ProcessingInstruction_impl* piImpl() const { return dynamic_cast*>(*NodeT::impl_); } }; // class DocumentFragment ////////////////////////////////////////////////////////// -template -class ProcessingInstruction_impl : virtual public Node_impl +template +class ProcessingInstruction_impl : virtual public Node_impl { public: virtual ~ProcessingInstruction_impl () { } diff --git a/include/DOM/Simple/AttrImpl.hpp b/include/DOM/Simple/AttrImpl.hpp index 3d40d91d..39119e5e 100644 --- a/include/DOM/Simple/AttrImpl.hpp +++ b/include/DOM/Simple/AttrImpl.hpp @@ -14,13 +14,17 @@ namespace SimpleDOM template class ElementImpl; template -class AttrImpl : public DOM::Attr_impl, +class AttrImpl : public DOM::Attr_impl, public NodeImplWithChildren { - typedef NodeImplWithChildren NodeT; public: + typedef NodeImplWithChildren NodeT; + typedef ElementImpl ElementImpl; + typedef DOM::Attr_impl DOMAttr_implT; + typedef DOM::Node_impl DOMNode_implT; + AttrImpl(DocumentImpl* ownerDoc, const stringT& name) : - DOM::Attr_impl(), + DOMAttr_implT(), NodeImplWithChildren(ownerDoc), name_(ownerDoc->stringPool(name)), ownerElement_(0), @@ -30,7 +34,7 @@ class AttrImpl : public DOM::Attr_impl, } // AttrImpl AttrImpl(DocumentImpl* ownerDoc, const stringT& name, const stringT& value) : - DOM::Attr_impl(), + DOMAttr_implT(), NodeImplWithChildren(ownerDoc), name_(ownerDoc->stringPool(name)), ownerElement_(0), @@ -61,16 +65,16 @@ class AttrImpl : public DOM::Attr_impl, ///////////////////////////////////////////////////// // DOM::Node methods - virtual typename DOM::Node::Type getNodeType() const + virtual typename DOM::Node_base::Type getNodeType() const { - return DOM::Node::ATTRIBUTE_NODE; + return DOM::Node_base::ATTRIBUTE_NODE; } // getNodeType - virtual DOM::Node_impl* getParentNode() const { return 0; } - virtual DOM::Node_impl* getPreviousSibling() const { return 0; } - virtual DOM::Node_impl* getNextSibling() const { return 0; } + virtual DOMNode_implT* getParentNode() const { return 0; } + virtual DOMNode_implT* getPreviousSibling() const { return 0; } + virtual DOMNode_implT* getNextSibling() const { return 0; } - virtual DOM::Node_impl* cloneNode(bool deep) const + virtual DOMNode_implT* cloneNode(bool deep) const { AttrImpl* a = dynamic_cast(NodeT::ownerDoc_->createAttribute(*name_)); cloneChildren(a); @@ -88,7 +92,7 @@ class AttrImpl : public DOM::Attr_impl, if(!valueCalculated_) { value_ = string_adaptorT::construct_from_utf8(""); - for(DOM::Node_impl* c = NodeT::getFirstChild(); c != 0; c = c->getNextSibling()) + for(DOMNode_implT* c = NodeT::getFirstChild(); c != 0; c = c->getNextSibling()) string_adaptorT::append(value_, c->getNodeValue()); valueCalculated_ = true; } @@ -100,7 +104,7 @@ class AttrImpl : public DOM::Attr_impl, NodeT::throwIfReadOnly(); // remove all children - for(DOM::Node_impl* c = NodeT::getFirstChild(); c != 0; c = NodeT::getFirstChild()) + for(DOMNode_implT* c = NodeT::getFirstChild(); c != 0; c = NodeT::getFirstChild()) NodeT::removeChild(c); // add a new text node @@ -112,7 +116,7 @@ class AttrImpl : public DOM::Attr_impl, ///////////////////////////////////////////////////////////// // this implementation - void setOwnerElement(ElementImpl* element) + void setOwnerElement(ElementImplT* element) { ownerElement_ = element; if(NodeT::ownerDoc_) @@ -132,22 +136,22 @@ class AttrImpl : public DOM::Attr_impl, protected: void cloneChildren(AttrImpl* clone) const { - for(DOM::Node_impl* c = NodeT::getFirstChild(); c != 0; c = c->getNextSibling()) + for(DOMNode_implT* c = NodeT::getFirstChild(); c != 0; c = c->getNextSibling()) clone->appendChild(c->cloneNode(true)); } // cloneChildren private: - virtual void checkChildType(DOM::Node_impl* child) + virtual void checkChildType(DOMNode_implT* child) { - typename DOM::Node::Type type = child->getNodeType(); - if((type != DOM::Node::TEXT_NODE) && - (type != DOM::Node::ENTITY_REFERENCE_NODE)) + typename DOM::Node_base::Type type = child->getNodeType(); + if((type != DOM::Node_base::TEXT_NODE) && + (type != DOM::Node_base::ENTITY_REFERENCE_NODE)) throw DOM::DOMException(DOM::DOMException::HIERARCHY_REQUEST_ERR); } // checkChildType protected: stringT const* name_; - ElementImpl* ownerElement_; + ElementImplT* ownerElement_; bool specified_; mutable bool valueCalculated_; mutable stringT value_; diff --git a/include/DOM/Simple/AttrMap.hpp b/include/DOM/Simple/AttrMap.hpp index 836bddca..b756fd42 100644 --- a/include/DOM/Simple/AttrMap.hpp +++ b/include/DOM/Simple/AttrMap.hpp @@ -13,10 +13,17 @@ namespace SimpleDOM template class AttrMap : public NamedNodeMapImpl { - typedef NamedNodeMapImpl MapT; public: - AttrMap(DocumentImpl* ownerDoc) : - NamedNodeMapImpl(ownerDoc), + typedef NamedNodeMapImpl MapT; + typedef AttrImpl AttrImplT; + typedef AttrNSImpl AttrNSImplT; + typedef ElementImpl ElementImplT; + typedef DocumentImpl DocumentImplT; + typedef DOM::Node_impl DOMNode_implT; + typedef DOM::Attr_impl DOMAttr_implT; + typedef DOM::NamedNodeMap_impl DOMNamedNodeMap_implT; + AttrMap(DocumentImplT* ownerDoc) : + NamedNodeMapImplT(ownerDoc), ownerElement_(0) { } // AttrMap @@ -28,13 +35,13 @@ class AttrMap : public NamedNodeMapImpl ///////////////////////////////////////////////////// const stringT& getAttribute(const stringT& name) const { - DOM::Node_impl* attr = MapT::getNamedItem(name); + DOMNode_implT* attr = MapT::getNamedItem(name); return attr ? attr->getNodeValue() : MapT::ownerDoc_->empty_string(); } // getAttribute void setAttribute(const stringT& name, const stringT& value) { - AttrImpl* a = new AttrImpl(MapT::ownerDoc_, name, value); + AttrImplT* a = new AttrImplT(MapT::ownerDoc_, name, value); a->setOwnerElement(ownerElement_); MapT::setNamedItem(a); } // setAttribute @@ -45,18 +52,18 @@ class AttrMap : public NamedNodeMapImpl createDefault(name); } // removeAttribute - DOM::Attr_impl* getAttributeNode(const stringT& name) const + DOMAttr_implT* getAttributeNode(const stringT& name) const { - return dynamic_cast*>(MapT::getNamedItem(name)); + return dynamic_cast(MapT::getNamedItem(name)); } // getAttributeNode - DOM::Attr_impl* setAttributeNode(DOM::Attr_impl* newAttr) + DOMAttr_implT* setAttributeNode(DOMAttr_implT* newAttr) { - dynamic_cast*>(newAttr)->setOwnerElement(ownerElement_); - return dynamic_cast*>(MapT::setNamedItem(newAttr)); + dynamic_cast(newAttr)->setOwnerElement(ownerElement_); + return dynamic_cast(MapT::setNamedItem(newAttr)); } // setAttributeNode - DOM::Attr_impl* removeAttributeNode(DOM::Attr_impl* oldAttr) + DOMAttr_implT* removeAttributeNode(DOMAttr_implT* oldAttr) { if(MapT::removeNamedItem(oldAttr->getNodeName()) == 0) throw DOM::DOMException(DOM::DOMException::NOT_FOUND_ERR); @@ -66,17 +73,16 @@ class AttrMap : public NamedNodeMapImpl stringT getAttributeNS(const stringT& namespaceURI, const stringT& localName) const { - DOM::Node_impl* attr = MapT::getNamedItemNS(namespaceURI, localName); + DOMNode_implT* attr = MapT::getNamedItemNS(namespaceURI, localName); return attr ? attr->getNodeValue() : stringT(); } // getAttributeNS void setAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName, const stringT& value) { - AttrNSImpl* a = - new AttrNSImpl(MapT::ownerDoc_, - namespaceURI, - !string_adaptorT::empty(namespaceURI), - qualifiedName); + AttrNSImplT* a = new AttrNSImplT(MapT::ownerDoc_, + namespaceURI, + !string_adaptorT::empty(namespaceURI), + qualifiedName); a->setValue(value); a->setOwnerElement(ownerElement_); MapT::setNamedItemNS(a); @@ -88,15 +94,15 @@ class AttrMap : public NamedNodeMapImpl createDefault(namespaceURI, localName); } // removeAttributeNS - DOM::Attr_impl* getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const + DOMAttr_implT* getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const { - return dynamic_cast*>(MapT::getNamedItemNS(namespaceURI, localName)); + return dynamic_cast(MapT::getNamedItemNS(namespaceURI, localName)); } // getAttributeNodeNS - DOM::Attr_impl* setAttributeNodeNS(DOM::Attr_impl* newAttr) + DOMAttr_implT* setAttributeNodeNS(DOMAttr_implT* newAttr) { - dynamic_cast*>(newAttr)->setOwnerElement(ownerElement_); - return dynamic_cast*>(MapT::setNamedItemNS(newAttr)); + dynamic_cast(newAttr)->setOwnerElement(ownerElement_); + return dynamic_cast(MapT::setNamedItemNS(newAttr)); } // setAttributeNodeNS bool hasAttribute(const stringT& name) const @@ -109,71 +115,71 @@ class AttrMap : public NamedNodeMapImpl return (MapT::getNamedItemNS(namespaceURI, localName) != 0); } // hasAttributeNS - void setOwnerElement(ElementImpl* element) + void setOwnerElement(ElementImplT* element) { ownerElement_ = element; getDefaults(); } // setOwnerElement - virtual void setOwnerDoc(DocumentImpl* ownerDoc) + virtual void setOwnerDoc(DocumentImplT* ownerDoc) { - NamedNodeMapImpl::setOwnerDoc(ownerDoc); + NamedNodeMapImplT::setOwnerDoc(ownerDoc); getDefaults(); } // setOwnerDoc private: void createDefault(const stringT& name) { - DOM::NamedNodeMap_impl* attrs = getDefaultAttrs(); + DOMNamedNodeMap_implT* attrs = getDefaultAttrs(); if(attrs) { - DOM::Node_impl* attr = attrs->getNamedItem(name); + DOMNode_implT* attr = attrs->getNamedItem(name); if(attr) - setAttributeNode(dynamic_cast*>(attr->cloneNode(true))); + setAttributeNode(dynamic_cast(attr->cloneNode(true))); } } // createDefault void createDefault(const stringT& namespaceURI, const stringT& localName) { - DOM::NamedNodeMap_impl* attrs = getDefaultAttrs(); + DOMNamedNodeMap_implT* attrs = getDefaultAttrs(); if(attrs) { - DOM::Node_impl* attr = attrs->getNamedItemNS(namespaceURI, localName); + DOMNode_implT* attr = attrs->getNamedItemNS(namespaceURI, localName); if(attr) - setAttributeNodeNS(dynamic_cast*>(attr->cloneNode(true))); + setAttributeNodeNS(dynamic_cast(attr->cloneNode(true))); } } // createDefault void getDefaults() { - DOM::NamedNodeMap_impl* attrs = getDefaultAttrs(); + DOMNamedNodeMap_implT* attrs = getDefaultAttrs(); if(attrs) { for(unsigned int i = 0; i < attrs->getLength(); ++i) { - DOM::Node_impl* attr = attrs->item(i); + DOMNode_implT* attr = attrs->item(i); if(getAttributeNodeNS(attr->getNamespaceURI(), attr->getNodeName()) == 0) - setAttributeNodeNS(dynamic_cast*>(attr->cloneNode(true))); + setAttributeNodeNS(dynamic_cast(attr->cloneNode(true))); } } } // getDefaults - DOM::NamedNodeMap_impl* getDefaultAttrs() + DOMNamedNodeMap_implT* getDefaultAttrs() { if(!MapT::ownerDoc_) return 0; - DocumentTypeImpl* docType = dynamic_cast*>(MapT::ownerDoc_->getDoctype()); + DocumentTypeImplT* docType = dynamic_cast(MapT::ownerDoc_->getDoctype()); if(docType) { - DOM::Node_impl* exemplar = docType->getElements()->getNamedItem(ownerElement_->getNodeName()); + DOMNode_implT* exemplar = docType->getElements()->getNamedItem(ownerElement_->getNodeName()); if(exemplar) return exemplar->getAttributes(); } return 0; } // getDefaultAttrs - ElementImpl* ownerElement_; + ElementImplT* ownerElement_; }; // class AttrMap diff --git a/include/DOM/Simple/AttrNSImpl.hpp b/include/DOM/Simple/AttrNSImpl.hpp index 898202da..d2def488 100644 --- a/include/DOM/Simple/AttrNSImpl.hpp +++ b/include/DOM/Simple/AttrNSImpl.hpp @@ -12,15 +12,16 @@ namespace SimpleDOM template class AttrNSImpl : public AttrImpl { - typedef typename string_adaptorT::size_type size_type; - typedef AttrImpl AttrT; - public: + typedef typename string_adaptorT::size_type size_type; + typedef AttrImpl AttrImplT; + typedef DOM::Node_impl DOMNode_implT + AttrNSImpl(DocumentImpl* ownerDoc, const stringT& namespaceURI, bool hasNamespaceURI, const stringT& qualifiedName) : - AttrImpl(ownerDoc, qualifiedName), + AttrImplT(ownerDoc, qualifiedName), prefix_(&ownerDoc->empty_string()), hasNamespaceURI_(false) { @@ -30,7 +31,7 @@ class AttrNSImpl : public AttrImpl if(index == string_adaptorT::npos()) { //qualifiedName contains no ':' - localName_ = AttrT::ownerDoc_->stringPool(qualifiedName); + localName_ = AttrImplT::ownerDoc_->stringPool(qualifiedName); if(*localName_ == string_adaptorT::construct_from_utf8("xmlns")) { hasPrefix = true; @@ -40,27 +41,27 @@ class AttrNSImpl : public AttrImpl else { hasPrefix = true; - prefix_ = AttrT::ownerDoc_->stringPool(string_adaptorT::substr(qualifiedName, 0, index)); - localName_ = AttrT::ownerDoc_->stringPool(string_adaptorT::substr(qualifiedName, index+1)); + prefix_ = AttrImplT::ownerDoc_->stringPool(string_adaptorT::substr(qualifiedName, 0, index)); + localName_ = AttrImplT::ownerDoc_->stringPool(string_adaptorT::substr(qualifiedName, index+1)); prefix_for_checking = prefix_; } // if(index == string_adaptorT::npos) std::pair mappedURI = - checkPrefixAndNamespace(hasPrefix, *prefix_for_checking, hasNamespaceURI, namespaceURI, DOM::Node::ATTRIBUTE_NODE); + checkPrefixAndNamespace(hasPrefix, *prefix_for_checking, hasNamespaceURI, namespaceURI, DOM::Node_base::ATTRIBUTE_NODE); hasNamespaceURI_ = mappedURI.first; - namespaceURI_ = AttrT::ownerDoc_->stringPool(mappedURI.second); + namespaceURI_ = AttrImplT::ownerDoc_->stringPool(mappedURI.second); } // AttrImpl virtual ~AttrNSImpl() { } /////////////////////////////////////////////////////// // DOM::Node methods - virtual DOM::Node_impl* cloneNode(bool deep) const + virtual DOMNode_impl* cloneNode(bool deep) const { - AttrNSImpl* clone = dynamic_cast(AttrT::ownerDoc_->createAttributeNS(*namespaceURI_, *AttrT::name_)); - AttrT::cloneChildren(clone); - clone->setSpecified(AttrT::getSpecified()); + AttrNSImpl* clone = dynamic_cast(AttrImplT::ownerDoc_->createAttributeNS(*namespaceURI_, *AttrImplT::name_)); + AttrImplT::cloneChildren(clone); + clone->setSpecified(AttrImplT::getSpecified()); return clone; } // cloneNode @@ -81,19 +82,19 @@ class AttrNSImpl : public AttrImpl if(string_adaptorT::empty(prefix)) { - AttrT::name_ = localName_; - prefix_ = &AttrT::ownerDoc_->empty_string(); + AttrImplT::name_ = localName_; + prefix_ = &AttrImplT::ownerDoc_->empty_string(); return; } // empty prefix - checkPrefixAndNamespace(true, prefix, true, *namespaceURI_, DOM::Node::ATTRIBUTE_NODE); + checkPrefixAndNamespace(true, prefix, true, *namespaceURI_, DOM::Node_base::ATTRIBUTE_NODE); stringT newName = prefix; string_adaptorT::append(newName, string_adaptorT::construct_from_utf8(":")); string_adaptorT::append(newName, *localName_); - prefix_ = AttrT::ownerDoc_->stringPool(prefix); - AttrT::name_ = AttrT::ownerDoc_->stringPool(newName); + prefix_ = AttrImplT::ownerDoc_->stringPool(prefix); + AttrImplT::name_ = AttrImplT::ownerDoc_->stringPool(newName); } // setPrefix virtual const stringT& getLocalName() const @@ -114,7 +115,7 @@ class AttrNSImpl : public AttrImpl virtual bool hasPrefix() const { - return !(*prefix_ == AttrT::ownerDoc_->empty_string()); + return !(*prefix_ == AttrImplT::ownerDoc_->empty_string()); } // hasPrefix private: diff --git a/include/DOM/Simple/CDATASectionImpl.hpp b/include/DOM/Simple/CDATASectionImpl.hpp index 2d468533..f40ffe17 100644 --- a/include/DOM/Simple/CDATASectionImpl.hpp +++ b/include/DOM/Simple/CDATASectionImpl.hpp @@ -9,13 +9,16 @@ namespace SimpleDOM { template -class CDATASectionImpl : public DOM::CDATASection_impl, +class CDATASectionImpl : public DOM::CDATASection_impl, public CharacterDataImpl { - typedef CharacterDataImpl CharDataT; public: + typedef CharacterDataImpl CharacterDataImplT; + typedef DOM::Text_impl DOMText_implT; + typedef DOM::Node_impl DOMNode_implT; + CDATASectionImpl(DocumentImpl* ownerDoc, const stringT& data) : - CharacterDataImpl(ownerDoc, data) + CharacterDataImplT(ownerDoc, data) { } // CDATASectionImpl @@ -24,15 +27,15 @@ class CDATASectionImpl : public DOM::CDATASection_impl, ////////////////////////////////////////////////////////////////// // DOM::CDATASection methods // on a compiler which implemented covariant return types this would return DOM::CDATASection - virtual DOM::Text_impl* splitText(int offset) + virtual DOMText_implT* splitText(int offset) { - CharDataT::throwIfReadOnly(); + CharacterDataImplT::throwIfReadOnly(); - stringT second = CharDataT::substringData(offset, CharDataT::getLength() - offset); - CharDataT::deleteData(offset, CharDataT::getLength() - offset); + stringT second = CharacterDataImplT::substringData(offset, CharacterDataImplT::getLength() - offset); + CharacterDataImplT::deleteData(offset, CharacterDataImplT::getLength() - offset); - CDATASectionImpl* splitNode = new CDATASectionImpl(CharDataT::getOwnerDoc(), second); - CharDataT::getParentNode()->insertBefore(splitNode, CharDataT::getNextSibling()); + CDATASectionImpl* splitNode = new CDATASectionImpl(CharacterDataImplT::getOwnerDoc(), second); + CharacterDataImplT::getParentNode()->insertBefore(splitNode, CharacterDataImplT::getNextSibling()); return splitNode; } // splitText @@ -43,9 +46,9 @@ class CDATASectionImpl : public DOM::CDATASection_impl, return DOM::Node_base::CDATA_SECTION_NODE; } // getNodeType - virtual DOM::Node_impl* cloneNode(bool deep) const + virtual DOMNode_implT* cloneNode(bool deep) const { - return CharDataT::ownerDoc_->createCDATASection(CharDataT::getData()); + return CharacterDataImplT::ownerDoc_->createCDATASection(CharacterDataImplT::getData()); } // cloneNode virtual const stringT& getNodeName() const diff --git a/include/DOM/Simple/ElementByTagImpl.hpp b/include/DOM/Simple/ElementByTagImpl.hpp index 4a7c3d53..d01827c4 100644 --- a/include/DOM/Simple/ElementByTagImpl.hpp +++ b/include/DOM/Simple/ElementByTagImpl.hpp @@ -13,13 +13,13 @@ template class DocumentImpl; template -class ElementByTagList : public DOM::NodeList_impl +class ElementByTagList : public DOM::NodeList_impl { public: ElementByTagList(DocumentImpl* ownerDoc, - DOM::Node_impl* rootNode, + DOM::Node_impl* rootNode, const stringT& tagName) : - DOM::NodeList_impl(), + DOM::NodeList_impl(), rootNode_(rootNode), ownerDoc_(ownerDoc), tagName_(tagName), @@ -34,10 +34,10 @@ class ElementByTagList : public DOM::NodeList_impl } // ElementByTagList ElementByTagList(DocumentImpl* ownerDoc, - DOM::Node_impl* rootNode, + DOM::Node_impl* rootNode, const stringT& namespaceURI, const stringT& localName) : - DOM::NodeList_impl(), + DOM::NodeList_impl(), rootNode_(rootNode), ownerDoc_(ownerDoc), namespaceURI_(namespaceURI), @@ -72,7 +72,7 @@ class ElementByTagList : public DOM::NodeList_impl ///////////////////////////////////////////////// // DOM::NodeList methods - virtual DOM::Node_impl* item(unsigned int index) const + virtual DOM::Node_impl* item(unsigned int index) const { if(index >= nodes_.size()) return 0; @@ -102,29 +102,29 @@ class ElementByTagList : public DOM::NodeList_impl changes_ = ownerDoc_->changes(); } // populate - void checkNode(DOM::Node_impl* node) const + void checkNode(DOM::Node_impl* node) const { if(useNamespace_) { if((node->hasNamespaceURI() && namespaceURI_ == node->getNamespaceURI()) || allNamespaces_) { - if((tagName_ == node->getLocalName()) || (allNames_ && node->getNodeType() == DOM::Node::ELEMENT_NODE)) + if((tagName_ == node->getLocalName()) || (allNames_ && node->getNodeType() == DOM::Node::ELEMENT_NODE)) nodes_.push_back(node); } } else - if((tagName_ == node->getNodeName()) || (allNames_ && node->getNodeType() == DOM::Node::ELEMENT_NODE)) + if((tagName_ == node->getNodeName()) || (allNames_ && node->getNodeType() == DOM::Node::ELEMENT_NODE)) nodes_.push_back(node); - for(DOM::Node_impl* child = node->getFirstChild(); child != 0; child = child->getNextSibling()) - if(child->getNodeType() == DOM::Node::ELEMENT_NODE) + for(DOM::Node_impl* child = node->getFirstChild(); child != 0; child = child->getNextSibling()) + if(child->getNodeType() == DOM::Node::ELEMENT_NODE) checkNode(child); } // checkNode - typedef std::deque*> NodeListT; + typedef std::deque*> NodeListT; mutable NodeListT nodes_; - DOM::Node_impl* rootNode_; + DOM::Node_impl* rootNode_; DocumentImpl* ownerDoc_; stringT namespaceURI_; stringT tagName_; diff --git a/include/DOM/Simple/ElementImpl.hpp b/include/DOM/Simple/ElementImpl.hpp index 4583c968..4971e4a8 100644 --- a/include/DOM/Simple/ElementImpl.hpp +++ b/include/DOM/Simple/ElementImpl.hpp @@ -12,16 +12,24 @@ namespace SimpleDOM { template -class ElementImpl : public DOM::Element_impl, +class ElementImpl : public DOM::Element_impl, public NodeImplWithChildren { protected: typedef NodeImplWithChildren NodeT; + typedef DocumentImpl DocumentImplT; + typedef AttrMap AttrMapT; + typedef ElementByTagList ElementByTagListT; + typedef DOM::Node_impl DOMNode_implT; + typedef DOM::Attr_impl DOMAttr_implT; + typedef DOM::NodeList_impl DOMNodeList_implT; + typedef DOM::NamedNodeMap_impl DOMNamedNodeMap_implT; + typedef DOM::Element_impl DOMElement_implT; public: - ElementImpl(DocumentImpl* ownerDoc, const stringT& tagName) : - DOM::Element_impl(), - NodeImplWithChildren(ownerDoc), + ElementImpl(DocumentImplT* ownerDoc, const stringT& tagName) : + DOMElement_implT(), + NodeT(ownerDoc), attributes_(ownerDoc), tagName_(ownerDoc->stringPool(tagName)) { @@ -51,26 +59,26 @@ class ElementImpl : public DOM::Element_impl, attributes_.removeAttribute(name); } // removeAttribute - virtual DOM::Attr_impl* getAttributeNode(const stringT& name) const + virtual DOMAttr_implT* getAttributeNode(const stringT& name) const { return attributes_.getAttributeNode(name); } // getAttributeNode - virtual DOM::Attr_impl* setAttributeNode(DOM::Attr_impl* newAttr) + virtual DOMAttr_implT* setAttributeNode(DOMAttr_implT* newAttr) { return attributes_.setAttributeNode(newAttr); } // setAttributeNode - virtual DOM::Attr_impl* removeAttributeNode(DOM::Attr_impl* oldAttr) + virtual DOMAttr_implT* removeAttributeNode(DOMAttr_implT* oldAttr) { return attributes_.removeAttributeNode(oldAttr); } // removeAttributeNode - virtual DOM::NodeList_impl* getElementsByTagName(const stringT& tagName) const + virtual DOMNodeList_implT* getElementsByTagName(const stringT& tagName) const { - return new ElementByTagList(NodeT::ownerDoc_, - const_cast(this), - tagName); + return new ElementByTagListT(NodeT::ownerDoc_, + const_cast(this), + tagName); } // getElementsByTagName virtual stringT getAttributeNS(const stringT& namespaceURI, const stringT& localName) const @@ -88,21 +96,22 @@ class ElementImpl : public DOM::Element_impl, attributes_.removeAttributeNS(namespaceURI, localName); } // removeAttributeNS - virtual DOM::Attr_impl* getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const + virtual DOMAttr_implT* getAttributeNodeNS(const stringT& namespaceURI, const stringT& localName) const { return attributes_.getAttributeNodeNS(namespaceURI, localName); } // getAttributeNodeNS - virtual DOM::Attr_impl* setAttributeNodeNS(DOM::Attr_impl* newAttr) + virtual DOMAttr_implT* setAttributeNodeNS(DOMAttr_implT* newAttr) { return attributes_.setAttributeNodeNS(newAttr); } // setAttributeNodeNS - virtual DOM::NodeList_impl* getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const + virtual DOMNodeList_implT* getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const { - return new ElementByTagList(NodeT::ownerDoc_, - const_cast(this), - namespaceURI, localName); + return new ElementByTagListT(NodeT::ownerDoc_, + const_cast(this), + namespaceURI, + localName); } // getElementsByTagNameNS virtual bool hasAttribute(const stringT& name) const @@ -127,12 +136,12 @@ class ElementImpl : public DOM::Element_impl, return *tagName_; } // getNodeName - virtual DOM::NamedNodeMap_impl* getAttributes() const + virtual DOMNamedNodeMap_implT* getAttributes() const { - return const_cast*>(&attributes_); + return const_cast(&attributes_); } // getAttributes - virtual DOM::Node_impl* cloneNode(bool deep) const + virtual DOMNode_impl* cloneNode(bool deep) const { ElementImpl* clone = dynamic_cast(NodeT::ownerDoc_->createElement(*tagName_)); cloneChildren(clone, deep); @@ -144,16 +153,16 @@ class ElementImpl : public DOM::Element_impl, return (attributes_.getLength() > 0); } // hasAttributes - virtual void setOwnerDoc(DocumentImpl* ownerDoc) + virtual void setOwnerDoc(DocumentImplT* ownerDoc) { attributes_.setOwnerDoc(ownerDoc); - NodeImplWithChildren::setOwnerDoc(ownerDoc); + NodeT::setOwnerDoc(ownerDoc); } // setOwnerDoc virtual void setReadOnly(bool readOnly) { attributes_.setReadOnly(readOnly); - NodeImplWithChildren::setReadOnly(readOnly); + NodeT::setReadOnly(readOnly); } // setReadOnly protected: @@ -161,10 +170,10 @@ class ElementImpl : public DOM::Element_impl, { for(unsigned int i = 0; i < attributes_.getLength(); ++i) { - DOM::Attr_impl* a = dynamic_cast*>(attributes_.item(i)); + DOMAttr_implT* a = dynamic_cast(attributes_.item(i)); if(a->getSpecified()) { - DOM::Attr_impl* newA = dynamic_cast*>(a->cloneNode(true)); + DOMAttr_implT* newA = dynamic_cast(a->cloneNode(true)); if(string_adaptorT::empty(a->getLocalName())) clone->setAttributeNode(newA); else @@ -173,24 +182,24 @@ class ElementImpl : public DOM::Element_impl, } // for if(deep) - for(DOM::Node_impl* c = NodeT::getFirstChild(); c != 0; c = c->getNextSibling()) + for(DOMNode_implT* c = NodeT::getFirstChild(); c != 0; c = c->getNextSibling()) clone->appendChild(c->cloneNode(true)); } // cloneChildren private: - virtual void checkChildType(DOM::Node_impl* child) + virtual void checkChildType(DOMNode_impl* child) { - typename DOM::Node::Type type = child->getNodeType(); - if((type != DOM::Node::ELEMENT_NODE) && - (type != DOM::Node::TEXT_NODE) && - (type != DOM::Node::COMMENT_NODE) && - (type != DOM::Node::PROCESSING_INSTRUCTION_NODE) && - (type != DOM::Node::CDATA_SECTION_NODE) && - (type != DOM::Node::ENTITY_REFERENCE_NODE)) + typename DOM::Node_base::Type type = child->getNodeType(); + if((type != DOM::Node_base::ELEMENT_NODE) && + (type != DOM::Node_base::TEXT_NODE) && + (type != DOM::Node_base::COMMENT_NODE) && + (type != DOM::Node_base::PROCESSING_INSTRUCTION_NODE) && + (type != DOM::Node_base::CDATA_SECTION_NODE) && + (type != DOM::Node_base::ENTITY_REFERENCE_NODE)) throw DOM::DOMException(DOM::DOMException::HIERARCHY_REQUEST_ERR); } // checkChildType - AttrMap attributes_; + AttrMapT attributes_; protected: stringT const* tagName_; }; // class ElementImpl diff --git a/include/DOM/Simple/NamedNodeMapImpl.hpp b/include/DOM/Simple/NamedNodeMapImpl.hpp index 2e0bf13e..2df7f31a 100644 --- a/include/DOM/Simple/NamedNodeMapImpl.hpp +++ b/include/DOM/Simple/NamedNodeMapImpl.hpp @@ -58,12 +58,17 @@ class namespaceAndNameIs : public std::unary_function -class NamedNodeMapImpl : public DOM::NamedNodeMap_impl +class NamedNodeMapImpl : public DOM::NamedNodeMap_impl { public: - NamedNodeMapImpl(DocumentImpl* ownerDoc) : - DOM::NamedNodeMap_impl(), - nodes_(), + typedef DOM::Node_impl DOMNode_implT; + typedef NodeImpl NodeImplT; + typedef NamedNodeMapImpl NamedNodeMapImplT; + typedef DocumentImpl DocumentImplT; + + NamedNodeMapImpl(DocumentImplT* ownerDoc) : + DOM::NamedNodeMap_impl(), + nodes_(), readOnly_(false), ownerDoc_(ownerDoc) { @@ -87,7 +92,7 @@ class NamedNodeMapImpl : public DOM::NamedNodeMap_impl if(ownerDoc_) ownerDoc_->releaseRef(); } // releaseRef - virtual void setOwnerDoc(DocumentImpl* ownerDoc) + virtual void setOwnerDoc(DocumentImplT* ownerDoc) { ownerDoc_ = ownerDoc; for(typename NodeListT::iterator i = nodes_.begin(); i != nodes_.end(); ++i) @@ -96,24 +101,24 @@ class NamedNodeMapImpl : public DOM::NamedNodeMap_impl /////////////////////////////////////////////////// // DOM::NamedNodeMap methods - virtual DOM::Node_impl* getNamedItem(const stringT& name) const + virtual DOMNode_implT* getNamedItem(const stringT& name) const { - return getNode(const_cast*>(this)->findByName(name)); + return getNode(const_cast(this)->findByName(name)); } // getNamedItem - virtual DOM::Node_impl* setNamedItem(DOM::Node_impl* arg) + virtual DOMNode_implT* setNamedItem(DOMNode_implT* arg) { throwIfReadOnly(); - return setNode(findByName(arg->getNodeName()), dynamic_cast*>(arg)); + return setNode(findByName(arg->getNodeName()), dynamic_cast(arg)); } // setNamedItem - virtual DOM::Node_impl* removeNamedItem(const stringT& name) + virtual DOMNode_implT* removeNamedItem(const stringT& name) { throwIfReadOnly(); return removeNode(findByName(name)); } // removedNamedItem - virtual DOM::Node_impl* item(unsigned int index) const + virtual DOMNode_implT* item(unsigned int index) const { return do_item(index); } // item @@ -123,18 +128,18 @@ class NamedNodeMapImpl : public DOM::NamedNodeMap_impl return static_cast(nodes_.size()); } // getLength - virtual DOM::Node_impl* getNamedItemNS(const stringT& namespaceURI, const stringT& localName) const + virtual DOMNode_implT* getNamedItemNS(const stringT& namespaceURI, const stringT& localName) const { - return getNode(const_cast*>(this)->findByNamespaceAndName(namespaceURI, localName)); + return getNode(const_cast(this)->findByNamespaceAndName(namespaceURI, localName)); } // getNamedItemNS - virtual DOM::Node_impl* setNamedItemNS(DOM::Node_impl* arg) + virtual DOMNode_implT* setNamedItemNS(DOMNode_implT* arg) { throwIfReadOnly(); - return setNode(findByNamespaceAndName(arg->getNamespaceURI(), arg->getLocalName()), dynamic_cast*>(arg)); + return setNode(findByNamespaceAndName(arg->getNamespaceURI(), arg->getLocalName()), dynamic_cast(arg)); } // setNamedItemNS - virtual DOM::Node_impl* removeNamedItemNS(const stringT& namespaceURI, const stringT& localName) + virtual DOMNode_implT* removeNamedItemNS(const stringT& namespaceURI, const stringT& localName) { throwIfReadOnly(); return removeNode(findByNamespaceAndName(namespaceURI, localName)); @@ -147,7 +152,7 @@ class NamedNodeMapImpl : public DOM::NamedNodeMap_impl readOnly_ = readOnly; } // setReadOnly - NodeImpl* do_item(unsigned int index) const + NodeImplT* do_item(unsigned int index) const { if(index >= nodes_.size()) return 0; @@ -162,16 +167,16 @@ class NamedNodeMapImpl : public DOM::NamedNodeMap_impl throw DOM::DOMException(DOM::DOMException::NO_MODIFICATION_ALLOWED_ERR); } // throwIfReadOnly - typedef std::deque*> NodeListT; + typedef std::deque NodeListT; - NodeImpl* getNode(typename NodeListT::const_iterator n) const + NodeImplT* getNode(typename NodeListT::const_iterator n) const { if(n == nodes_.end()) return 0; return *n; } // getNode - NodeImpl* setNode(typename NodeListT::iterator n, NodeImpl* arg) + NodeImplT* setNode(typename NodeListT::iterator n, NodeImplT* arg) { if(n == nodes_.end()) { @@ -179,17 +184,17 @@ class NamedNodeMapImpl : public DOM::NamedNodeMap_impl return 0; } // if(n == nodes_.end()) - NodeImpl* removedNode = *n; + NodeImplT* removedNode = *n; *n = arg; ownerDoc_->orphaned(removedNode); return removedNode; } // setNode - NodeImpl* removeNode(typename NodeListT::iterator n) + NodeImplT* removeNode(typename NodeListT::iterator n) { if(n == nodes_.end()) return 0; - NodeImpl* removedNode = *n; + NodeImplT* removedNode = *n; nodes_.erase(n); ownerDoc_->orphaned(removedNode); return removedNode; @@ -209,7 +214,7 @@ class NamedNodeMapImpl : public DOM::NamedNodeMap_impl bool readOnly_; protected: - DocumentImpl* ownerDoc_; + DocumentImplT ownerDoc_; }; // class NamedNodeMapImpl } // namespace SAX2DOM diff --git a/include/DOM/Text.hpp b/include/DOM/Text.hpp index af8e9833..180d0c3d 100644 --- a/include/DOM/Text.hpp +++ b/include/DOM/Text.hpp @@ -13,17 +13,20 @@ namespace Arabica { namespace DOM { -template class Text_impl; +template class Text_impl; -template -class Text : public CharacterData +template +class Text : public CharacterData { - typedef CharacterData CharDataT; + typedef Text_impl Text_implT; public: - Text() : CharacterData() { } - explicit Text(Text_impl* impl) : CharacterData(impl) { } - Text(const Text& rhs) : CharacterData(rhs) { } - explicit Text(const Node& rhs) : CharacterData(rhs, 0) + typedef Node NodeT; + typedef CharacterData CharacterDataT; + + Text() : CharacterDataT() { } + explicit Text(Text_implT* impl) : CharacterDataT(impl) { } + Text(const Text& rhs) : CharacterDataT(rhs) { } + explicit Text(const NodeT& rhs) : CharacterDataT(rhs, 0) { typename Text::Type type = rhs.getNodeType(); if((type != Text::TEXT_NODE) && (type != Text::CDATA_SECTION_NODE)) @@ -32,7 +35,7 @@ class Text : public CharacterData } // Text protected: - Text(const Node& rhs, int dummy) : CharacterData(rhs, 0) { } + Text(const NodeT& rhs, int dummy) : CharacterDataT(rhs, 0) { } Text splitText(int offset) { @@ -40,19 +43,19 @@ class Text : public CharacterData } // splitText protected: - Text_impl* tImpl() const { return dynamic_cast*>(CharDataT::impl()); } + Text_implT* tImpl() const { return dynamic_cast(CharacterDataT::impl()); } }; // class Text //////////////////////////////////////////////////////////////////// -template -class Text_impl : virtual public CharacterData_impl +template +class Text_impl : virtual public CharacterData_impl { public: virtual ~Text_impl() { } //////////////////////////////////////////////////////////// // DOM::Text methods - virtual Text_impl* splitText(int offset) = 0; + virtual Text_impl* splitText(int offset) = 0; }; // Text_impl } // namespace DOM diff --git a/include/DOM/Traversal/DocumentTraversal.hpp b/include/DOM/Traversal/DocumentTraversal.hpp index 4407ff3e..e84b4607 100644 --- a/include/DOM/Traversal/DocumentTraversal.hpp +++ b/include/DOM/Traversal/DocumentTraversal.hpp @@ -38,21 +38,27 @@ enum whatToShowFlags SHOW_NOTATION = 0x00000800 }; -template class NodeIterator; -template class TreeWalker; -template class DocumentTraversal_impl; +template class NodeIterator; +template class TreeWalker; +template class DocumentTraversal_impl; -template -class DocumentTraversal : protected DOM::Proxy > +template +class DocumentTraversal : protected DOM::Proxy > { public: - typedef DOM::Proxy > proxy_t; + typedef NodeFilter NodeFilterT; + typedef TreeWalker TreeWalkerT; + typedef NodeIterator NodeIteratorT; + typedef DocumentTraversal_impl DocumentTraversal_implT; + typedef DOM::Proxy proxy_t; typedef typename proxy_t::value_type impl_t; + typedef DOM::Document DocumentT; + typedef DOM::Node NodeT; DocumentTraversal() : proxy_t(0) { } - explicit DocumentTraversal(DocumentTraversal_impl* const impl) : proxy_t(impl) { } + explicit DocumentTraversal(DocumentTraversal_implT* const impl) : proxy_t(impl) { } DocumentTraversal(const DocumentTraversal& rhs) : proxy_t(rhs) { } - explicit DocumentTraversal(const DOM::Document& rhs) : proxy_t(rhs.dImpl()) + explicit DocumentTraversal(const DocumentT& rhs) : proxy_t(rhs.dImpl()) { if(dynamic_cast(rhs.dImpl()) == 0) throw DOM::DOMException(DOM::DOMException::NOT_SUPPORTED_ERR); @@ -72,55 +78,59 @@ class DocumentTraversal : protected DOM::Proxy > /////////////////////////////////////////////////// // DocumentTraversal methods - NodeIterator createNodeIterator(DOM::Node root, - unsigned long whatToShow, - bool entityRefExpansion) + NodeIteratorT createNodeIterator(NodeT root, + unsigned long whatToShow, + bool entityRefExpansion) { - return NodeIterator(proxy_t::impl()->createNodeIterator(root, whatToShow, 0, entityRefExpansion)); + return NodeIteratorT(proxy_t::impl()->createNodeIterator(root, whatToShow, 0, entityRefExpansion)); } // createNodeIterator - NodeIterator createNodeIterator(DOM::Node root, - unsigned long whatToShow, - NodeFilter& filter, - bool entityRefExpansion) + NodeIteratorT createNodeIterator(NodeT root, + unsigned long whatToShow, + NodeFilterT& filter, + bool entityRefExpansion) { - return NodeIterator(proxy_t::impl()->createNodeIterator(root, whatToShow, &filter, entityRefExpansion)); + return NodeIteratorT(proxy_t::impl()->createNodeIterator(root, whatToShow, &filter, entityRefExpansion)); } // createNodeIterator - TreeWalker createTreeWalker(DOM::Node root, - unsigned long whatToShow, - bool entityRefExpansion) + TreeWalkerT createTreeWalker(NodeT root, + unsigned long whatToShow, + bool entityRefExpansion) { - return TreeWalker(proxy_t::impl()->createTreeWalker(root, whatToShow, 0, entityRefExpansion)); + return TreeWalkerT(proxy_t::impl()->createTreeWalker(root, whatToShow, 0, entityRefExpansion)); } // createTreeWalker - TreeWalker createTreeWalker(DOM::Node root, - unsigned long whatToShow, - NodeFilter& filter, - bool entityRefExpansion) + TreeWalkerT createTreeWalker(NodeT root, + unsigned long whatToShow, + NodeFilterT& filter, + bool entityRefExpansion) { - return TreeWalker(proxy_t::impl()->createTreeWalker(root, whatToShow, &filter, entityRefExpansion)); + return TreeWalkerT(proxy_t::impl()->createTreeWalker(root, whatToShow, &filter, entityRefExpansion)); } // createTreeWalker }; // class DocumentTraversal ////////////////////////////////////////////////////////////// // implementation class -template class NodeIterator_impl; -template class TreeWalker_impl; +template class NodeIterator_impl; +template class TreeWalker_impl; -template +template class DocumentTraversal_impl : virtual public TraversalImpl { public: - virtual NodeIterator_impl* createNodeIterator(DOM::Node root, - unsigned long whatToShow, - NodeFilter* filter, - bool entityRefExpansion) = 0; + typedef NodeFilter NodeFilterT; + typedef TreeWalker_impl TreeWalker_implT; + typedef NodeIterator_impl NodeIterator_implT; - virtual TreeWalker_impl* createTreeWalker(DOM::Node root, - unsigned long whatToShow, - NodeFilter* filter, - bool entityRefExpansion) = 0; + virtual NodeIterator_implT* createNodeIterator(NodeT root, + unsigned long whatToShow, + NodeFilterT* filter, + bool entityRefExpansion) = 0; + + virtual TreeWalker_implT* createTreeWalker(NodeT root, + unsigned long whatToShow, + NodeFilterT* filter, + bool entityRefExpansion) = 0; }; // class DocumentTraveral_impl } // namespace Traversal diff --git a/include/DOM/Traversal/DocumentTraversalImpl.hpp b/include/DOM/Traversal/DocumentTraversalImpl.hpp index de2a7158..63c1d0ea 100644 --- a/include/DOM/Traversal/DocumentTraversalImpl.hpp +++ b/include/DOM/Traversal/DocumentTraversalImpl.hpp @@ -17,36 +17,42 @@ namespace Traversal { -template -class DocumentTraversalImpl : public DocumentTraversal_impl +template +class DocumentTraversalImpl : public DocumentTraversal_impl { public: + typedef DOM::Node NodeT; + typedef NodeFilter NodeFilterT; + typedef NodeIterator_impl NodeIterator_implT; + typedef TreeWalker_impl TreeWalker_implT; + typedef TreeWalkerImpl TreeWalkerImplT; + DocumentTraversalImpl() {} - virtual NodeIterator_impl* createNodeIterator(DOM::Node root, - unsigned long whatToShow, - NodeFilter* filter, - bool entityRefExpansion) + virtual NodeIterator_implT* createNodeIterator(NodeT root, + unsigned long whatToShow, + NodeFilterT* filter, + bool entityRefExpansion) { return 0; } - virtual TreeWalker_impl* createTreeWalker(DOM::Node root, - unsigned long whatToShow, - NodeFilter* filter, - bool entityRefExpansion) + virtual TreeWalker_implT* createTreeWalker(NodeT root, + unsigned long whatToShow, + NodeFilterT* filter, + bool entityRefExpansion) { - return new TreeWalkerImpl(root, whatToShow, filter, entityRefExpansion); + return new TreeWalkerImplT(root, whatToShow, filter, entityRefExpansion); } }; // class DocumentTraversalImpl //todo: move to DOM::Document? -template -DocumentTraversal make_document_traversal_t() +template +DocumentTraversal make_document_traversal_t() { - DocumentTraversal docTraversal(new DocumentTraversalImpl()); + DocumentTraversal docTraversal(new DocumentTraversalImpl()); return docTraversal; } diff --git a/include/DOM/Traversal/NodeFilter.hpp b/include/DOM/Traversal/NodeFilter.hpp index f534f9b5..508e11ac 100644 --- a/include/DOM/Traversal/NodeFilter.hpp +++ b/include/DOM/Traversal/NodeFilter.hpp @@ -12,12 +12,17 @@ namespace Arabica namespace DOM { +template class Node; + namespace Traversal { -template +template class NodeFilter { + public: + typedef DOM::Node NodeT; + protected: virtual ~NodeFilter() { } @@ -31,7 +36,7 @@ class NodeFilter FILTER_SKIP = 3 }; // Result - virtual Result acceptNode(const DOM::Node& node) const = 0; + virtual Result acceptNode(const NodeT& node) const = 0; }; // class NodeFilter diff --git a/include/DOM/Traversal/NodeIterator.hpp b/include/DOM/Traversal/NodeIterator.hpp index cdac8b60..c50e1287 100644 --- a/include/DOM/Traversal/NodeIterator.hpp +++ b/include/DOM/Traversal/NodeIterator.hpp @@ -18,17 +18,22 @@ namespace DOM namespace Traversal { -template class NodeIterator_impl; +template class NodeIterator_impl; -template -class NodeIterator : protected DOM::Proxy > +template +class NodeIterator : protected DOM::Proxy > { + public: + typedef NodeFilter NodeFilterT; + typedef NodeIterator_impl NodeIterator_implT; + typedef DOM::Node NodeT; + private: - typedef DOM::Proxy > proxy_t; + typedef DOM::Proxy proxy_t; public: NodeIterator() : proxy_t(0) { } - explicit NodeIterator(NodeIterator_impl* const impl) : proxy_t(impl) { } + explicit NodeIterator(NodeIterator_implT* const impl) : proxy_t(impl) { } NodeIterator(const NodeIterator& rhs) : proxy_t(rhs) { } virtual ~NodeIterator() { } bool operator==(const NodeIterator& rhs) const { return proxy_t::operator==(rhs); } @@ -44,37 +49,40 @@ class NodeIterator : protected DOM::Proxy > /////////////////////////////////////////////////////////////// // NodeIterator methods - DOM::Node getRoot() const { return proxy_t::impl()->getRoot(); } + NodeT getRoot() const { return proxy_t::impl()->getRoot(); } unsigned long getWhatToShow() const { return proxy_t::impl()->getWhatToShow(); } - NodeFilter* getFilter() const { return proxy_t::impl()->getFilter(); } + NodeFilterT* getFilter() const { return proxy_t::impl()->getFilter(); } bool getExpandEntityReferences() const { return proxy_t::impl()->getExpandEntityReferences(); } - DOM::Node nextNode() { return proxy_t::impl()->nextNode(); } + NodeT nextNode() { return proxy_t::impl()->nextNode(); } - DOM::Node previousNode() { return proxy_t::impl()->prevNode(); } + NodeT previousNode() { return proxy_t::impl()->prevNode(); } void detach() { return proxy_t::impl()->detach(); } }; // class NodeIterator //////////////////////////////////////////////// -template +template class NodeIterator_impl { public: - virtual DOM::Node getRoot() const = 0; + typedef NodeFilter NodeFilterT; + typedef DOM::Node NodeT; + + virtual NodeT getRoot() const = 0; virtual unsigned long getWhatToShow() const = 0; - virtual NodeFilter* getFilter() const = 0; + virtual NodeFilterT* getFilter() const = 0; virtual bool getExpandEntityReferences() const = 0; - virtual DOM::Node nextNode() = 0; + virtual NodeT nextNode() = 0; - virtual DOM::Node previousNode() = 0; + virtual NodeT previousNode() = 0; virtual void detach() = 0; }; // class NodeIterator_impl diff --git a/include/DOM/Traversal/TreeWalker.hpp b/include/DOM/Traversal/TreeWalker.hpp index 6872940e..72f6ec22 100644 --- a/include/DOM/Traversal/TreeWalker.hpp +++ b/include/DOM/Traversal/TreeWalker.hpp @@ -19,17 +19,23 @@ namespace DOM namespace Traversal { -template class TreeWalker_impl; +template class TreeWalker_impl; -template -class TreeWalker : protected DOM::Proxy > +template +class TreeWalker : protected DOM::Proxy > { + public: + typedef TreeWalker_impl TreeWalker_implT; + typedef NodeFilter NodeFilterT; + typedef DOM::Node NodeT; + private: - typedef DOM::Proxy > proxy_t; + typedef DOM::Proxy proxy_t; typedef typename proxy_t::value_type impl_t; + public: TreeWalker() : proxy_t(0) { } - explicit TreeWalker(TreeWalker_impl* const impl) : proxy_t(impl) { } + explicit TreeWalker(TreeWalker_implT* const impl) : proxy_t(impl) { } TreeWalker(const TreeWalker& rhs) : proxy_t(rhs) { } virtual ~TreeWalker() { } bool operator==(const TreeWalker& rhs) const { return proxy_t::operator==(rhs); } @@ -45,62 +51,65 @@ class TreeWalker : protected DOM::Proxy > /////////////////////////////////////////////////////////////// // TreeWalker methods - DOM::Node getRoot() { return proxy_t::impl()->getRoot(); } + NodeT getRoot() { return proxy_t::impl()->getRoot(); } unsigned long getWhatToShow() { return proxy_t::impl()->getWhatToShow(); } - NodeFilter* getFilter() { return proxy_t::impl()->getFilter(); } + NodeFilterT* getFilter() { return proxy_t::impl()->getFilter(); } bool getExpandEntityReferences() { return proxy_t::impl()->getExpandEntityReferences(); } - DOM::Node getCurrentNode() { return proxy_t::impl()->getCurrentNode(); } - void setCurrentNode(const DOM::Node& currentNode) { proxy_t::impl()->setCurrentNode(currentNode); } + NodeT getCurrentNode() { return proxy_t::impl()->getCurrentNode(); } + void setCurrentNode(const NodeT& currentNode) { proxy_t::impl()->setCurrentNode(currentNode); } - DOM::Node parentNode() { return proxy_t::impl()->parentNode(); } + NodeT parentNode() { return proxy_t::impl()->parentNode(); } - DOM::Node firstChild() { return proxy_t::impl()->firstChild(); } + NodeT firstChild() { return proxy_t::impl()->firstChild(); } - DOM::Node lastChild() { return proxy_t::impl()->lastChild(); } + NodeT lastChild() { return proxy_t::impl()->lastChild(); } - DOM::Node previousSibling() { return proxy_t::impl()->previousSibling(); } + NodeT previousSibling() { return proxy_t::impl()->previousSibling(); } - DOM::Node nextSibling() { return proxy_t::impl()->nextSibling(); } + NodeT nextSibling() { return proxy_t::impl()->nextSibling(); } - DOM::Node previousNode() { return proxy_t::impl()->previousNode(); } + NodeT previousNode() { return proxy_t::impl()->previousNode(); } - DOM::Node nextNode() { return proxy_t::impl()->nextNode(); } + NodeT nextNode() { return proxy_t::impl()->nextNode(); } }; // class TreeWalker //////////////////////////////////////////////// -template +template class TreeWalker_impl : public TraversalImpl { public: - virtual DOM::Node getRoot() = 0; + typedef DOM::Node NodeT; + typedef NodeFilter NodeFilterT; + + virtual NodeT getRoot() = 0; virtual unsigned long getWhatToShow() = 0; - virtual NodeFilter* getFilter() = 0; + virtual NodeFilterT* getFilter() = 0; virtual bool getExpandEntityReferences() = 0; - virtual DOM::Node getCurrentNode() = 0; + virtual NodeT getCurrentNode() = 0; - virtual void setCurrentNode(const DOM::Node& currentNode) = 0; + virtual void setCurrentNode(const NodeT& currentNode) = 0; - virtual DOM::Node parentNode() = 0; + virtual NodeT parentNode() = 0; - virtual DOM::Node firstChild() = 0; + virtual NodeT firstChild() = 0; - virtual DOM::Node lastChild() = 0; + virtual NodeT lastChild() = 0; - virtual DOM::Node previousSibling() = 0; + virtual NodeT previousSibling() = 0; - virtual DOM::Node nextSibling() = 0; + virtual NodeT nextSibling() = 0; - virtual DOM::Node previousNode() = 0; + virtual NodeT previousNode() = 0; - virtual DOM::Node nextNode() = 0; + virtual NodeT nextNode() = 0; }; // class TreeWalker_impl } // namespace Traversal diff --git a/include/DOM/Traversal/TreeWalkerImpl.hpp b/include/DOM/Traversal/TreeWalkerImpl.hpp index 5140d324..79226a01 100644 --- a/include/DOM/Traversal/TreeWalkerImpl.hpp +++ b/include/DOM/Traversal/TreeWalkerImpl.hpp @@ -16,19 +16,19 @@ namespace DOM namespace Traversal { -template -class TreeWalkerImpl : public TreeWalker_impl +template +class TreeWalkerImpl : public TreeWalker_impl { public: - typedef DOM::Node node_t; - typedef DOM::Traversal::NodeFilter filter_t; + typedef DOM::Node node_t; + typedef NodeFilter filter_t; typedef typename filter_t::Result filter_result_t; TreeWalkerImpl ( node_t root, unsigned long whatToShow, - NodeFilter* nodeFilter, + filter_t* nodeFilter, bool expandEntityRef ) : root_(root), @@ -47,7 +47,7 @@ public: unsigned long getWhatToShow() { return whatToShow_; } - NodeFilter* getFilter() { return nodeFilter_; } + filter_t* getFilter() { return nodeFilter_; } bool getExpandEntityReferences() { return expandEntityRef_; } @@ -290,7 +290,7 @@ private: node_t root_; node_t currentNode_; unsigned long whatToShow_; - NodeFilter* nodeFilter_; + filter_t* nodeFilter_; bool expandEntityRef_; }; // class TreeWalkerImpl