arabica/include/DOM/Attr.h
2006-12-14 11:51:23 +00:00

72 lines
1.9 KiB
C++

#ifndef JEZUK_DOM_ATTR_H
#define JEZUK_DOM_ATTR_H
////////////////////////////
// C++ DOM definition
//
// $Id$
////////////////////////////
#include <DOM/Node.h>
namespace DOM
{
template<class stringT> class Element;
template<class stringT> class Attr_impl;
template<class stringT>
class Attr : public Node<stringT>
{
typedef Node<stringT> NodeT;
public:
Attr() : Node<stringT>() { }
explicit Attr(Attr_impl<stringT>* impl) : Node<stringT>(impl) { }
Attr(const Attr& rhs) : Node<stringT>(rhs) { }
explicit Attr(const Node<stringT>& rhs) : Node<stringT>(rhs)
{
if(rhs.getNodeType() != Node<stringT>::ATTRIBUTE_NODE)
throw std::bad_cast();
} // Attr
const stringT& getName() const { return attrImpl()->getName(); }
bool getSpecified() const { return attrImpl()->getSpecified(); }
const stringT& getValue() const { return attrImpl()->getValue(); }
void setValue(const stringT& value) { attrImpl()->setValue(value); }
Element<stringT> getOwnerElement() const { return Element<stringT>(attrImpl()->getOwnerElement()); }
private:
Attr_impl<stringT>* attrImpl() const { return dynamic_cast<Attr_impl<stringT>*>(*NodeT::impl_); }
typedef Element<stringT> ElementT;
friend class Element<stringT>;
}; // class Attr
//////////////////////////////////////////////////////////
template<class stringT> class Element_impl;
template<class stringT>
class Attr_impl : virtual public Node_impl<stringT>
{
public:
virtual ~Attr_impl() { }
///////////////////////////////////////////////////
// DOM::Attribute methods
virtual const stringT& getName() const = 0;
virtual bool getSpecified() const = 0;
virtual const stringT& getValue() const = 0;
virtual void setValue(const stringT& value) = 0;
virtual Element_impl<stringT>* getOwnerElement() const = 0;
}; // class Attr_impl
} // namespace DOM
#endif