QGrpcOperation: modernize api with [[nodiscard]]

This improves tooling for return values that shouldn't be ignored.
As a drive-by mark some of those functions as noexcept.

Task-number: QTBUG-123625
Pick-to: 6.7
Change-Id: I92a7aed22208b1e5f073089306da2e04fb143f9b
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Dennis Oberst 2024-03-26 14:08:51 +01:00
parent 4b4785d609
commit fb0136487a
2 changed files with 13 additions and 13 deletions

View File

@ -104,7 +104,7 @@ QGrpcOperation::~QGrpcOperation() = default;
\internal \internal
Getter of the data received from the channel. Getter of the data received from the channel.
*/ */
QByteArray QGrpcOperation::data() const QByteArray QGrpcOperation::data() const noexcept
{ {
return d_func()->data; return d_func()->data;
} }
@ -136,7 +136,7 @@ void QGrpcOperation::read(QProtobufMessage *message) const
Getter of the metadata received from the channel. For the HTTP2 channels it Getter of the metadata received from the channel. For the HTTP2 channels it
usually contains the HTTP headers received from the server. usually contains the HTTP headers received from the server.
*/ */
QGrpcMetadata QGrpcOperation::metadata() const QGrpcMetadata QGrpcOperation::metadata() const noexcept
{ {
return d_func()->channelOperation->serverMetadata(); return d_func()->channelOperation->serverMetadata();
} }
@ -144,7 +144,7 @@ QGrpcMetadata QGrpcOperation::metadata() const
/*! /*!
Getter of the method that this operation was intialized with. Getter of the method that this operation was intialized with.
*/ */
QLatin1StringView QGrpcOperation::method() const QLatin1StringView QGrpcOperation::method() const noexcept
{ {
return d_func()->channelOperation->method(); return d_func()->channelOperation->method();
} }
@ -153,7 +153,7 @@ QLatin1StringView QGrpcOperation::method() const
\internal \internal
Returns a pointer to the assigned channel-side QGrpcChannelOperation. Returns a pointer to the assigned channel-side QGrpcChannelOperation.
*/ */
const QGrpcChannelOperation *QGrpcOperation::channelOperation() const const QGrpcChannelOperation *QGrpcOperation::channelOperation() const noexcept
{ {
return d_func()->channelOperation.get(); return d_func()->channelOperation.get();
} }
@ -162,7 +162,7 @@ const QGrpcChannelOperation *QGrpcOperation::channelOperation() const
\internal \internal
Getter of the serializer that QGrpcOperation was constructed with. Getter of the serializer that QGrpcOperation was constructed with.
*/ */
std::shared_ptr<const QAbstractProtobufSerializer> QGrpcOperation::serializer() const std::shared_ptr<const QAbstractProtobufSerializer> QGrpcOperation::serializer() const noexcept
{ {
return d_func()->channelOperation->serializer(); return d_func()->channelOperation->serializer();
} }
@ -185,7 +185,7 @@ void QGrpcOperation::cancel()
Returns true when QGrpcOperation finished its workflow, Returns true when QGrpcOperation finished its workflow,
meaning it was finished, canceled, or error occurred, otherwise returns false. meaning it was finished, canceled, or error occurred, otherwise returns false.
*/ */
bool QGrpcOperation::isFinished() const bool QGrpcOperation::isFinished() const noexcept
{ {
return d_func()->isFinished.loadRelaxed(); return d_func()->isFinished.loadRelaxed();
} }

View File

@ -36,11 +36,11 @@ public:
void read(QProtobufMessage *message) const; void read(QProtobufMessage *message) const;
QGrpcMetadata metadata() const; [[nodiscard]] QGrpcMetadata metadata() const noexcept;
QLatin1StringView method() const; [[nodiscard]] QLatin1StringView method() const noexcept;
void cancel(); void cancel();
bool isFinished() const; [[nodiscard]] bool isFinished() const noexcept;
Q_SIGNALS: Q_SIGNALS:
void finished(); void finished();
@ -49,14 +49,14 @@ Q_SIGNALS:
protected: protected:
explicit QGrpcOperation(std::shared_ptr<QGrpcChannelOperation> channelOperation); explicit QGrpcOperation(std::shared_ptr<QGrpcChannelOperation> channelOperation);
const QGrpcChannelOperation *channelOperation() const; [[nodiscard]] const QGrpcChannelOperation *channelOperation() const noexcept;
std::shared_ptr<const QAbstractProtobufSerializer> serializer() const; [[nodiscard]] std::shared_ptr<const QAbstractProtobufSerializer> serializer() const noexcept;
private: private:
Q_DISABLE_COPY_MOVE(QGrpcOperation) Q_DISABLE_COPY_MOVE(QGrpcOperation)
QByteArray data() const; [[nodiscard]] QByteArray data() const noexcept;
QGrpcStatus deserializationError() const; [[nodiscard]] QGrpcStatus deserializationError() const;
Q_DECLARE_PRIVATE(QGrpcOperation) Q_DECLARE_PRIVATE(QGrpcOperation)
}; };