|
| 1 | +/* |
| 2 | +Copyright (C) 2012 Sebastian Herbord. All rights reserved. |
| 3 | +
|
| 4 | +This file is part of Mod Organizer. |
| 5 | +
|
| 6 | +Mod Organizer is free software: you can redistribute it and/or modify |
| 7 | +it under the terms of the GNU General Public License as published by |
| 8 | +the Free Software Foundation, either version 3 of the License, or |
| 9 | +(at your option) any later version. |
| 10 | +
|
| 11 | +Mod Organizer is distributed in the hope that it will be useful, |
| 12 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +GNU General Public License for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU General Public License |
| 17 | +along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include "executableslistproxy.h" |
| 21 | + |
| 22 | +#include "executableslist.h" |
| 23 | + |
| 24 | +#include <generator> |
| 25 | +#include <stdexcept> |
| 26 | + |
| 27 | +#include <QFileInfo> |
| 28 | +#include <QString> |
| 29 | + |
| 30 | +ExecutablesListProxy::ExecutablesListProxy(ExecutablesList* executablesList) |
| 31 | + : m_Proxied(executablesList) |
| 32 | +{} |
| 33 | + |
| 34 | +std::generator<const MOBase::IExecutable&> ExecutablesListProxy::executables() const |
| 35 | +{ |
| 36 | + for (const auto& exe : *m_Proxied) { |
| 37 | + co_yield exe; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +const MOBase::IExecutable* ExecutablesListProxy::getByTitle(const QString& title) const |
| 42 | +{ |
| 43 | + try { |
| 44 | + return &m_Proxied->get(title); |
| 45 | + } catch (const std::runtime_error&) { |
| 46 | + return nullptr; |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +const MOBase::IExecutable* |
| 51 | +ExecutablesListProxy::getByBinary(const QFileInfo& info) const |
| 52 | +{ |
| 53 | + try { |
| 54 | + return &m_Proxied->getByBinary(info); |
| 55 | + } catch (const std::runtime_error&) { |
| 56 | + return nullptr; |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +bool ExecutablesListProxy::contains(const QString& title) const |
| 61 | +{ |
| 62 | + return m_Proxied->titleExists(title); |
| 63 | +} |
0 commit comments