Debian Codegraph @

src/core/components/controls/amd/pm/fixed/pmfixedprofilepart.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "pmfixedprofilepart.h"
5
6 #include "core/profilepartprovider.h"
7 #include <algorithm>
8 #include <memory>
9 #include <utility>
10
11 class AMD::PMFixedProfilePart::Initializer final : public AMD::PMFixed::Exporter
12 {
13 public:
14 Initializer(AMD::PMFixedProfilePart &outer) noexcept
15 : outer_(outer)
16 {
17 }
18
19 std::optional<std::reference_wrapper<Exportable::Exporter>>
20 provideExporter(Item const &) override
21 {
22 return {};
23 }
24
25 void takeActive(bool active) override;
26 void takePMFixedMode(std::string const &mode) override;
27 void takePMFixedModes(std::vector<std::string> const &modes) override;
28
29 private:
30 AMD::PMFixedProfilePart &outer_;
31 };
32
33 void AMD::PMFixedProfilePart::Initializer::takeActive(bool active)
34 {
35 outer_.activate(active);
36 }
37
38 void AMD::PMFixedProfilePart::Initializer::takePMFixedMode(std::string const &mode)
39 {
40 outer_.mode_ = mode;
41 }
42
43 void AMD::PMFixedProfilePart::Initializer::takePMFixedModes(
44 std::vector<std::string> const &modes)
45 {
46 outer_.modes_ = modes;
47 }
48
49 AMD::PMFixedProfilePart::PMFixedProfilePart() noexcept
50 : id_(AMD::PMFixed::ItemID)
51 {
52 }
53
54 std::unique_ptr<Exportable::Exporter>
55 AMD::PMFixedProfilePart::factory(IProfilePartProvider const &)
56 {
57 return nullptr;
58 }
59
60 std::unique_ptr<Exportable::Exporter> AMD::PMFixedProfilePart::initializer()
61 {
62 return std::make_unique<AMD::PMFixedProfilePart::Initializer>(*this);
63 }
64
65 std::string const &AMD::PMFixedProfilePart::ID() const
66 {
67 return id_;
68 }
69
70 std::optional<std::reference_wrapper<Importable::Importer>>
71 AMD::PMFixedProfilePart::provideImporter(Item const &)
72 {
73 return {};
74 }
75
76 bool AMD::PMFixedProfilePart::provideActive() const
77 {
78 return active();
79 }
80
81 std::string const &AMD::PMFixedProfilePart::providePMFixedMode() const
82 {
83 return mode_;
84 }
85
86 void AMD::PMFixedProfilePart::importProfilePart(IProfilePart::Importer &i)
87 {
88 auto &pmfImporter = dynamic_cast<AMD::PMFixedProfilePart::Importer &>(i);
89 mode(pmfImporter.providePMFixedMode());
90 }
91
92 void AMD::PMFixedProfilePart::exportProfilePart(IProfilePart::Exporter &e) const
93 {
94 auto &pmfExporter = dynamic_cast<AMD::PMFixedProfilePart::Exporter &>(e);
95 pmfExporter.takePMFixedMode(mode_);
96 }
97
98 std::unique_ptr<IProfilePart> AMD::PMFixedProfilePart::cloneProfilePart() const
99 {
100 auto clone = std::make_unique<AMD::PMFixedProfilePart>();
101 clone->modes_ = modes_;
102 clone->mode_ = mode_;
103
104 return std::move(clone);
105 }
106
107 void AMD::PMFixedProfilePart::mode(std::string const &mode)
108 {
109 auto iter = std::find_if(
110 modes_.cbegin(), modes_.cend(),
111 [&](auto const &availableMode) { return mode == availableMode; });
112 if (iter != modes_.cend())
113 mode_ = mode;
114 }
115
116 bool const AMD::PMFixedProfilePart::registered_ =
117 ProfilePartProvider::registerProvider(AMD::PMFixed::ItemID, []() {
118 return std::make_unique<AMD::PMFixedProfilePart>();
119 });