1 /* 2 SPDX-FileCopyrightText: 2008 Akarsh Simha <akarshsimha@gmail.com> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #pragma once 8 9 #include <QString> 10 #include <QUrl> 11 #include <map> 12 #include <vector> 13 14 namespace SkyObjectUserdata 15 { 16 /** 17 * Stores the tite and URL of a webpage. 18 * 19 * @note As we still have no std::variant support we use an enum. 20 */ 21 struct LinkData 22 { 23 enum class Type 24 { 25 website = 0, 26 image = 1 27 }; 28 29 QString title; 30 QUrl url; 31 Type type; 32 }; 33 34 using Type = LinkData::Type; 35 using LinkList = std::vector<LinkData>; 36 37 /** 38 * Stores Users' Logs, Pictures and Websites regarding an object in 39 * the sky. 40 * 41 * @short Auxiliary information associated with a SkyObject. 42 * @author Akarsh Simha, Valentin Boettcher 43 * @version 2.0 44 */ 45 struct Data 46 { 47 std::map<LinkData::Type, LinkList> links{ { Type::website, {} }, 48 { Type::image, {} } }; 49 QString userLog; 50 imagesData51 inline LinkList &images() { return links.at(Type::image); }; imagesData52 inline const LinkList &images() const { return links.at(Type::image); }; 53 websitesData54 inline LinkList &websites() { return links.at(Type::website); }; websitesData55 inline const LinkList &websites() const { return links.at(Type::website); }; 56 findLinkByTitleData57 auto findLinkByTitle(const QString &title, const Type type) const 58 { 59 return std::find_if(cbegin(links.at(type)), cend(links.at(type)), 60 [&title](const auto &entry) { return entry.title == title; }); 61 }; 62 findLinkByTitleData63 auto findLinkByTitle(const QString &title, const Type type) 64 { 65 return std::find_if(begin(links.at(type)), end(links.at(type)), 66 [&title](const auto &entry) { return entry.title == title; }); 67 }; 68 addLinkData69 void addLink(QString title, QUrl url, Type type) 70 { 71 links[type].push_back(LinkData{ std::move(title), std::move(url), type }); 72 } 73 }; 74 } // namespace SkyObjectUserdata 75