DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
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 edash_packager {
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 // C++11 allows template alias but standards before it do not. This struct is
38 // for aliasing scoped_ptr with libxml2 object deleter.
40 template <typename XmlType>
41 struct ScopedXmlPtr {
42  typedef scoped_ptr<XmlType, XmlDeleter> type;
43 };
44 
45 } // namespace xml
46 } // namespace edash_packager
47 #endif // MPD_BASE_XML_SCOPED_XML_PTR_H_
scoped_ptr for libxml2 resources.