Commit | Line | Data |
---|---|---|
051356a8 SM |
1 | /* |
2 | * Copyright (C) 2024 EfficiOS Inc. | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #ifndef TESTS_UTILS_XML_UTILS_COMMON_HPP | |
9 | #define TESTS_UTILS_XML_UTILS_COMMON_HPP | |
10 | ||
11 | #include "common/make-unique-wrapper.hpp" | |
12 | ||
13 | #include <libxml/parser.h> | |
14 | #include <memory> | |
15 | ||
f59edc7c JG |
16 | namespace lttng { |
17 | namespace libxml { | |
18 | ||
19 | using parser_ctx_uptr = std::unique_ptr< | |
051356a8 SM |
20 | xmlParserCtxt, |
21 | lttng::memory::create_deleter_class<xmlParserCtxt, xmlFreeParserCtxt>::deleter>; | |
f59edc7c JG |
22 | using doc_uptr = |
23 | std::unique_ptr<xmlDoc, lttng::memory::create_deleter_class<xmlDoc, xmlFreeDoc>::deleter>; | |
24 | ||
25 | /* | |
26 | * Manage the global parser context of libxml2. | |
27 | * There should only be one instance of this class per process. | |
28 | */ | |
29 | class global_parser_context { | |
30 | public: | |
31 | global_parser_context() | |
32 | { | |
33 | xmlInitParser(); | |
34 | } | |
35 | ||
36 | ~global_parser_context() | |
37 | { | |
38 | xmlCleanupParser(); | |
39 | } | |
051356a8 | 40 | |
f59edc7c JG |
41 | /* Deactivate copy and assignment. */ |
42 | global_parser_context(const global_parser_context&) = delete; | |
43 | global_parser_context(global_parser_context&&) = delete; | |
44 | global_parser_context& operator=(const global_parser_context&) = delete; | |
45 | global_parser_context& operator=(global_parser_context&&) = delete; | |
46 | }; | |
47 | } /* namespace libxml */ | |
48 | } /* namespace lttng */ | |
051356a8 | 49 | #endif /* TESTS_UTILS_XML_UTILS_COMMON_HPP */ |