Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / plugins / plugin_xml_parser.h
1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMMON_PLUGINS_PLUGIN_XML_PARSER_H_
6 #define COMMON_PLUGINS_PLUGIN_XML_PARSER_H_
7
8 #include <libxml2/libxml/xmlreader.h>
9
10 #include <filesystem>
11 #include <string>
12 #include <vector>
13 #include <set>
14
15 namespace common_installer {
16
17 /** this class parse xml file*/
18 class PluginsXmlParser {
19  public:
20   explicit PluginsXmlParser(const std::filesystem::path& path)
21       : path_(path), doc_ptr_(nullptr) {}
22   ~PluginsXmlParser();
23   bool Parse();
24   const std::vector<std::string>& tags_list();
25   xmlDocPtr doc_ptr();
26
27  private:
28   const std::filesystem::path path_;
29   xmlDocPtr doc_ptr_;
30   std::vector<std::string> tags_;
31   int NextChildElement(xmlTextReaderPtr reader, int depth);
32
33   class WrapperXMLReader {
34    public:
35     WrapperXMLReader() : reader_(nullptr) {}
36
37     xmlTextReaderPtr Create(const xmlDocPtr doc_ptr_) {
38       reader_ = xmlReaderWalker(doc_ptr_);
39       return reader_;
40     }
41     virtual ~WrapperXMLReader() {
42       if (reader_) {
43         xmlFreeTextReader(reader_);
44       }
45     }
46
47    private:
48     xmlTextReaderPtr reader_;
49   };
50 };
51
52 }  // namespace common_installer
53 #endif  // COMMON_PLUGINS_PLUGIN_XML_PARSER_H_