arabica/include/DOM/Attr.hpp

81 lines
2.2 KiB
C++
Raw Normal View History

2002-06-21 13:16:28 +02:00
#ifndef JEZUK_DOM_ATTR_H
#define JEZUK_DOM_ATTR_H
////////////////////////////
// C++ DOM definition
//
// $Id$
////////////////////////////
2007-09-05 00:55:47 +02:00
#include <DOM/Node.hpp>
2002-06-21 13:16:28 +02:00
2007-09-05 13:47:13 +02:00
namespace Arabica
{
2002-06-21 13:16:28 +02:00
namespace DOM
{
template<class stringT, class string_adaptorT> class Element;
template<class stringT, class string_adaptorT> class Attr_impl;
2002-06-21 13:16:28 +02:00
template<class stringT, class string_adaptorT = Arabica::default_string_adaptor<stringT> >
class Attr : public Node<stringT, string_adaptorT>
2002-06-21 13:16:28 +02:00
{
public:
typedef Node<stringT, string_adaptorT> NodeT;
typedef Element<stringT, string_adaptorT> ElementT;
typedef Attr_impl<stringT, string_adaptorT> Attr_implT;
Attr() : NodeT() { }
explicit Attr(Attr_implT* impl) : NodeT(impl) { }
Attr(const Attr& rhs) : NodeT(rhs) { }
explicit Attr(const NodeT& rhs) : NodeT(rhs)
2002-06-21 13:16:28 +02:00
{
if(NodeT::impl_ == 0) // null nodes can always be cast
return;
if(rhs.getNodeType() != NodeT::ATTRIBUTE_NODE)
2010-12-10 10:24:34 +01:00
throw DOMBadCast("Attr");
2002-06-21 13:16:28 +02:00
} // Attr
const stringT& getName() const { return attrImpl()->getName(); }
2002-06-21 13:16:28 +02:00
bool getSpecified() const { return attrImpl()->getSpecified(); }
const stringT& getValue() const { return attrImpl()->getValue(); }
2006-12-14 12:51:23 +01:00
void setValue(const stringT& value) { attrImpl()->setValue(value); }
2002-06-21 13:16:28 +02:00
ElementT getOwnerElement() const { return ElementT(attrImpl()->getOwnerElement()); }
2002-06-21 13:16:28 +02:00
private:
Attr_implT* attrImpl() const { return dynamic_cast<Attr_implT*>(*NodeT::impl_); }
2002-06-21 13:16:28 +02:00
friend class Element<stringT, string_adaptorT>;
2005-06-06 23:00:20 +02:00
}; // class Attr
2002-06-21 13:16:28 +02:00
//////////////////////////////////////////////////////////
template<class stringT, class string_adaptorT> class Element_impl;
2002-06-21 13:16:28 +02:00
template<class stringT, class string_adaptorT>
class Attr_impl : virtual public Node_impl<stringT, string_adaptorT>
2002-06-21 13:16:28 +02:00
{
public:
virtual ~Attr_impl() { }
///////////////////////////////////////////////////
// DOM::Attribute methods
virtual const stringT& getName() const = 0;
2002-06-21 13:16:28 +02:00
virtual bool getSpecified() const = 0;
virtual const stringT& getValue() const = 0;
2002-06-21 13:16:28 +02:00
virtual void setValue(const stringT& value) = 0;
virtual Element_impl<stringT, string_adaptorT>* getOwnerElement() const = 0;
2002-06-21 13:16:28 +02:00
}; // class Attr_impl
} // namespace DOM
2007-09-05 13:47:13 +02:00
} // namespace Arabica
2002-06-21 13:16:28 +02:00
#endif