| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "exportable.h" |
| 7 | #include "importable.h" |
| 8 | #include "iprofilepartxmlparser.h" |
| 9 | #include <functional> |
| 10 | #include <memory> |
| 11 | #include <optional> |
| 12 | #include <pugixml.hpp> |
| 13 | #include <string> |
| 14 | #include <string_view> |
| 15 | #include <vector> |
| 16 | |
| 17 | class Item; |
| 18 | class IProfilePartXMLParserProvider; |
| 19 | |
| 20 | class ProfilePartXMLParser : public IProfilePartXMLParser |
| 21 | { |
| 22 | public: |
| 23 | ProfilePartXMLParser(std::string_view id, |
| 24 | Importable::Importer &profilePartImporter, |
| 25 | Exportable::Exporter &profilePartExporter) noexcept; |
| 26 | |
| 27 | std::string const &ID() const final override; |
| 28 | |
| 29 | void loadFrom(pugi::xml_node const &parentNode) final override; |
| 30 | Importable::Importer &profilePartImporter() const final override; |
| 31 | Exportable::Exporter &profilePartExporter() const final override; |
| 32 | |
| 33 | class Factory |
| 34 | { |
| 35 | public: |
| 36 | Factory(IProfilePartXMLParserProvider const &profilePartParserProvider) noexcept; |
| 37 | |
| 38 | std::optional<std::reference_wrapper<Exportable::Exporter>> |
| 39 | factory(Item const &i); |
| 40 | |
| 41 | virtual void takePartParser(Item const &i, |
| 42 | std::unique_ptr<IProfilePartXMLParser> &&part) = 0; |
| 43 | virtual ~Factory() = default; |
| 44 | |
| 45 | private: |
| 46 | std::unique_ptr<IProfilePartXMLParser> |
| 47 | createPartParser(std::string const &componentID) const; |
| 48 | |
| 49 | IProfilePartXMLParserProvider const &profilePartParserProvider_; |
| 50 | std::vector<std::unique_ptr<Exportable::Exporter>> factories_; |
| 51 | }; |
| 52 | |
| 53 | protected: |
| 54 | virtual void resetAttributes() = 0; |
| 55 | virtual void loadPartFrom(pugi::xml_node const &parentNode) = 0; |
| 56 | |
| 57 | private: |
| 58 | std::string const id_; |
| 59 | Importable::Importer &importer_; |
| 60 | Exportable::Exporter &exporter_; |
| 61 | }; |