Kstars

skyobjectuserdata.h
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
14namespace 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 */
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
34using Type = LinkData::Type;
35using 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 */
45struct Data
46{
47 std::map<LinkData::Type, LinkList> links{ { Type::website, {} },
48 { Type::image, {} } };
49 QString userLog;
50
51 inline LinkList &images() { return links.at(Type::image); };
52 inline const LinkList &images() const { return links.at(Type::image); };
53
54 inline LinkList &websites() { return links.at(Type::website); };
55 inline const LinkList &websites() const { return links.at(Type::website); };
56
57 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
63 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
69 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
Stores Users' Logs, Pictures and Websites regarding an object in the sky.
Stores the tite and URL of a webpage.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:04 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.