2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
//
|
2016-08-17 17:41:40 +00:00
|
|
|
// unique_ptr alias for libxml2 objects. Deleters for the objects are also
|
2013-11-18 18:40:47 +00:00
|
|
|
// defined in this file.
|
2014-02-14 23:21:05 +00:00
|
|
|
|
2013-11-18 18:40:47 +00:00
|
|
|
#ifndef MPD_BASE_XML_SCOPED_XML_PTR_H_
|
|
|
|
#define MPD_BASE_XML_SCOPED_XML_PTR_H_
|
|
|
|
|
2014-08-28 18:35:15 +00:00
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/xmlschemas.h>
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2013-11-18 18:40:47 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-11-18 18:40:47 +00:00
|
|
|
namespace xml {
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Deleter functor for deleting libxml2 pointers. This is used with
|
|
|
|
/// ScopedXmlPtr.
|
2013-11-18 18:40:47 +00:00
|
|
|
struct XmlDeleter {
|
2016-08-17 17:41:40 +00:00
|
|
|
// Called by std::unique_ptr.
|
2013-12-30 23:05:27 +00:00
|
|
|
inline void operator()(xmlSchemaParserCtxtPtr ptr) const {
|
|
|
|
xmlSchemaFreeParserCtxt(ptr);
|
|
|
|
}
|
|
|
|
inline void operator()(xmlSchemaValidCtxtPtr ptr) const {
|
|
|
|
xmlSchemaFreeValidCtxt(ptr);
|
|
|
|
}
|
2020-10-08 21:46:37 +00:00
|
|
|
inline void operator()(xmlOutputBufferPtr ptr) const {
|
|
|
|
xmlOutputBufferClose(ptr);
|
|
|
|
}
|
2013-12-30 23:05:27 +00:00
|
|
|
inline void operator()(xmlSchemaPtr ptr) const { xmlSchemaFree(ptr); }
|
2013-11-18 18:40:47 +00:00
|
|
|
inline void operator()(xmlNodePtr ptr) const { xmlFreeNode(ptr); }
|
|
|
|
inline void operator()(xmlDocPtr ptr) const { xmlFreeDoc(ptr); }
|
|
|
|
inline void operator()(xmlChar* ptr) const { xmlFree(ptr); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename XmlType>
|
2016-08-17 17:41:40 +00:00
|
|
|
using scoped_xml_ptr = std::unique_ptr<XmlType, XmlDeleter>;
|
2013-11-18 18:40:47 +00:00
|
|
|
|
|
|
|
} // namespace xml
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2016-08-17 17:41:40 +00:00
|
|
|
|
2013-11-18 18:40:47 +00:00
|
|
|
#endif // MPD_BASE_XML_SCOPED_XML_PTR_H_
|