| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/profile.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "profile.h"cxx . . $ `<file>/src/core/profile.h`/ |
| 5 | |
| 6 | #include "iprofile.h"cxx . . $ `<file>/src/core/iprofile.h`/ |
| 7 | #include "iprofilepart.h"cxx . . $ `<file>/src/core/iprofilepart.h`/ |
| 8 | #include "iprofilepartprovider.h"cxx . . $ `<file>/src/core/iprofilepartprovider.h`/ |
| 9 | #include "isyscomponent.h"cxx . . $ `<file>/src/core/isyscomponent.h`/ |
| 10 | #include "isyscomponentprofilepart.h"cxx . . $ `<file>/src/core/isyscomponentprofilepart.h`/ |
| 11 | #include "isysmodel.h"cxx . . $ `<file>/src/core/isysmodel.h`/ |
| 12 | #include "item.h"cxx . . $ `<file>/src/core/item.h`/ |
| 13 | #include <algorithm> |
| 14 | #include <iterator> |
| 15 | #include <unordered_map> |
| 16 | #include <utility> |
| 17 | |
| 18 | Profilecxx . . $ Profile#::Factorycxx . . $ Profile#Factory#::Factorycxx . . $ Profile#Factory#Factory(81dab335255d20a5).(IProfilePartProvidercxx . . $ IProfilePartProvider# const &profilePartProvider, |
| 19 | Profilecxx . . $ Profile# &outer) noexcept |
| 20 | : ProfilePartcxx . . $ ProfilePart#::Factorycxx . . $ ProfilePart#Factory#(profilePartProvider) |
| 21 | , outer_cxx . . $ Profile#Factory#outer_.(outer) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | void Profilecxx . . $ Profile#::Factorycxx . . $ Profile#Factory#::takeProfilePartcxx . . $ Profile#Factory#takeProfilePart(8c7717026cb6ec4).(stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> &&part) |
| 26 | { |
| 27 | outer_cxx . . $ Profile#Factory#outer_..parts_cxx . . $ Profile#parts_..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(part)); |
| 28 | } |
| 29 | |
| 30 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 31 | Profilecxx . . $ Profile#::Factorycxx . . $ Profile#Factory#::provideExportercxx . . $ Profile#Factory#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) |
| 32 | { |
| 33 | auto &id = i.IDcxx . . $ Item#ID(f4fff0029955a25f).(); |
| 34 | if (id == ISysModelcxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02).::ItemIDcxx . . $ ISysModel#ItemID.) |
| 35 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).this; |
| 36 | else |
| 37 | return factorycxx . . $ ProfilePart#Factory#factory(f4c9227945a043b8).(id); |
| 38 | } |
| 39 | |
| 40 | class Profilecxx . . $ Profile#::Initializercxx . . $ Profile#Initializer# final : public ISysModelcxx . . $ ISysModel#::Exportercxx . . $ ISysModel#Exporter# |
| 41 | { |
| 42 | public: |
| 43 | Initializercxx . . $ Profile#Initializer#Initializer(7f22761f36b9aa90).(Profilecxx . . $ Profile# const &outer) |
| 44 | : outer_cxx . . $ Profile#Initializer#outer_.(outer) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 49 | provideExportercxx . . $ Profile#Initializer#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) override; |
| 50 | |
| 51 | private: |
| 52 | Profilecxx . . $ Profile# const &outer_cxx . . $ Profile#Initializer#outer_.; |
| 53 | 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 . . $ Profile#Initializer#initializers_.; |
| 54 | }; |
| 55 | |
| 56 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 57 | Profilecxx . . $ Profile#::Initializercxx . . $ Profile#Initializer#::provideExportercxx . . $ Profile#Initializer#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) |
| 58 | { |
| 59 | auto &id = i.IDcxx . . $ Item#ID(f4fff0029955a25f).(); |
| 60 | if (id == ISysModelcxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02).::ItemIDcxx . . $ ISysModel#ItemID.) |
| 61 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).this; |
| 62 | else { |
| 63 | auto &key = dynamic_cast<ISysComponentcxx . . $ ISysComponent# const &>(i).keycxx . . $ ISysComponent#key(f4fff0029955a25f).(); |
| 64 | for (auto &part : outer_cxx . . $ Profile#Initializer#outer_..parts_cxx . . $ Profile#parts_.) { |
| 65 | if (key ==cxx . . $ std/`operator==`(5ea818b58063a774). dynamic_cast<ISysComponentProfilePartcxx . . $ ISysComponentProfilePart# const &>(*cxx . . $ std/__shared_ptr_access#`operator*`(d426bc7b625886b7).part).keycxx . . $ ISysComponentProfilePart#key(f4fff0029955a25f).()) { |
| 66 | if (initializers_cxx . . $ Profile#Initializer#initializers_..countcxx . . $ std/unordered_map#count(b71ff106d381144b).(key) > 0) |
| 67 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).initializers_cxx . . $ Profile#Initializer#initializers_..atcxx . . $ std/unordered_map#at(4f10b6009f0ee734).(key); |
| 68 | else { |
| 69 | auto initializer = part->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).initializercxx . . $ IProfilePart#initializer(6b4e1016740e578).(); |
| 70 | if (initializer != nullptr) { |
| 71 | initializers_cxx . . $ Profile#Initializer#initializers_..emplacecxx . . $ std/unordered_map#emplace(8e800962ae7274b6).(key, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(initializer)); |
| 72 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).initializers_cxx . . $ Profile#Initializer#initializers_..atcxx . . $ std/unordered_map#at(4f10b6009f0ee734).(key); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 82 | } |
| 83 | |
| 84 | Profilecxx . . $ Profile#::Profilecxx . . $ Profile#Profile(ced63f7c635d850d).() noexcept |
| 85 | : id_cxx . . $ Profile#id_.(IProfilecxx . . $ IProfile#::ItemIDcxx . . $ IProfile#ItemID.) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#> Profilecxx . . $ Profile#::initializercxx . . $ Profile#initializer(6b4e1016740e578).() |
| 90 | { |
| 91 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<Profilecxx . . $ Profile#::Initializercxx . . $ Profile#Initializer#>(*this); |
| 92 | } |
| 93 | |
| 94 | bool Profilecxx . . $ Profile#::activecxx . . $ Profile#active(50ce9a9e25b4a850).() const |
| 95 | { |
| 96 | return active_cxx . . $ Profile#active_.; |
| 97 | } |
| 98 | |
| 99 | void Profilecxx . . $ Profile#::activatecxx . . $ Profile#activate(b45ddcbc8423892c).(bool active) |
| 100 | { |
| 101 | active_cxx . . $ Profile#active_. = active; |
| 102 | } |
| 103 | |
| 104 | IProfilecxx . . $ IProfile#::Infocxx . . $ IProfile#Info# const &Profilecxx . . $ Profile#::infocxx . . $ Profile#info(ad075d653bfbbbea).() const |
| 105 | { |
| 106 | return info_cxx . . $ Profile#info_.; |
| 107 | } |
| 108 | |
| 109 | void Profilecxx . . $ Profile#::infocxx . . $ Profile#info(7a3f345cc6258353).(Infocxx . . $ IProfile#Info# const &info) |
| 110 | { |
| 111 | info_cxx . . $ Profile#info_. =cxx . . $ IProfile#Info#`operator=`(2bd26973b47a6d10). info; |
| 112 | } |
| 113 | |
| 114 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilecxx . . $ IProfile#> Profilecxx . . $ Profile#::clonecxx . . $ Profile#clone(f422f8feab2476b6).() const |
| 115 | { |
| 116 | auto clone = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<Profilecxx . . $ Profile#>(); |
| 117 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).active_cxx . . $ Profile#active_. = active_cxx . . $ Profile#active_.; |
| 118 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).info_cxx . . $ Profile#info_. =cxx . . $ IProfile#Info#`operator=`(2bd26973b47a6d10). info_cxx . . $ Profile#info_.; |
| 119 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).parts_cxx . . $ Profile#parts_..reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(parts_cxx . . $ Profile#parts_..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()); |
| 120 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).( |
| 121 | parts_cxx . . $ Profile#parts_..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), parts_cxx . . $ Profile#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).parts_cxx . . $ Profile#parts_.), |
| 122 | [](stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<IProfilePartcxx . . $ IProfilePart#> const &part) { return part->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).clonecxx . . $ IProfilePart#clone(1378fcc1caef3e7b).(); }); |
| 123 | |
| 124 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::movecxx . . $ std/move(e35c19a1ba7baa26).(clone); |
| 125 | } |
| 126 | |
| 127 | stdcxx . . $ std/::stringcxx . . $ std/string# const &Profilecxx . . $ Profile#::IDcxx . . $ Profile#ID(f4fff0029955a25f).() const |
| 128 | { |
| 129 | return id_cxx . . $ Profile#id_.; |
| 130 | } |
| 131 | |
| 132 | void Profilecxx . . $ Profile#::importWithcxx . . $ Profile#importWith(94eddebf9440278).(Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer# &i) |
| 133 | { |
| 134 | auto importer = i.provideImportercxx . . $ Importable#Importer#provideImporter(c13a3bcac0db4745).(*this); |
| 135 | if (importer.has_valuecxx . . $ std/optional#has_value(3482b152b9333168).()) { |
| 136 | auto &profileImporter = dynamic_cast<IProfilecxx . . $ IProfile#::Importercxx . . $ IProfile#Importer# &>(importer->cxx . . $ std/optional#`operator->`(258ee1c9e0a18a5c).getcxx . . $ std/reference_wrapper#get(d426bc7b625886b7).()); |
| 137 | |
| 138 | activatecxx . . $ Profile#activate(b45ddcbc8423892c).(profileImporter.provideActivecxx . . $ IProfile#Importer#provideActive(50ce9a9e25b4a850).()); |
| 139 | infocxx . . $ Profile#info(7a3f345cc6258353).(profileImporter.provideInfocxx . . $ IProfile#Importer#provideInfo(ad075d653bfbbbea).()); |
| 140 | |
| 141 | for (auto &part : parts_cxx . . $ Profile#parts_.) |
| 142 | part->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).importWithcxx . . $ Importable#importWith(94eddebf9440278).(*cxx . . $ std/optional#`operator*`(47e1a15210ec6306).importer); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | void Profilecxx . . $ Profile#::exportWithcxx . . $ Profile#exportWith(5b5c94ff60635419).(Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter# &e) const |
| 147 | { |
| 148 | auto exporter = e.provideExportercxx . . $ Exportable#Exporter#provideExporter(3acccbde2694e33a).(*this); |
| 149 | if (exporter.has_valuecxx . . $ std/optional#has_value(3482b152b9333168).()) { |
| 150 | auto &profileExporter = dynamic_cast<IProfilecxx . . $ IProfile#::Exportercxx . . $ IProfile#Exporter# &>(exporter->cxx . . $ std/optional#`operator->`(258ee1c9e0a18a5c).getcxx . . $ std/reference_wrapper#get(d426bc7b625886b7).()); |
| 151 | |
| 152 | profileExporter.takeActivecxx . . $ IProfile#Exporter#takeActive(b45ddcbc8423892c).(activecxx . . $ Profile#active(50ce9a9e25b4a850).()); |
| 153 | profileExporter.takeInfocxx . . $ IProfile#Exporter#takeInfo(7a3f345cc6258353).(infocxx . . $ Profile#info(ad075d653bfbbbea).()); |
| 154 | |
| 155 | for (auto const &part : parts_cxx . . $ Profile#parts_.) |
| 156 | part->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).exportWithcxx . . $ Exportable#exportWith(5b5c94ff60635419).(*cxx . . $ std/optional#`operator*`(47e1a15210ec6306).exporter); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | stdcxx . . $ std/::stringcxx . . $ std/string# const &Profilecxx . . $ Profile#::namecxx . . $ Profile#name(f4fff0029955a25f).() const |
| 161 | { |
| 162 | return info_cxx . . $ Profile#info_..namecxx . . $ IProfile#Info#name.; |
| 163 | } |
| 164 | |
| 165 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<IProfilePartcxx . . $ IProfilePart#>> const &Profilecxx . . $ Profile#::partscxx . . $ Profile#parts(eb73fac8769a6fd1).() const |
| 166 | { |
| 167 | return parts_cxx . . $ Profile#parts_.; |
| 168 | } |