File indexing completed on 2024-04-21 14:46:46
0001 /* 0002 SPDX-FileCopyrightText: 2008 Akarsh Simha <akarshsimha@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QString> 0010 #include <QUrl> 0011 #include <map> 0012 #include <vector> 0013 0014 namespace SkyObjectUserdata 0015 { 0016 /** 0017 * Stores the tite and URL of a webpage. 0018 * 0019 * @note As we still have no std::variant support we use an enum. 0020 */ 0021 struct LinkData 0022 { 0023 enum class Type 0024 { 0025 website = 0, 0026 image = 1 0027 }; 0028 0029 QString title; 0030 QUrl url; 0031 Type type; 0032 }; 0033 0034 using Type = LinkData::Type; 0035 using LinkList = std::vector<LinkData>; 0036 0037 /** 0038 * Stores Users' Logs, Pictures and Websites regarding an object in 0039 * the sky. 0040 * 0041 * @short Auxiliary information associated with a SkyObject. 0042 * @author Akarsh Simha, Valentin Boettcher 0043 * @version 2.0 0044 */ 0045 struct Data 0046 { 0047 std::map<LinkData::Type, LinkList> links{ { Type::website, {} }, 0048 { Type::image, {} } }; 0049 QString userLog; 0050 0051 inline LinkList &images() { return links.at(Type::image); }; 0052 inline const LinkList &images() const { return links.at(Type::image); }; 0053 0054 inline LinkList &websites() { return links.at(Type::website); }; 0055 inline const LinkList &websites() const { return links.at(Type::website); }; 0056 0057 auto findLinkByTitle(const QString &title, const Type type) const 0058 { 0059 return std::find_if(cbegin(links.at(type)), cend(links.at(type)), 0060 [&title](const auto &entry) { return entry.title == title; }); 0061 }; 0062 0063 auto findLinkByTitle(const QString &title, const Type type) 0064 { 0065 return std::find_if(begin(links.at(type)), end(links.at(type)), 0066 [&title](const auto &entry) { return entry.title == title; }); 0067 }; 0068 0069 void addLink(QString title, QUrl url, Type type) 0070 { 0071 links[type].push_back(LinkData{ std::move(title), std::move(url), type }); 0072 } 0073 }; 0074 } // namespace SkyObjectUserdata