Initialize all data members in QNetworkAccessCache::CacheableObject
Address the "A constructor must initialize all data members of the class" warning. The class should accept initial values as argument of a (possibly protected) constructor if it expects them to be set by a derived class. Add an enum Option and a protected constructor that can be called by the derived classes with the enum values. This makes setExpires and setShareable redundant so remove them. Found by an Axivion scan. Pick-to: 6.7 6.5 Task-number: QTBUG-125026 Change-Id: Ia8a2a19469a2c0185b5d2e6b2a0895e897f33f28 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 36aa5fc3fa361ecb6f7bb035c3cace3dd14735e0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b17e92952a
commit
779ff8f333
@ -151,9 +151,9 @@ public:
|
|||||||
QNetworkAccessCachedHttpConnection(quint16 connectionCount, const QString &hostName, quint16 port, bool encrypt, bool isLocalSocket,
|
QNetworkAccessCachedHttpConnection(quint16 connectionCount, const QString &hostName, quint16 port, bool encrypt, bool isLocalSocket,
|
||||||
QHttpNetworkConnection::ConnectionType connectionType)
|
QHttpNetworkConnection::ConnectionType connectionType)
|
||||||
: QHttpNetworkConnection(connectionCount, hostName, port, encrypt, isLocalSocket, /*parent=*/nullptr, connectionType)
|
: QHttpNetworkConnection(connectionCount, hostName, port, encrypt, isLocalSocket, /*parent=*/nullptr, connectionType)
|
||||||
|
,CacheableObject(Option::Expires | Option::Shareable)
|
||||||
{
|
{
|
||||||
setExpires(true);
|
|
||||||
setShareable(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() override
|
virtual void dispose() override
|
||||||
|
@ -22,9 +22,8 @@ class QNetworkAuthenticationCache : private QList<QNetworkAuthenticationCredenti
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QNetworkAuthenticationCache()
|
QNetworkAuthenticationCache()
|
||||||
|
: CacheableObject(Option::Shareable)
|
||||||
{
|
{
|
||||||
setExpires(false);
|
|
||||||
setShareable(true);
|
|
||||||
reserve(1);
|
reserve(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,10 +31,11 @@ struct QNetworkAccessCache::Node
|
|||||||
int useCount = 0;
|
int useCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
QNetworkAccessCache::CacheableObject::CacheableObject()
|
QNetworkAccessCache::CacheableObject::CacheableObject(Options options)
|
||||||
|
: expires(options & Option::Expires),
|
||||||
|
shareable(options & Option::Shareable)
|
||||||
{
|
{
|
||||||
// leave the members uninitialized
|
|
||||||
// they must be initialized by the derived class's constructor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkAccessCache::CacheableObject::~CacheableObject()
|
QNetworkAccessCache::CacheableObject::~CacheableObject()
|
||||||
@ -46,16 +47,6 @@ QNetworkAccessCache::CacheableObject::~CacheableObject()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QNetworkAccessCache::CacheableObject::setExpires(bool enable)
|
|
||||||
{
|
|
||||||
expires = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QNetworkAccessCache::CacheableObject::setShareable(bool enable)
|
|
||||||
{
|
|
||||||
shareable = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkAccessCache::~QNetworkAccessCache()
|
QNetworkAccessCache::~QNetworkAccessCache()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "QtCore/qobject.h"
|
#include "QtCore/qobject.h"
|
||||||
#include "QtCore/qbasictimer.h"
|
#include "QtCore/qbasictimer.h"
|
||||||
#include "QtCore/qbytearray.h"
|
#include "QtCore/qbytearray.h"
|
||||||
|
#include <QtCore/qflags.h>
|
||||||
#include "QtCore/qhash.h"
|
#include "QtCore/qhash.h"
|
||||||
#include "QtCore/qmetatype.h"
|
#include "QtCore/qmetatype.h"
|
||||||
|
|
||||||
@ -36,7 +37,6 @@ class QNetworkAccessCache: public QObject
|
|||||||
public:
|
public:
|
||||||
struct Node;
|
struct Node;
|
||||||
typedef QHash<QByteArray, Node *> NodeHash;
|
typedef QHash<QByteArray, Node *> NodeHash;
|
||||||
|
|
||||||
class CacheableObject
|
class CacheableObject
|
||||||
{
|
{
|
||||||
friend class QNetworkAccessCache;
|
friend class QNetworkAccessCache;
|
||||||
@ -45,14 +45,17 @@ public:
|
|||||||
bool shareable;
|
bool shareable;
|
||||||
qint64 expiryTimeoutSeconds = -1;
|
qint64 expiryTimeoutSeconds = -1;
|
||||||
public:
|
public:
|
||||||
CacheableObject();
|
enum class Option {
|
||||||
|
Expires = 0x01,
|
||||||
|
Shareable = 0x02,
|
||||||
|
};
|
||||||
|
typedef QFlags<Option> Options; // #### QTBUG-127269
|
||||||
|
|
||||||
virtual ~CacheableObject();
|
virtual ~CacheableObject();
|
||||||
virtual void dispose() = 0;
|
virtual void dispose() = 0;
|
||||||
inline QByteArray cacheKey() const { return key; }
|
inline QByteArray cacheKey() const { return key; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setExpires(bool enable);
|
explicit CacheableObject(Options options);
|
||||||
void setShareable(bool enable);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
~QNetworkAccessCache();
|
~QNetworkAccessCache();
|
||||||
@ -85,6 +88,8 @@ private:
|
|||||||
bool emitEntryReady(Node *node, QObject *target, const char *member);
|
bool emitEntryReady(Node *node, QObject *target, const char *member);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkAccessCache::CacheableObject::Options)
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user