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

Commit b38c9e3

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

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/base/QXmppBitsOfBinaryData.cpp

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

217217
/// \cond
218+
219+
///
220+
/// \brief Finds the data for a uri
221+
/// \param Uri cid uri
222+
/// \return Data belonging to the uri
223+
///
224+
/// \since QXmpp 1.5
225+
///
226+
std::optional<QXmppBitsOfBinaryData> QXmppBitsOfBinaryDataList::find(const QXmppBitsOfBinaryContentId &cid) const
227+
{
228+
const auto thumbnailData = std::find_if(begin(), end(), [&](const auto &bobBlob) {
229+
return bobBlob.cid() == cid;
230+
});
231+
232+
if (thumbnailData != end()) {
233+
return *thumbnailData;
234+
} else {
235+
return {};
236+
}
237+
238+
return *thumbnailData;
239+
}
240+
218241
void QXmppBitsOfBinaryDataList::parse(const QDomElement &element)
219242
{
220243
// 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)