From 21aad421ceb81130cd0c98c39a7bf12a690cc496 Mon Sep 17 00:00:00 2001 From: Rintaro Kuroiwa Date: Mon, 18 Nov 2013 10:40:47 -0800 Subject: [PATCH] scoped_ptr definitions for libxml2 objects Change-Id: Iafbfce42d5cb91b0a5ddbf3149d434e10a4cb8d6 --- mpd/base/xml/scoped_xml_ptr.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 mpd/base/xml/scoped_xml_ptr.h diff --git a/mpd/base/xml/scoped_xml_ptr.h b/mpd/base/xml/scoped_xml_ptr.h new file mode 100644 index 0000000000..6aeee3ab47 --- /dev/null +++ b/mpd/base/xml/scoped_xml_ptr.h @@ -0,0 +1,28 @@ +// scoped_ptr alias for libxml2 objects. Deleters for the objects are also +// defined in this file. +#ifndef MPD_BASE_XML_SCOPED_XML_PTR_H_ +#define MPD_BASE_XML_SCOPED_XML_PTR_H_ + +#include "base/memory/scoped_ptr.h" +#include "third_party/libxml/src/include/libxml/tree.h" + +namespace dash_packager { +namespace xml { + +struct XmlDeleter { + // Called by scoped_ptr. http://goo.gl/YaLbcS + inline void operator()(xmlNodePtr ptr) const { xmlFreeNode(ptr); } + inline void operator()(xmlDocPtr ptr) const { xmlFreeDoc(ptr); } + inline void operator()(xmlChar* ptr) const { xmlFree(ptr); } +}; + +// C++11 allows template alias but standards before it do not. This struct is +// for aliasing scoped_ptr with libxml2 object deleter. +template +struct ScopedXmlPtr { + typedef scoped_ptr type; +}; + +} // namespace xml +} // namespace dash_packager +#endif // MPD_BASE_XML_SCOPED_XML_PTR_H_