| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2021 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "noopxmlparser.h" |
| 5 | |
| 6 | #include "core/profilepartxmlparserprovider.h" |
| 7 | #include "noop.h" |
| 8 | #include <memory> |
| 9 | |
| 10 | class NoopXMLParser::Initializer final : public NoopProfilePart::Exporter |
| 11 | { |
| 12 | public: |
| 13 | Initializer(NoopXMLParser &outer) noexcept |
| 14 | : outer_(outer) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | std::optional<std::reference_wrapper<Exportable::Exporter>> |
| 19 | provideExporter(Item const &) override |
| 20 | { |
| 21 | return {}; |
| 22 | } |
| 23 | |
| 24 | void takeActive(bool active) override; |
| 25 | |
| 26 | private: |
| 27 | NoopXMLParser &outer_; |
| 28 | }; |
| 29 | |
| 30 | void NoopXMLParser::Initializer::takeActive(bool active) |
| 31 | { |
| 32 | outer_.active_ = outer_.activeDefault_ = active; |
| 33 | } |
| 34 | |
| 35 | NoopXMLParser::NoopXMLParser() noexcept |
| 36 | : ProfilePartXMLParser(Noop::ItemID, *this, *this) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | std::unique_ptr<Exportable::Exporter> |
| 41 | NoopXMLParser::factory(IProfilePartXMLParserProvider const &) |
| 42 | { |
| 43 | return nullptr; |
| 44 | } |
| 45 | |
| 46 | std::unique_ptr<Exportable::Exporter> NoopXMLParser::initializer() |
| 47 | { |
| 48 | return std::make_unique<NoopXMLParser::Initializer>(*this); |
| 49 | } |
| 50 | |
| 51 | std::optional<std::reference_wrapper<Exportable::Exporter>> |
| 52 | NoopXMLParser::provideExporter(Item const &) |
| 53 | { |
| 54 | return {}; |
| 55 | } |
| 56 | |
| 57 | std::optional<std::reference_wrapper<Importable::Importer>> |
| 58 | NoopXMLParser::provideImporter(Item const &) |
| 59 | { |
| 60 | return {}; |
| 61 | } |
| 62 | |
| 63 | void NoopXMLParser::takeActive(bool active) |
| 64 | { |
| 65 | active_ = active; |
| 66 | } |
| 67 | |
| 68 | bool NoopXMLParser::provideActive() const |
| 69 | { |
| 70 | return active_; |
| 71 | } |
| 72 | |
| 73 | void NoopXMLParser::appendTo(pugi::xml_node &parentNode) |
| 74 | { |
| 75 | auto pmFixedNode = parentNode.append_child(ID().c_str()); |
| 76 | pmFixedNode.append_attribute("active") = active_; |
| 77 | } |
| 78 | |
| 79 | void NoopXMLParser::resetAttributes() |
| 80 | { |
| 81 | active_ = activeDefault_; |
| 82 | } |
| 83 | |
| 84 | void NoopXMLParser::loadPartFrom(pugi::xml_node const &parentNode) |
| 85 | { |
| 86 | auto pmFixedNode = parentNode.find_child( |
| 87 | [&](pugi::xml_node const &node) { return node.name() == ID(); }); |
| 88 | |
| 89 | active_ = pmFixedNode.attribute("active").as_bool(activeDefault_); |
| 90 | } |
| 91 | |
| 92 | bool const NoopXMLParser::registered_ = |
| 93 | ProfilePartXMLParserProvider::registerProvider( |
| 94 | Noop::ItemID, []() { return std::make_unique<NoopXMLParser>(); }); |