| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "swinfo.h" |
| 5 | |
| 6 | #include <algorithm> |
| 7 | #include <iterator> |
| 8 | #include <utility> |
| 9 | |
| 10 | std::string SWInfo::info(std::string_view key) const |
| 11 | { |
| 12 | auto const dataIt = info_.find(std::string(key)); |
| 13 | if (dataIt != info_.cend()) |
| 14 | return dataIt->second; |
| 15 | |
| 16 | return std::string{}; |
| 17 | } |
| 18 | |
| 19 | std::vector<std::string> SWInfo::keys() const |
| 20 | { |
| 21 | std::vector<std::string> keys; |
| 22 | keys.reserve(info_.size()); |
| 23 | |
| 24 | auto const keySelector = [](auto const &pair) { return pair.first; }; |
| 25 | std::transform(info_.cbegin(), info_.cend(), std::back_inserter(keys), |
| 26 | keySelector); |
| 27 | |
| 28 | return keys; |
| 29 | } |
| 30 | |
| 31 | void SWInfo::initialize( |
| 32 | std::vector<std::unique_ptr<ISWInfo::IProvider>> const &infoProviders) |
| 33 | { |
| 34 | for (auto const &provider : infoProviders) { |
| 35 | auto infos = provider->provideInfo(); |
| 36 | for (auto &info : infos) |
| 37 | info_.insert(std::move(info)); |
| 38 | } |
| 39 | } |