#ifndef H_CORAL_IO_LIBXML2INTERNAL
#define H_CORAL_IO_LIBXML2INTERNAL
// This file is part of the Coral project.
// Please read the copyright notice in the LICENSE file.

#include <libxml/xmlreader.h>

namespace {
	class w {
	protected:
		xmlChar* m_Name;
	public:
		w(xmlChar* name = NULL) : m_Name(name) {
		  ;
		}
		~w() throw () {
			// assume xmlFree allows NULL here
			xmlFree(m_Name);
		}
		xmlChar* operator->() throw () { return get(); }
		xmlChar* get() throw () { return m_Name; }
		w& operator=(w& other) {
		  xmlFree(m_Name);
		  m_Name = other.m_Name;
		  other.m_Name = NULL;
		  return *this;
		}
	};

	struct wXmlTextReaderName : public w {
	  wXmlTextReaderName(xmlTextReaderPtr reader)
		  : w(xmlTextReaderName(reader)) { ; }
	};
	struct wXmlTextReaderValue : public w {
	  wXmlTextReaderValue(xmlTextReaderPtr reader)
		  : w(xmlTextReaderValue(reader)) { ; }
	};
	struct wXmlTextReaderLocalName : public w {
	  wXmlTextReaderLocalName(xmlTextReaderPtr reader)
		  : w(xmlTextReaderLocalName(reader)) { ; }
	};
	struct wXmlTextReaderPrefix : public w {
	  wXmlTextReaderPrefix(xmlTextReaderPtr reader)
		  : w(xmlTextReaderPrefix(reader)) {; }
	};
	struct wXmlTextReaderLookupNamespace : public w {
	  wXmlTextReaderLookupNamespace(xmlTextReaderPtr reader, const xmlChar* prefix)
		  : w(xmlTextReaderLookupNamespace(reader, prefix)) { ; }
	};
	struct wXmlTextReaderGetAttribute : public w {
	  wXmlTextReaderGetAttribute(xmlTextReaderPtr reader, const xmlChar* name)
		  : w(xmlTextReaderGetAttribute(reader, name)) { ; }
	};
	struct wXmlTextReaderGetAttributeNo : public w {
	  wXmlTextReaderGetAttributeNo(xmlTextReaderPtr reader, int no)
		  : w(xmlTextReaderGetAttributeNo(reader, no)) { ; }
	};
}

#endif
