Shaka Packager SDK
Loading...
Searching...
No Matches
scoped_xml_ptr.h
1// Copyright 2014 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6//
7// unique_ptr alias for libxml2 objects. Deleters for the objects are also
8// defined in this file.
9
10#ifndef MPD_BASE_XML_SCOPED_XML_PTR_H_
11#define MPD_BASE_XML_SCOPED_XML_PTR_H_
12
13#include <memory>
14
15#include <libxml/tree.h>
16#include <libxml/xmlschemas.h>
17
18namespace shaka {
19namespace xml {
20
23struct XmlDeleter {
24 // Called by std::unique_ptr.
25 inline void operator()(xmlSchemaParserCtxtPtr ptr) const {
26 xmlSchemaFreeParserCtxt(ptr);
27 }
28 inline void operator()(xmlSchemaValidCtxtPtr ptr) const {
29 xmlSchemaFreeValidCtxt(ptr);
30 }
31 inline void operator()(xmlOutputBufferPtr ptr) const {
32 xmlOutputBufferClose(ptr);
33 }
34 inline void operator()(xmlSchemaPtr ptr) const { xmlSchemaFree(ptr); }
35 inline void operator()(xmlNodePtr ptr) const { xmlFreeNode(ptr); }
36 inline void operator()(xmlDocPtr ptr) const { xmlFreeDoc(ptr); }
37 inline void operator()(xmlChar* ptr) const { xmlFree(ptr); }
38};
39
40template <typename XmlType>
41using scoped_xml_ptr = std::unique_ptr<XmlType, XmlDeleter>;
42
43} // namespace xml
44} // namespace shaka
45
46#endif // MPD_BASE_XML_SCOPED_XML_PTR_H_
All the methods that are virtual are virtual for mocking.