21template <
typename T,
char Prefix>
25 explicit inline constexpr Identifier() =
default;
26 explicit inline constexpr Identifier(T
id) : m_id(id) {}
27 explicit inline Identifier(
QStringView id) : m_id(fromString(id).m_id) {}
28 explicit inline Identifier(
QByteArrayView id) : m_id(fromString(id).m_id) {}
30 [[nodiscard]]
inline constexpr bool isValid()
const
35 [[nodiscard]]
inline constexpr bool operator<(Identifier other)
const
37 return m_id < other.m_id;
39 [[nodiscard]]
inline constexpr bool operator==(Identifier other)
const
41 return m_id == other.m_id;
43 [[nodiscard]]
inline constexpr bool operator!=(Identifier other)
const
45 return m_id != other.m_id;
48 [[nodiscard]]
inline QString toString()
const
57 [[nodiscard]]
static inline Identifier fromString(
QStringView id)
62 return Identifier(
id.mid(1).toULongLong());
64 [[nodiscard]]
static inline Identifier fromString(
QByteArrayView id)
66 if (!
id.startsWith(Prefix)) {
69 return Identifier(
id.mid(1).toULongLong());
74class Q :
public Identifier<uint64_t, 'Q'>
77 explicit inline constexpr Q() =
default;
78 explicit inline constexpr Q(uint64_t
id) : Identifier(
id) {}
83 friend class std::hash<Wikidata::
Q>;
87class
P :
public Identifier<uint32_t, 'P'>
90 enum Property : uint32_t {
97 imageOfInterior = 5775,
103 explicit inline constexpr P() =
default;
104 inline constexpr P(Property
id) : Identifier(
id) {}
105 explicit inline constexpr P(uint32_t
id) : Identifier(
id) {}
109 friend class std::hash<Wikidata::
P>;
120 [[nodiscard]]
inline constexpr bool isValid()
const {
return m_id.isValid(); }
121 [[nodiscard]]
inline constexpr Q id()
const {
return m_id; }
123 template <
typename T>
124 [[nodiscard]]
inline T value(
P property)
const
126 return convertValue<T>(value(property));
129 template <
typename T>
130 [[nodiscard]]
inline std::vector<T> values(
P property)
const
132 const auto vals = values(property);
134 v.reserve(vals.size());
135 std::transform(vals.begin(), vals.end(), std::back_inserter(v), [](
const QVariant &value) { return convertValue<T>(value); });
140 [[nodiscard]] std::vector<QVariant> values(
P property)
const;
141 [[nodiscard]]
QVariant value(
P property)
const;
143 template <
typename T>
144 [[nodiscard]]
static inline T convertValue(
const QVariant &v)
171 [[nodiscard]]
QString name()
const;
172 [[nodiscard]] uint64_t fileSize()
const;
173 [[nodiscard]] uint32_t width()
const;
174 [[nodiscard]] uint32_t height()
const;
175 [[nodiscard]]
QString mimeType()
const;
176 [[nodiscard]]
QString license()
const;
188template <
typename T,
char Prefix>
189inline QDebug operator<<(
QDebug debug, Wikidata::Identifier<T, Prefix>
id)
199struct std::hash<Wikidata::P>
201 std::size_t operator()(
Wikidata::P id)
const noexcept
203 return std::hash<uint64_t>{}(
id.m_id);
207struct std::hash<Wikidata::Q>
209 std::size_t operator()(
Wikidata::Q id)
const noexcept
211 return std::hash<uint64_t>{}(
id.m_id);
Wikidata property identifier.
Wikidata item identifier.
QString toString() const const
QString number(double n, char format, int precision)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.