DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
scoped_xml_ptr.h
1 // Copyright 2014 Google Inc. 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 // scoped_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 <libxml/tree.h>
14 #include <libxml/xmlschemas.h>
15 
16 #include "packager/base/memory/scoped_ptr.h"
17 
18 namespace shaka {
19 namespace xml {
20 
23 struct XmlDeleter {
24  // Called by scoped_ptr. http://goo.gl/YaLbcS
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()(xmlSchemaPtr ptr) const { xmlSchemaFree(ptr); }
32  inline void operator()(xmlNodePtr ptr) const { xmlFreeNode(ptr); }
33  inline void operator()(xmlDocPtr ptr) const { xmlFreeDoc(ptr); }
34  inline void operator()(xmlChar* ptr) const { xmlFree(ptr); }
35 };
36 
37 template <typename XmlType>
38 using scoped_xml_ptr = scoped_ptr<XmlType, XmlDeleter>;
39 
40 } // namespace xml
41 } // namespace shaka
42 #endif // MPD_BASE_XML_SCOPED_XML_PTR_H_