2002-06-21 13:16:28 +02:00
|
|
|
#ifndef JEZUK_DOM_CHARACTERDATA_H
|
|
|
|
#define JEZUK_DOM_CHARACTERDATA_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
|
|
|
|
{
|
2007-09-08 00:03:27 +02:00
|
|
|
template<class stringT, class string_adaptorT> class CharacterData_impl;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-09 00:31:24 +02:00
|
|
|
template<class stringT, class string_adaptorT = Arabica::default_string_adaptor<stringT> >
|
2007-09-08 00:03:27 +02:00
|
|
|
class CharacterData : public Node<stringT, string_adaptorT>
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2007-09-08 00:03:27 +02:00
|
|
|
typedef CharacterData_impl<stringT, string_adaptorT> CharacterData_implT;
|
2002-06-21 13:16:28 +02:00
|
|
|
public:
|
2007-09-08 00:03:27 +02:00
|
|
|
typedef Node<stringT, string_adaptorT> NodeT;
|
|
|
|
|
|
|
|
CharacterData() : NodeT() { }
|
|
|
|
explicit CharacterData(CharacterData_implT* impl) : NodeT(impl) { }
|
|
|
|
CharacterData(const CharacterData& rhs) : NodeT(rhs) { }
|
|
|
|
explicit CharacterData(const NodeT& rhs) : NodeT(rhs)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2010-12-09 12:35:54 +01:00
|
|
|
if(NodeT::impl_ == 0) // null nodes can always be cast
|
|
|
|
return;
|
2005-10-22 05:17:39 +02:00
|
|
|
typename NodeT::Type type = rhs.getNodeType();
|
|
|
|
if((type != NodeT::TEXT_NODE) && (type != NodeT::CDATA_SECTION_NODE))
|
2010-12-10 10:24:34 +01:00
|
|
|
throw DOMBadCast("CharacterData");
|
2002-06-21 13:16:28 +02:00
|
|
|
} // CharacterData
|
|
|
|
|
2005-08-30 11:40:34 +02:00
|
|
|
protected:
|
2009-12-06 22:34:46 +01:00
|
|
|
CharacterData(const NodeT& rhs, int /*dummy*/) : NodeT(rhs) { }
|
2005-08-30 11:40:34 +02:00
|
|
|
|
|
|
|
public:
|
2005-12-09 16:57:21 +01:00
|
|
|
const stringT& getData() const { return cdImpl()->getData(); }
|
2005-08-30 11:40:34 +02:00
|
|
|
void setData(const stringT& data)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
cdImpl()->setData(data);
|
|
|
|
} // setData
|
|
|
|
|
|
|
|
int getLength() const { return cdImpl()->getLength(); }
|
|
|
|
|
|
|
|
stringT substringData(int offset, int count) const { return cdImpl()->substringData(offset, count); }
|
|
|
|
|
|
|
|
void appendData(const stringT& arg)
|
|
|
|
{
|
|
|
|
cdImpl()->appendData(arg);
|
|
|
|
} // appendData
|
|
|
|
void insertData(int offset, const stringT& arg)
|
|
|
|
{
|
2004-09-18 01:17:51 +02:00
|
|
|
cdImpl()->insertData(offset, arg);
|
2002-06-21 13:16:28 +02:00
|
|
|
} // insertData
|
|
|
|
void deleteData(int offset, int count)
|
|
|
|
{
|
2004-09-18 01:17:51 +02:00
|
|
|
cdImpl()->deleteData(offset, count);
|
2002-06-21 13:16:28 +02:00
|
|
|
} // deleteData
|
|
|
|
void replaceData(int offset, int count, const stringT& arg)
|
|
|
|
{
|
2009-12-06 22:34:46 +01:00
|
|
|
cdImpl()->replaceData(offset, count, arg);
|
2002-06-21 13:16:28 +02:00
|
|
|
} // replaceData
|
|
|
|
|
|
|
|
private:
|
2007-09-08 00:03:27 +02:00
|
|
|
CharacterData_implT* cdImpl() { return dynamic_cast<CharacterData_implT*>(*NodeT::impl_); }
|
|
|
|
const CharacterData_implT* cdImpl() const { return dynamic_cast<const CharacterData_implT*>(*NodeT::impl_); }
|
2002-06-21 13:16:28 +02:00
|
|
|
}; // class CharacterData
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2007-09-08 00:03:27 +02:00
|
|
|
template<class stringT, class string_adaptorT>
|
|
|
|
class CharacterData_impl : virtual public Node_impl<stringT, string_adaptorT>
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~CharacterData_impl () { }
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// DOM::CharacterData methods
|
2005-12-09 16:57:21 +01:00
|
|
|
virtual const stringT& getData() const = 0;
|
2002-06-21 13:16:28 +02:00
|
|
|
virtual void setData(const stringT& data) = 0;
|
|
|
|
|
|
|
|
virtual int getLength() const = 0;
|
|
|
|
|
|
|
|
virtual stringT substringData(int offset, int count) const = 0;
|
|
|
|
|
|
|
|
virtual void appendData(const stringT& arg) = 0;
|
|
|
|
virtual void insertData(int offset, const stringT& arg) = 0;
|
|
|
|
virtual void deleteData(int offset, int count) = 0;
|
|
|
|
virtual void replaceData(int offset, int count, const stringT& arg) = 0;
|
|
|
|
}; // CharacterData_impl
|
|
|
|
|
|
|
|
} // namespace DOM
|
2007-09-05 13:47:13 +02:00
|
|
|
} // namespace Arabica
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
#endif
|