Skip to content

Commit

Permalink
Add convinience data retrieval method to QXmppBitsOfBinaryDataList
Browse files Browse the repository at this point in the history
  • Loading branch information
jbruechert committed Sep 28, 2022
1 parent f762f73 commit e101790
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/base/QXmppBitsOfBinaryData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ QXmppBitsOfBinaryDataList::QXmppBitsOfBinaryDataList() = default;
QXmppBitsOfBinaryDataList::~QXmppBitsOfBinaryDataList() = default;

/// \cond

///
/// \brief Finds the data for a uri
/// \return Data belonging to the uri
///
/// \since QXmpp 1.5
///
std::optional<QXmppBitsOfBinaryData> QXmppBitsOfBinaryDataList::find(const QXmppBitsOfBinaryContentId &cid) const
{
const auto thumbnailData = std::find_if(begin(), end(), [&](const auto &bobBlob) {
return bobBlob.cid() == cid;
});

if (thumbnailData != end()) {
return *thumbnailData;
} else {
return {};
}
}

void QXmppBitsOfBinaryDataList::parse(const QDomElement &element)
{
// clear previous data elements
Expand Down
3 changes: 3 additions & 0 deletions src/base/QXmppBitsOfBinaryDataList.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "QXmppBitsOfBinaryData.h"

#include <QVector>
#include <optional>

class QDomElement;
class QXmlStreamWriter;
Expand All @@ -18,6 +19,8 @@ class QXMPP_EXPORT QXmppBitsOfBinaryDataList : public QVector<QXmppBitsOfBinaryD
QXmppBitsOfBinaryDataList();
~QXmppBitsOfBinaryDataList();

std::optional<QXmppBitsOfBinaryData> find(const QXmppBitsOfBinaryContentId &cid) const;

/// \cond
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;
Expand Down

0 comments on commit e101790

Please sign in to comment.