Debian Codegraph @

xbmc/windowing/WindowSystemFactory.cpp

raw
1 /*
2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "WindowSystemFactory.h"
10
11 #include <algorithm>
12
13 using namespace KODI::WINDOWING;
14
15 std::list<std::pair<std::string, std::function<std::unique_ptr<CWinSystemBase>()>>>
16 CWindowSystemFactory::m_windowSystems;
17
18 std::list<std::string> CWindowSystemFactory::GetWindowSystems()
19 {
20 std::list<std::string> available;
21 for (const auto& windowSystem : m_windowSystems)
22 available.emplace_back(windowSystem.first);
23
24 return available;
25 }
26
27 std::unique_ptr<CWinSystemBase> CWindowSystemFactory::CreateWindowSystem(const std::string& name)
28 {
29 auto windowSystem =
30 std::find_if(m_windowSystems.begin(), m_windowSystems.end(),
31 [&name](auto& windowSystem) { return windowSystem.first == name; });
32 if (windowSystem != m_windowSystems.end())
33 return windowSystem->second();
34
35 return nullptr;
36 }
37
38 void CWindowSystemFactory::RegisterWindowSystem(
39 const std::function<std::unique_ptr<CWinSystemBase>()>& createFunction, const std::string& name)
40 {
41 m_windowSystems.emplace_back(name, createFunction);
42 }