On Tuesday 07 March 2006 15:56, Scott Cantor wrote:
> I stick with XMLCh* until I need
> 8-bit strings and then I wrap them in a simple auto_ptr clone that does a
> release() instead of a delete.
Something like this? Perhaps I could delay the conversion until I call the
conversion operator?
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
using namespace xercesc;
template<class Y> struct XCPtr_ref {
Y* y_ptr;
XCPtr_ref (Y* rhs): y_ptr(rhs) {}
};
template<typename C=char, typename T=XMLCh, typename XS=XMLString>
class XCPtr {
public:
typedef T element_type;
explicit XCPtr(C* ptr = 0) throw(): x_ptr(XS::transcode(ptr))
{}
XCPtr (XCPtr& rhs) throw(): x_ptr(rhs.release()) {}
template<class Y> XCPtr (XCPtr<Y>& rhs) throw(): x_ptr(rhs.release()) {}
XCPtr& operator= (XCPtr& rhs) throw() {
reset(rhs.release());
return *this;
}
template<class Y>
XCPtr& operator=(XCPtr<Y>& rhs) throw() {
reset(rhs.release());
return *this;
}
template<class Y> operator Y() throw() { return x_ptr; }
~XCPtr() throw() { XS::transcode(x_ptr); }
T* get () const throw() { return x_ptr; }
T& operator* () const throw() { return *x_ptr; }
T* operator->() const throw() { return x_ptr; }
T* release() throw(){
T* tmp(x_ptr);
x_ptr = 0;
return tmp;
}
void reset (T* ptr=0) throw() {
if (x_ptr != ptr) {
XS::transcode(x_ptr);
x_ptr = ptr;
}
}
XCPtr(XCPtr_ref<T> rhs) throw(): x_ptr(rhs.y_ptr) {}
XCPtr& operator= (XCPtr_ref<T> rhs) throw() {
reset(rhs.y_ptr);
return *this;
}
template<class Y> operator XCPtr_ref<Y>() throw() { return
XCPtr_ref<Y>(release()); }
template<class Y> operator XCPtr<Y> () throw() { return XCPtr<Y>
(release()); }
private:
T* x_ptr;
};
typedef XCPtr<char, XMLCh, XMLString> XPtr;
typedef XCPtr<XMLCh, char, XMLString> CPtr;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]