| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "core/profilepartxmlparser.h" |
| 7 | #include "igpuprofilepart.h" |
| 8 | #include <memory> |
| 9 | #include <optional> |
| 10 | #include <pugixml.hpp> |
| 11 | #include <string> |
| 12 | #include <unordered_map> |
| 13 | |
| 14 | class IProfilePartXMLParserProvider; |
| 15 | |
| 16 | class GPUXMLParser final |
| 17 | : public ProfilePartXMLParser |
| 18 | , public IGPUProfilePart::Exporter |
| 19 | , public IGPUProfilePart::Importer |
| 20 | { |
| 21 | public: |
| 22 | GPUXMLParser() noexcept; |
| 23 | |
| 24 | std::unique_ptr<Exportable::Exporter> factory( |
| 25 | IProfilePartXMLParserProvider const &profilePartParserProvider) override; |
| 26 | std::unique_ptr<Exportable::Exporter> initializer() override; |
| 27 | |
| 28 | std::optional<std::reference_wrapper<Exportable::Exporter>> |
| 29 | provideExporter(Item const &i) override; |
| 30 | std::optional<std::reference_wrapper<Importable::Importer>> |
| 31 | provideImporter(Item const &i) override; |
| 32 | |
| 33 | void takeActive(bool active) override; |
| 34 | bool provideActive() const override; |
| 35 | |
| 36 | void takeIndex(int index) override; |
| 37 | int provideIndex() const override; |
| 38 | |
| 39 | void takeDeviceID(std::string const &deviceID) override; |
| 40 | std::string const &provideDeviceID() const override; |
| 41 | |
| 42 | void takeRevision(std::string const &revision) override; |
| 43 | std::string const &provideRevision() const override; |
| 44 | |
| 45 | void takeUniqueID(std::optional<std::string> uniqueID) override; |
| 46 | std::optional<std::string> provideUniqueID() const override; |
| 47 | |
| 48 | void appendTo(pugi::xml_node &parentNode) override; |
| 49 | |
| 50 | protected: |
| 51 | void resetAttributes() override; |
| 52 | void loadPartFrom(pugi::xml_node const &parentNode) override; |
| 53 | |
| 54 | private: |
| 55 | class Factory; |
| 56 | class Initializer; |
| 57 | |
| 58 | std::unordered_map<std::string, std::unique_ptr<IProfilePartXMLParser>> parsers_; |
| 59 | |
| 60 | bool active_; |
| 61 | bool activeDefault_; |
| 62 | |
| 63 | std::string deviceID_; |
| 64 | std::string deviceIDDefault_; |
| 65 | std::string revision_; |
| 66 | std::string revisionDefault_; |
| 67 | std::optional<std::string> uniqueID_; |
| 68 | std::optional<std::string> uniqueIDDefault_; |
| 69 | int index_; |
| 70 | int indexDefault_; |
| 71 | |
| 72 | static bool const registered_; |
| 73 | }; |