| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/components/controls/controlmodeprofilepart.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "controlmodeprofilepart.h"cxx . . $ `<file>/src/core/components/controls/controlmodeprofilepart.h`/ |
| 5 | |
| 6 | #include "core/item.h"cxx . . $ `<file>/src/core/item.h`/ |
| 7 | #include <algorithm> |
| 8 | #include <iterator> |
| 9 | #include <unordered_map> |
| 10 | #include <utility> |
| 11 | |
| 12 | class ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Factorycxx . . $ ControlModeProfilePart#Factory# final |
| 13 | : public ProfilePartcxx . . $ ProfilePart#::Factorycxx . . $ ProfilePart#Factory# |
| 14 | , public ControlModecxx . . $ ControlMode#::Exportercxx . . $ ControlMode#Exporter# |
| 15 | { |
| 16 | public: |
| 17 | Factorycxx . . $ ControlModeProfilePart#Factory#Factory(1e88fa7a45dfae3e).(IProfilePartProvidercxx . . $ IProfilePartProvider# const &profilePartProvider, |
| 18 | ControlModeProfilePartcxx . . $ ControlModeProfilePart# &outer) noexcept |
| 19 | : ProfilePartcxx . . $ ProfilePart#::Factorycxx . . $ ProfilePart#Factory#(profilePartProvider) |
| 20 | , outer_cxx . . $ ControlModeProfilePart#Factory#outer_.(outer) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | void takeProfilePartcxx . . $ ControlModeProfilePart#Factory#takeProfilePart(8c7717026cb6ec4).(stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> &&part) override; |
| 25 | |
| 26 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 27 | provideExportercxx . . $ ControlModeProfilePart#Factory#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) override; |
| 28 | |
| 29 | void takeActivecxx . . $ ControlModeProfilePart#Factory#takeActive(b45ddcbc8423892c).(bool) override |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | void takeModecxx . . $ ControlModeProfilePart#Factory#takeMode(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &) override |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | void takeModescxx . . $ ControlModeProfilePart#Factory#takeModes(eb4a68411a16b7e7).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> const &) override |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | ControlModeProfilePartcxx . . $ ControlModeProfilePart# &outer_cxx . . $ ControlModeProfilePart#Factory#outer_.; |
| 43 | }; |
| 44 | |
| 45 | void ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Factorycxx . . $ ControlModeProfilePart#Factory#::takeProfilePartcxx . . $ ControlModeProfilePart#Factory#takeProfilePart(8c7717026cb6ec4).( |
| 46 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> &&part) |
| 47 | { |
| 48 | outer_cxx . . $ ControlModeProfilePart#Factory#outer_..parts_cxx . . $ ControlModeProfilePart#parts_..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(part)); |
| 49 | } |
| 50 | |
| 51 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 52 | ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Factorycxx . . $ ControlModeProfilePart#Factory#::provideExportercxx . . $ ControlModeProfilePart#Factory#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) |
| 53 | { |
| 54 | return factorycxx . . $ ProfilePart#Factory#factory(f4c9227945a043b8).(i.IDcxx . . $ Item#ID(f4fff0029955a25f).()); |
| 55 | } |
| 56 | |
| 57 | class ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Initializercxx . . $ ControlModeProfilePart#Initializer# final : public ControlModecxx . . $ ControlMode#::Exportercxx . . $ ControlMode#Exporter# |
| 58 | { |
| 59 | public: |
| 60 | Initializercxx . . $ ControlModeProfilePart#Initializer#Initializer(31a6bfbcdc6d83ab).(ControlModeProfilePartcxx . . $ ControlModeProfilePart# &outer) noexcept |
| 61 | : outer_cxx . . $ ControlModeProfilePart#Initializer#outer_.(outer) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 66 | provideExportercxx . . $ ControlModeProfilePart#Initializer#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) override; |
| 67 | |
| 68 | void takeActivecxx . . $ ControlModeProfilePart#Initializer#takeActive(b45ddcbc8423892c).(bool) override; |
| 69 | void takeModecxx . . $ ControlModeProfilePart#Initializer#takeMode(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &) override; |
| 70 | void takeModescxx . . $ ControlModeProfilePart#Initializer#takeModes(eb4a68411a16b7e7).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> const &) override |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | ControlModeProfilePartcxx . . $ ControlModeProfilePart# &outer_cxx . . $ ControlModeProfilePart#Initializer#outer_.; |
| 76 | stdcxx . . $ std/::unordered_mapcxx . . $ std/unordered_map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> initializers_cxx . . $ ControlModeProfilePart#Initializer#initializers_.; |
| 77 | }; |
| 78 | |
| 79 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 80 | ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Initializercxx . . $ ControlModeProfilePart#Initializer#::provideExportercxx . . $ ControlModeProfilePart#Initializer#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) |
| 81 | { |
| 82 | for (auto &part : outer_cxx . . $ ControlModeProfilePart#Initializer#outer_..parts_cxx . . $ ControlModeProfilePart#parts_.) { |
| 83 | auto &id = part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).IDcxx . . $ Item#ID(f4fff0029955a25f).(); |
| 84 | if (id ==cxx . . $ std/`operator==`(5ea818b58063a774). i.IDcxx . . $ Item#ID(f4fff0029955a25f).()) { |
| 85 | if (initializers_cxx . . $ ControlModeProfilePart#Initializer#initializers_..countcxx . . $ std/unordered_map#count(b71ff106d381144b).(id) > 0) |
| 86 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).initializers_cxx . . $ ControlModeProfilePart#Initializer#initializers_..atcxx . . $ std/unordered_map#at(4f10b6009f0ee734).(id); |
| 87 | else { |
| 88 | auto initializer = part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).initializercxx . . $ IProfilePart#initializer(6b4e1016740e578).(); |
| 89 | if (initializer != nullptr) { |
| 90 | initializers_cxx . . $ ControlModeProfilePart#Initializer#initializers_..emplacecxx . . $ std/unordered_map#emplace(8e800962ae7274b6).(id, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(initializer)); |
| 91 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).initializers_cxx . . $ ControlModeProfilePart#Initializer#initializers_..atcxx . . $ std/unordered_map#at(4f10b6009f0ee734).(id); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 100 | } |
| 101 | |
| 102 | void ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Initializercxx . . $ ControlModeProfilePart#Initializer#::takeActivecxx . . $ ControlModeProfilePart#Initializer#takeActive(b45ddcbc8423892c).(bool active) |
| 103 | { |
| 104 | outer_cxx . . $ ControlModeProfilePart#Initializer#outer_..activatecxx . . $ ProfilePart#activate(b45ddcbc8423892c).(active); |
| 105 | } |
| 106 | |
| 107 | void ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Initializercxx . . $ ControlModeProfilePart#Initializer#::takeModecxx . . $ ControlModeProfilePart#Initializer#takeMode(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &mode) |
| 108 | { |
| 109 | outer_cxx . . $ ControlModeProfilePart#Initializer#outer_..mode_cxx . . $ ControlModeProfilePart#mode_. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). mode; |
| 110 | } |
| 111 | |
| 112 | ControlModeProfilePartcxx . . $ ControlModeProfilePart#::ControlModeProfilePartcxx . . $ ControlModeProfilePart#ControlModeProfilePart(c6e332c41c54746f).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# id) noexcept |
| 113 | : id_cxx . . $ ControlModeProfilePart#id_.(id) |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#> |
| 118 | ControlModeProfilePartcxx . . $ ControlModeProfilePart#::factorycxx . . $ ControlModeProfilePart#factory(af48dc8d4887b70c).(IProfilePartProvidercxx . . $ IProfilePartProvider# const &profilePartProvider) |
| 119 | { |
| 120 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Factorycxx . . $ ControlModeProfilePart#Factory#>(profilePartProvider, |
| 121 | *this); |
| 122 | } |
| 123 | |
| 124 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#> ControlModeProfilePartcxx . . $ ControlModeProfilePart#::initializercxx . . $ ControlModeProfilePart#initializer(6b4e1016740e578).() |
| 125 | { |
| 126 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Initializercxx . . $ ControlModeProfilePart#Initializer#>(*this); |
| 127 | } |
| 128 | |
| 129 | stdcxx . . $ std/::stringcxx . . $ std/string# const &ControlModeProfilePartcxx . . $ ControlModeProfilePart#::IDcxx . . $ ControlModeProfilePart#ID(f4fff0029955a25f).() const |
| 130 | { |
| 131 | return id_cxx . . $ ControlModeProfilePart#id_.; |
| 132 | } |
| 133 | |
| 134 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer#>> |
| 135 | ControlModeProfilePartcxx . . $ ControlModeProfilePart#::provideImportercxx . . $ ControlModeProfilePart#provideImporter(c13a3bcac0db4745).(Itemcxx . . $ Item# const &i) |
| 136 | { |
| 137 | auto &id = i.IDcxx . . $ Item#ID(f4fff0029955a25f).(); |
| 138 | auto partIter = stdcxx . . $ std/::find_ifcxx . . $ std/find_if(f0a0a4f94ee5cb00).( |
| 139 | parts_cxx . . $ ControlModeProfilePart#parts_..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), parts_cxx . . $ ControlModeProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 140 | [&](auto const &part) { return part->ID() == id; }); |
| 141 | |
| 142 | if (partIter != parts_cxx . . $ ControlModeProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) { |
| 143 | auto importer = dynamic_cast<Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer# *>(partIter->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).()); |
| 144 | if (importer != nullptr) |
| 145 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).importer; |
| 146 | } |
| 147 | |
| 148 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 149 | } |
| 150 | |
| 151 | bool ControlModeProfilePartcxx . . $ ControlModeProfilePart#::provideActivecxx . . $ ControlModeProfilePart#provideActive(50ce9a9e25b4a850).() const |
| 152 | { |
| 153 | return activecxx . . $ ProfilePart#active(50ce9a9e25b4a850).(); |
| 154 | } |
| 155 | |
| 156 | stdcxx . . $ std/::stringcxx . . $ std/string# const &ControlModeProfilePartcxx . . $ ControlModeProfilePart#::provideModecxx . . $ ControlModeProfilePart#provideMode(f4fff0029955a25f).() const |
| 157 | { |
| 158 | return mode_cxx . . $ ControlModeProfilePart#mode_.; |
| 159 | } |
| 160 | |
| 161 | void ControlModeProfilePartcxx . . $ ControlModeProfilePart#::importProfilePartcxx . . $ ControlModeProfilePart#importProfilePart(d62b6a6dfe9fe695).(IProfilePartcxx . . $ IProfilePart#::Importercxx . . $ IProfilePart#Importer# &i) |
| 162 | { |
| 163 | auto &pmImporter = dynamic_cast<ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Importercxx . . $ ControlModeProfilePart#Importer# &>(i); |
| 164 | modecxx . . $ ControlModeProfilePart#mode(9c546c94e5fcce4e).(pmImporter.provideModecxx . . $ ControlModeProfilePart#Importer#provideMode(f4fff0029955a25f).()); |
| 165 | |
| 166 | for (auto &part : parts_cxx . . $ ControlModeProfilePart#parts_.) { |
| 167 | part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).importWithcxx . . $ Importable#importWith(94eddebf9440278).(i); |
| 168 | |
| 169 | // only the selected mode profile part can be active |
| 170 | part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).activatecxx . . $ IProfilePart#activate(b45ddcbc8423892c).(part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).IDcxx . . $ Item#ID(f4fff0029955a25f).() ==cxx . . $ std/`operator==`(5ea818b58063a774). mode_cxx . . $ ControlModeProfilePart#mode_.); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void ControlModeProfilePartcxx . . $ ControlModeProfilePart#::exportProfilePartcxx . . $ ControlModeProfilePart#exportProfilePart(702e13e8794d0da4).(IProfilePartcxx . . $ IProfilePart#::Exportercxx . . $ IProfilePart#Exporter# &e) const |
| 175 | { |
| 176 | auto &pmExporter = dynamic_cast<ControlModeProfilePartcxx . . $ ControlModeProfilePart#::Exportercxx . . $ ControlModeProfilePart#Exporter# &>(e); |
| 177 | pmExporter.takeModecxx . . $ ControlModeProfilePart#Exporter#takeMode(9c546c94e5fcce4e).(mode_cxx . . $ ControlModeProfilePart#mode_.); |
| 178 | |
| 179 | for (auto const &part : parts_cxx . . $ ControlModeProfilePart#parts_.) |
| 180 | part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).exportWithcxx . . $ Exportable#exportWith(5b5c94ff60635419).(e); |
| 181 | } |
| 182 | |
| 183 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> ControlModeProfilePartcxx . . $ ControlModeProfilePart#::cloneProfilePartcxx . . $ ControlModeProfilePart#cloneProfilePart(1378fcc1caef3e7b).() const |
| 184 | { |
| 185 | auto clone = instancecxx . . $ ControlModeProfilePart#instance(ca12253372a842fa).(); |
| 186 | |
| 187 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).parts_cxx . . $ ControlModeProfilePart#parts_..reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(parts_cxx . . $ ControlModeProfilePart#parts_..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()); |
| 188 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).( |
| 189 | parts_cxx . . $ ControlModeProfilePart#parts_..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), parts_cxx . . $ ControlModeProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).parts_cxx . . $ ControlModeProfilePart#parts_.), |
| 190 | [](stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> const &part) { return part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).clonecxx . . $ IProfilePart#clone(1378fcc1caef3e7b).(); }); |
| 191 | |
| 192 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).mode_cxx . . $ ControlModeProfilePart#mode_. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). mode_cxx . . $ ControlModeProfilePart#mode_.; |
| 193 | |
| 194 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::movecxx . . $ std/move(e35c19a1ba7baa26).(clone); |
| 195 | } |
| 196 | |
| 197 | void ControlModeProfilePartcxx . . $ ControlModeProfilePart#::modecxx . . $ ControlModeProfilePart#mode(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &mode) |
| 198 | { |
| 199 | auto iter = stdcxx . . $ std/::find_ifcxx . . $ std/find_if(f0a0a4f94ee5cb00).(parts_cxx . . $ ControlModeProfilePart#parts_..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), parts_cxx . . $ ControlModeProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 200 | [&](auto const &part) { return mode == part->ID(); }); |
| 201 | if (iter != parts_cxx . . $ ControlModeProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) |
| 202 | mode_cxx . . $ ControlModeProfilePart#mode_. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). mode; |
| 203 | } |