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/xmlIO.h>
17#include <libxml/xmlmemory.h>
18#include <libxml/xmlschemas.h>
19#include <libxml/xmlstring.h>
20
21namespace shaka {
22namespace xml {
23
26struct XmlDeleter {
27 // Called by std::unique_ptr.
28 inline void operator()(xmlSchemaParserCtxtPtr ptr) const {
29 xmlSchemaFreeParserCtxt(ptr);
30 }
31 inline void operator()(xmlSchemaValidCtxtPtr ptr) const {
32 xmlSchemaFreeValidCtxt(ptr);
33 }
34 inline void operator()(xmlOutputBufferPtr ptr) const {
35 xmlOutputBufferClose(ptr);
36 }
37 inline void operator()(xmlSchemaPtr ptr) const { xmlSchemaFree(ptr); }
38 inline void operator()(xmlNodePtr ptr) const { xmlFreeNode(ptr); }
39 inline void operator()(xmlDocPtr ptr) const { xmlFreeDoc(ptr); }
40 inline void operator()(xmlChar* ptr) const { xmlFree(ptr); }
41};
42
43template <typename XmlType>
44using scoped_xml_ptr = std::unique_ptr<XmlType, XmlDeleter>;
45
46} // namespace xml
47} // namespace shaka
48
49#endif // MPD_BASE_XML_SCOPED_XML_PTR_H_
All the methods that are virtual are virtual for mocking.