arabica/DOM/Simple/DocumentTypeImpl.h

177 lines
4.8 KiB
C
Raw Normal View History

2002-06-21 13:16:28 +02:00
#ifndef JEZUK_SimpleDOM_DOCUMENTTYPEIMPL_H
#define JEZUK_SimpleDOM_DOCUMENTTYPEIMPL_H
#include <DOM/DocumentType.h>
#include <DOM/Simple/NodeImpl.h>
#include <vector>
namespace SimpleDOM
{
template<class stringT, class string_adaptorT> class ElementImpl;
template<class stringT, class string_adaptorT> class NotationImpl;
template<class stringT, class string_adaptorT> class EntityImpl;
template<class stringT, class string_adaptorT>
class DocumentTypeImpl : public DOM::DocumentType_impl<stringT>,
public ChildlessNodeImpl<stringT, string_adaptorT>
{
typedef ChildlessNodeImpl<stringT, string_adaptorT> NodeT;
2002-06-21 13:16:28 +02:00
public:
DocumentTypeImpl(const stringT& qualifiedName,
const stringT& publicId,
const stringT& systemId) :
DOM::DocumentType_impl<stringT>(),
ChildlessNodeImpl<stringT, string_adaptorT>(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();
2002-06-21 13:16:28 +02:00
else
++refCount_;
} // addRef
virtual void releaseRef()
{
if(NodeT::ownerDoc_)
NodeT::ownerDoc_->releaseRef();
2002-06-21 13:16:28 +02:00
else
if(--refCount_ == 0)
delete this;
} // releaseRef
//////////////////////////////////////////////////////
// DOM::DOMImplementation methods
virtual const stringT& getName() const
2002-06-21 13:16:28 +02:00
{
return getNodeName();
} // getName
virtual DOM::NamedNodeMap_impl<stringT>* getEntities()
{
return &entities_;
} // getEntities
virtual DOM::NamedNodeMap_impl<stringT>* getNotations()
{
return &notations_;
} // getNotations
virtual stringT getPublicId() const
{
return publicId_;
} // getPublicId
virtual stringT getSystemId() const
{
return systemId_;
} // getSystemId
virtual stringT getInternalSubset() const
{
2005-09-30 23:36:11 +02:00
return string_adaptorT::construct_from_utf8("");
2002-06-21 13:16:28 +02:00
} // getInternalSubset
//////////////////////////////////////////////////////////
// DOM::Node methods
2002-11-23 21:03:54 +01:00
typename DOM::Node<stringT>::Type getNodeType() const
2002-06-21 13:16:28 +02:00
{
return DOM::Node<stringT>::DOCUMENT_TYPE_NODE;
} // getNodeType
2005-12-09 15:09:32 +01:00
virtual const stringT& getNodeName() const
2002-06-21 13:16:28 +02:00
{
return qualifiedName_;
} // getNodeName
DOM::Node_impl<stringT>* cloneNode(bool deep) const
{
DocumentTypeImpl* clone = new DocumentTypeImpl(qualifiedName_, publicId_, systemId_);
return clone;
} // cloneNode
virtual void setOwnerDoc(DocumentImpl<stringT, string_adaptorT>* ownerDoc)
{
entities_.setOwnerDoc(ownerDoc);
notations_.setOwnerDoc(ownerDoc);
ChildlessNodeImpl<stringT, string_adaptorT>::setOwnerDoc(ownerDoc);
while(refCount_--)
NodeT::ownerDoc_->addRef();
2002-06-21 13:16:28 +02:00
} // setOwnerDocument
NamedNodeMapImpl<stringT, string_adaptorT>* getElements()
{
return &elements_;
} // getElements
std::vector<stringT>* getElementIds()
{
return &IDs_;
} // getIDs
protected:
void addEntity(SimpleDOM::EntityImpl<stringT, string_adaptorT>* entity)
{
entities_.setReadOnly(false);
entity->setOwnerDoc(NodeT::ownerDoc_);
2002-06-21 13:16:28 +02:00
entities_.setNamedItem(entity);
entities_.setReadOnly(true);
} // setEntity
void addNotation(SimpleDOM::NotationImpl<stringT, string_adaptorT>* notation)
{
notations_.setReadOnly(false);
notation->setOwnerDoc(NodeT::ownerDoc_);
2002-06-21 13:16:28 +02:00
notations_.setNamedItem(notation);
notations_.setReadOnly(true);
} // setNotation
void addElement(SimpleDOM::ElementImpl<stringT, string_adaptorT>* element)
{
2004-01-28 22:38:17 +01:00
if(elements_.getNamedItem(element->getNodeName()) != 0)
{
delete element;
return; // already have an element decl for it
} // if ...
element->setOwnerDoc(NodeT::ownerDoc_);
2002-06-21 13:16:28 +02:00
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<stringT, string_adaptorT> entities_;
NamedNodeMapImpl<stringT, string_adaptorT> notations_;
NamedNodeMapImpl<stringT, string_adaptorT> elements_;
std::vector<stringT> IDs_;
unsigned int refCount_;
}; // class DOMImplementation
} // namespace SAX2DOM
#endif
// end of file