2002-06-21 13:16:28 +02:00
|
|
|
#ifndef JEZUK_DOM_NODE_H
|
|
|
|
#define JEZUK_DOM_NODE_H
|
|
|
|
|
|
|
|
////////////////////////////
|
|
|
|
// C++ DOM definition
|
|
|
|
////////////////////////////
|
2007-09-05 00:55:47 +02:00
|
|
|
#include <DOM/Proxy.hpp>
|
|
|
|
#include <DOM/DOMException.hpp>
|
2007-09-10 19:52:04 +02:00
|
|
|
#include <Arabica/StringAdaptor.hpp>
|
2007-09-09 00:31:24 +02:00
|
|
|
|
|
|
|
|
2002-06-21 13:16:28 +02:00
|
|
|
#include <typeinfo>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2007-09-05 13:47:13 +02:00
|
|
|
namespace Arabica
|
2015-12-10 00:03:49 +01:00
|
|
|
{
|
2002-06-21 13:16:28 +02:00
|
|
|
namespace DOM
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Events {
|
2007-09-08 00:03:27 +02:00
|
|
|
template<class stringT, class string_adaptorT> class EventTarget;
|
2015-12-10 00:03:49 +01:00
|
|
|
} // namespace Events
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
template<class stringT, class string_adaptorT> class Document;
|
|
|
|
template<class stringT, class string_adaptorT> class NodeList;
|
|
|
|
template<class stringT, class string_adaptorT> class NamedNodeMap;
|
|
|
|
template<class stringT, class string_adaptorT> class Node_impl;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
class Node_base
|
|
|
|
{
|
2009-12-14 23:39:15 +01:00
|
|
|
public:
|
|
|
|
typedef int Type;
|
|
|
|
|
|
|
|
static const int ELEMENT_NODE = 1;
|
|
|
|
static const int ATTRIBUTE_NODE = 2;
|
|
|
|
static const int TEXT_NODE = 3;
|
|
|
|
static const int CDATA_SECTION_NODE = 4;
|
|
|
|
static const int ENTITY_REFERENCE_NODE = 5;
|
|
|
|
static const int ENTITY_NODE = 6;
|
|
|
|
static const int PROCESSING_INSTRUCTION_NODE = 7;
|
|
|
|
static const int COMMENT_NODE = 8;
|
|
|
|
static const int DOCUMENT_NODE = 9;
|
|
|
|
static const int DOCUMENT_TYPE_NODE = 10;
|
|
|
|
static const int DOCUMENT_FRAGMENT_NODE = 11;
|
|
|
|
static const int NOTATION_NODE = 12;
|
|
|
|
static const int MAX_TYPE = 13;
|
2002-06-21 13:16:28 +02:00
|
|
|
}; // class Node_base
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////
|
2007-09-09 00:31:24 +02:00
|
|
|
template<class stringT, class string_adaptorT = Arabica::default_string_adaptor<stringT> >
|
2002-06-21 13:16:28 +02:00
|
|
|
class Node : public Node_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Node() : impl_() { }
|
2007-09-08 00:03:27 +02:00
|
|
|
Node(Node_impl<stringT, string_adaptorT>* const impl) : impl_(impl) { }
|
2002-06-21 13:16:28 +02:00
|
|
|
Node(const Node& rhs) : impl_(rhs.impl_) { }
|
|
|
|
virtual ~Node() { }
|
|
|
|
|
2007-01-02 12:32:48 +01:00
|
|
|
operator bool() const { return impl_; }
|
2013-01-07 14:55:13 +01:00
|
|
|
bool operator< (const Node& rhs) const { return impl_ < rhs.impl_; }
|
2002-06-21 13:16:28 +02:00
|
|
|
bool operator==(const Node& rhs) const { return impl_ == rhs.impl_; }
|
|
|
|
bool operator!=(const Node& rhs) const { return impl_ != rhs.impl_; }
|
2015-12-10 00:03:49 +01:00
|
|
|
bool operator==(int dummy) const { return impl_ == dummy; }
|
2002-06-21 13:16:28 +02:00
|
|
|
bool operator!=(int dummy) const { return impl_ != dummy; }
|
|
|
|
|
2015-12-10 00:03:49 +01:00
|
|
|
Node& operator=(const Node& rhs)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
impl_ = rhs.impl_;
|
|
|
|
return *this;
|
|
|
|
} // operator=
|
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
const stringT& getNodeName() const { return impl_->getNodeName(); }
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
const stringT& getNodeValue() const { return impl_->getNodeValue(); }
|
|
|
|
void setNodeValue(const stringT& nodeValue) { impl_->setNodeValue(nodeValue); }
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
Type getNodeType() const { return impl_->getNodeType(); }
|
2015-12-10 00:03:49 +01:00
|
|
|
|
2002-06-21 13:16:28 +02:00
|
|
|
Node getParentNode() const { return impl_->getParentNode(); }
|
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
const NodeList<stringT, string_adaptorT> getChildNodes() const { return NodeList<stringT, string_adaptorT>(impl_->getChildNodes()); }
|
2015-12-10 00:03:49 +01:00
|
|
|
|
2002-06-21 13:16:28 +02:00
|
|
|
Node getFirstChild() const { return impl_->getFirstChild(); }
|
|
|
|
Node getLastChild() const { return impl_->getLastChild(); }
|
|
|
|
Node getPreviousSibling() const { return impl_->getPreviousSibling(); }
|
|
|
|
Node getNextSibling() const { return impl_->getNextSibling(); }
|
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
const NamedNodeMap<stringT, string_adaptorT> getAttributes() const { return NamedNodeMap<stringT, string_adaptorT>(impl_->getAttributes()); }
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
Document<stringT, string_adaptorT> getOwnerDocument() const { return impl_->getOwnerDocument(); }
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2015-12-10 00:03:49 +01:00
|
|
|
Node insertBefore(const Node& newChild, const Node& refChild) { return impl_->insertBefore(*newChild.impl_, *refChild.impl_); }
|
2002-06-21 13:16:28 +02:00
|
|
|
Node replaceChild(const Node& newChild, const Node& oldChild) { return impl_->replaceChild(*newChild.impl_, *oldChild.impl_); }
|
2015-12-10 00:03:49 +01:00
|
|
|
Node removeChild(const Node& oldChild) { return impl_->removeChild(*oldChild.impl_); }
|
2002-06-21 13:16:28 +02:00
|
|
|
Node appendChild(const Node& newChild) { return impl_->appendChild(*newChild.impl_); }
|
2015-12-10 00:03:49 +01:00
|
|
|
void purgeChild(Node& oldChild)
|
|
|
|
{
|
2007-09-08 00:03:27 +02:00
|
|
|
Node_impl<stringT, string_adaptorT>* child = *oldChild.impl_;
|
2005-11-25 23:39:16 +01:00
|
|
|
oldChild = 0;
|
|
|
|
|
|
|
|
try {
|
2015-12-10 00:03:49 +01:00
|
|
|
impl_->purgeChild(child);
|
2005-11-25 23:39:16 +01:00
|
|
|
}
|
2005-11-28 13:40:20 +01:00
|
|
|
catch(DOMException&)
|
2005-11-25 23:39:16 +01:00
|
|
|
{
|
|
|
|
oldChild = child;
|
|
|
|
throw;
|
|
|
|
} // catch
|
|
|
|
} // purge
|
2015-12-10 00:03:49 +01:00
|
|
|
|
2002-06-21 13:16:28 +02:00
|
|
|
bool hasChildNodes() const { return impl_->hasChildNodes(); }
|
|
|
|
|
|
|
|
Node cloneNode(bool deep) const { return impl_->cloneNode(deep); }
|
|
|
|
|
|
|
|
void normalize() { impl_->normalize(); }
|
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
bool isSupported(const stringT& feature, const stringT& version) const { return impl_->isSupported(feature, version); }
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
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(); }
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
// additional three methods - since C++ std::string (and by implication
|
2007-09-08 00:03:27 +02:00
|
|
|
// stringT) don't differenciate between a null string and an empty string,
|
2015-12-10 00:03:49 +01:00
|
|
|
// but the DOM recommendation does, I have to introduce these three methods
|
2002-06-21 13:16:28 +02:00
|
|
|
// to disambiguate. If they return false, the corresponding attribute should be
|
2015-12-10 00:03:49 +01:00
|
|
|
// considered null. If they return true, the attribute has been set EVEN IF
|
2002-06-21 13:16:28 +02:00
|
|
|
// it has been set to the empty string
|
2015-12-10 00:03:49 +01:00
|
|
|
bool hasNamespaceURI() const { return impl_->hasNamespaceURI(); }
|
2002-06-21 13:16:28 +02:00
|
|
|
bool hasPrefix() const { return impl_->hasPrefix(); }
|
|
|
|
|
|
|
|
bool hasAttributes() const { return impl_->hasAttributes(); }
|
|
|
|
|
2005-07-16 00:51:57 +02:00
|
|
|
// you almost certainly don't need to use this function
|
2008-04-23 16:41:00 +02:00
|
|
|
Node_impl<stringT, string_adaptorT>* underlying_impl() const { return *impl_; }
|
2009-05-19 10:24:19 +02:00
|
|
|
void set_underlying_impl(Node_impl<stringT, string_adaptorT>* new_impl) { impl_ = new_impl; }
|
2005-07-16 00:51:57 +02:00
|
|
|
|
2002-06-21 13:16:28 +02:00
|
|
|
protected:
|
2007-09-08 00:03:27 +02:00
|
|
|
Proxy<Node_impl<stringT, string_adaptorT> > impl_;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
typedef class Document<stringT, string_adaptorT> DocumentT;
|
|
|
|
friend class Document<stringT, string_adaptorT>;
|
2009-11-25 11:23:27 +01:00
|
|
|
friend class NamedNodeMap<stringT, string_adaptorT>;
|
2007-09-08 00:03:27 +02:00
|
|
|
typedef class Events::EventTarget<stringT, string_adaptorT> EventTargetT;
|
|
|
|
friend class Events::EventTarget<stringT, string_adaptorT>;
|
2002-06-21 13:16:28 +02:00
|
|
|
}; // class Node
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
// derive from this class to implement your own
|
|
|
|
// DOM provider
|
2007-09-08 00:03:27 +02:00
|
|
|
template<class stringT, class string_adaptorT> class Document_impl;
|
|
|
|
template<class stringT, class string_adaptorT> class NodeList_impl;
|
|
|
|
template<class stringT, class string_adaptorT> class NamedNodeMap_impl;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
template<class stringT, class string_adaptorT>
|
2002-06-21 13:16:28 +02:00
|
|
|
class Node_impl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Node_impl() { }
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// Ref counting
|
|
|
|
virtual void addRef() = 0;
|
|
|
|
virtual void releaseRef() = 0;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// Node methods
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual const stringT& getNodeName() const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual const stringT& getNodeValue() const = 0;
|
|
|
|
virtual void setNodeValue(const stringT& nodeValue) = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
virtual Node_base::Type getNodeType() const = 0;
|
2015-12-10 00:03:49 +01:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual Node_impl<stringT, string_adaptorT>* getParentNode() const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual NodeList_impl<stringT, string_adaptorT>* getChildNodes() const = 0;
|
2015-12-10 00:03:49 +01:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual Node_impl<stringT, string_adaptorT>* getFirstChild() const = 0;
|
|
|
|
virtual Node_impl<stringT, string_adaptorT>* getLastChild() const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual Node_impl<stringT, string_adaptorT>* getPreviousSibling() const = 0;
|
|
|
|
virtual Node_impl<stringT, string_adaptorT>* getNextSibling() const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual NamedNodeMap_impl<stringT, string_adaptorT>* getAttributes() const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual Document_impl<stringT, string_adaptorT>* getOwnerDocument() const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual Node_impl<stringT, string_adaptorT>* insertBefore(Node_impl<stringT, string_adaptorT>* newChild, Node_impl<stringT, string_adaptorT>* refChild) = 0;
|
|
|
|
virtual Node_impl<stringT, string_adaptorT>* replaceChild(Node_impl<stringT, string_adaptorT>* newChild, Node_impl<stringT, string_adaptorT>* oldChild) = 0;
|
|
|
|
virtual Node_impl<stringT, string_adaptorT>* removeChild(Node_impl<stringT, string_adaptorT>* oldChild) = 0;
|
|
|
|
virtual Node_impl<stringT, string_adaptorT>* appendChild(Node_impl<stringT, string_adaptorT>* newChild) = 0;
|
|
|
|
virtual void purgeChild(Node_impl<stringT, string_adaptorT>* oldChild) = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
virtual bool hasChildNodes() const = 0;
|
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual Node_impl<stringT, string_adaptorT>* cloneNode(bool deep) const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
virtual void normalize() = 0;
|
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
virtual bool isSupported(const stringT& feature, const stringT& version) const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-08 00:03:27 +02:00
|
|
|
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;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
// additional methods - since C++ std::string (and by implication
|
2007-09-08 00:03:27 +02:00
|
|
|
// stringT) don't differenciate between a null string and an empty string,
|
2015-12-10 00:03:49 +01:00
|
|
|
// but the DOM recommendation does, I have to introduce these three methods
|
2002-06-21 13:16:28 +02:00
|
|
|
// to disambiguate. If they return false, the corresponding attribute should be
|
2015-12-10 00:03:49 +01:00
|
|
|
// considered null. If they return true, the attribute has been set EVEN IF
|
2002-06-21 13:16:28 +02:00
|
|
|
// it has been set to the empty string
|
|
|
|
virtual bool hasNamespaceURI() const = 0;
|
|
|
|
virtual bool hasPrefix() const = 0;
|
|
|
|
|
|
|
|
virtual bool hasAttributes() const = 0;
|
|
|
|
}; // class Node_impl
|
|
|
|
|
|
|
|
} // namespace DOM
|
2007-09-05 13:47:13 +02:00
|
|
|
} // namespace Arabica
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
#endif // JEZUK_DOM_NODE_H
|
|
|
|
// end of file
|