#ifndef JEZUK_SimpleDOM_DOCUMENTTYPEIMPL_H #define JEZUK_SimpleDOM_DOCUMENTTYPEIMPL_H #include #include #include namespace SimpleDOM { template class ElementImpl; template class NotationImpl; template class EntityImpl; template class DocumentTypeImpl : public DOM::DocumentType_impl, public ChildlessNodeImpl { typedef ChildlessNodeImpl NodeT; public: DocumentTypeImpl(const stringT& qualifiedName, const stringT& publicId, const stringT& systemId) : DOM::DocumentType_impl(), ChildlessNodeImpl(0), qualifiedName_(qualifiedName), publicId_(publicId), systemId_(systemId), entities_(0), notations_(0), elements_(0), refCount_(0) { entities_.setReadOnly(true); notations_.setReadOnly(true); } // DOMImplemenationImpl virtual ~DocumentTypeImpl() { } /////////////////////////////////////////////////////// // Ref counting virtual void addRef() { if(NodeT::ownerDoc_) NodeT::ownerDoc_->addRef(); else ++refCount_; } // addRef virtual void releaseRef() { if(NodeT::ownerDoc_) NodeT::ownerDoc_->releaseRef(); else if(--refCount_ == 0) delete this; } // releaseRef ////////////////////////////////////////////////////// // DOM::DOMImplementation methods virtual stringT getName() const { return getNodeName(); } // getName virtual DOM::NamedNodeMap_impl* getEntities() { return &entities_; } // getEntities virtual DOM::NamedNodeMap_impl* getNotations() { return ¬ations_; } // getNotations virtual stringT getPublicId() const { return publicId_; } // getPublicId virtual stringT getSystemId() const { return systemId_; } // getSystemId virtual stringT getInternalSubset() const { return string_adaptorT::construct_from_utf8(""); } // getInternalSubset ////////////////////////////////////////////////////////// // DOM::Node methods typename DOM::Node::Type getNodeType() const { return DOM::Node::DOCUMENT_TYPE_NODE; } // getNodeType virtual stringT getNodeName() const { return qualifiedName_; } // getNodeName DOM::Node_impl* cloneNode(bool deep) const { DocumentTypeImpl* clone = new DocumentTypeImpl(qualifiedName_, publicId_, systemId_); return clone; } // cloneNode virtual void setOwnerDoc(DocumentImpl* ownerDoc) { entities_.setOwnerDoc(ownerDoc); notations_.setOwnerDoc(ownerDoc); ChildlessNodeImpl::setOwnerDoc(ownerDoc); while(refCount_--) NodeT::ownerDoc_->addRef(); } // setOwnerDocument NamedNodeMapImpl* getElements() { return &elements_; } // getElements std::vector* getElementIds() { return &IDs_; } // getIDs protected: void addEntity(SimpleDOM::EntityImpl* entity) { entities_.setReadOnly(false); entity->setOwnerDoc(NodeT::ownerDoc_); entities_.setNamedItem(entity); entities_.setReadOnly(true); } // setEntity void addNotation(SimpleDOM::NotationImpl* notation) { notations_.setReadOnly(false); notation->setOwnerDoc(NodeT::ownerDoc_); notations_.setNamedItem(notation); notations_.setReadOnly(true); } // setNotation void addElement(SimpleDOM::ElementImpl* element) { if(elements_.getNamedItem(element->getNodeName()) != 0) { delete element; return; // already have an element decl for it } // if ... element->setOwnerDoc(NodeT::ownerDoc_); elements_.setNamedItem(element); } // addElements void addElementId(const stringT& elementId) { IDs_.push_back(elementId); } // addId private: DocumentTypeImpl(const DocumentTypeImpl&); DocumentTypeImpl& operator=(const DocumentTypeImpl&); stringT qualifiedName_; stringT publicId_; stringT systemId_; NamedNodeMapImpl entities_; NamedNodeMapImpl notations_; NamedNodeMapImpl elements_; std::vector IDs_; unsigned int refCount_; }; // class DOMImplementation } // namespace SAX2DOM #endif // end of file