Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit e101790

Browse files
committed
Add convinience data retrieval method to QXmppBitsOfBinaryDataList
1 parent f762f73 commit e101790

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/base/QXmppBitsOfBinaryData.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,26 @@ QXmppBitsOfBinaryDataList::QXmppBitsOfBinaryDataList() = default;
215215
QXmppBitsOfBinaryDataList::~QXmppBitsOfBinaryDataList() = default;
216216

217217
/// \cond
218+
219+
///
220+
/// \brief Finds the data for a uri
221+
/// \return Data belonging to the uri
222+
///
223+
/// \since QXmpp 1.5
224+
///
225+
std::optional<QXmppBitsOfBinaryData> QXmppBitsOfBinaryDataList::find(const QXmppBitsOfBinaryContentId &cid) const
226+
{
227+
const auto thumbnailData = std::find_if(begin(), end(), [&](const auto &bobBlob) {
228+
return bobBlob.cid() == cid;
229+
});
230+
231+
if (thumbnailData != end()) {
232+
return *thumbnailData;
233+
} else {
234+
return {};
235+
}
236+
}
237+
218238
void QXmppBitsOfBinaryDataList::parse(const QDomElement &element)
219239
{
220240
// clear previous data elements

src/base/QXmppBitsOfBinaryDataList.h

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "QXmppBitsOfBinaryData.h"
99

1010
#include <QVector>
11+
#include <optional>
1112

1213
class QDomElement;
1314
class QXmlStreamWriter;
@@ -18,6 +19,8 @@ class QXMPP_EXPORT QXmppBitsOfBinaryDataList : public QVector<QXmppBitsOfBinaryD
1819
QXmppBitsOfBinaryDataList();
1920
~QXmppBitsOfBinaryDataList();
2021

22+
std::optional<QXmppBitsOfBinaryData> find(const QXmppBitsOfBinaryContentId &cid) const;
23+
2124
/// \cond
2225
void parse(const QDomElement &element);
2326
void toXml(QXmlStreamWriter *writer) const;

0 commit comments

Comments
 (0)