Skip to content

Commit

Permalink
brushup code
Browse files Browse the repository at this point in the history
  • Loading branch information
aoym committed Jan 24, 2018
1 parent b0afe7e commit 6f60994
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 135 deletions.
4 changes: 1 addition & 3 deletions src/tabstractwebsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ TAbstractWebSocket::~TAbstractWebSocket()
tSystemWarn("Logic warning [%s:%d]", __FILE__, __LINE__);
}

if (keepAliveTimer) {
delete keepAliveTimer;
}
delete keepAliveTimer;
}


Expand Down
16 changes: 7 additions & 9 deletions src/taccesslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/

TAccessLog::TAccessLog()
: timestamp(), remoteHost(), request(), statusCode(0), responseBytes(0)
{ }


TAccessLog::TAccessLog(const QByteArray &host, const QByteArray &req)
: timestamp(), remoteHost(host), request(req), statusCode(0), responseBytes(0)
: remoteHost(host), request(req)
{ }


Expand Down Expand Up @@ -104,12 +103,12 @@ QByteArray TAccessLog::toByteArray(const QByteArray &layout, const QByteArray &d


TAccessLogger::TAccessLogger()
: accessLog(0)
: accessLog(nullptr)
{ }


TAccessLogger::TAccessLogger(const TAccessLogger &other)
: accessLog(0)
: accessLog(nullptr)
{
if (other.accessLog) {
open();
Expand All @@ -136,8 +135,9 @@ TAccessLogger &TAccessLogger::operator=(const TAccessLogger &other)

void TAccessLogger::open()
{
if (!accessLog)
if (!accessLog) {
accessLog = new TAccessLog();
}
}


Expand All @@ -152,8 +152,6 @@ void TAccessLogger::write()

void TAccessLogger::close()
{
if (accessLog) {
delete accessLog;
accessLog = 0;
}
delete accessLog;
accessLog = nullptr;
}
6 changes: 3 additions & 3 deletions src/taccesslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class T_CORE_EXPORT TAccessLog
QDateTime timestamp;
QByteArray remoteHost;
QByteArray request;
int statusCode;
int responseBytes;
int statusCode {0};
int responseBytes {0};
};


Expand All @@ -41,7 +41,7 @@ class T_CORE_EXPORT TAccessLogger
void setResponseBytes(int bytes) { if (accessLog) accessLog->responseBytes = bytes; }

private:
TAccessLog *accessLog;
TAccessLog *accessLog {nullptr};
};

#endif // TACCESSLOG_H
1 change: 0 additions & 1 deletion src/taccesslogstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


TAccessLogStream::TAccessLogStream(const QString &fileName)
: logger(0)
{
TFileAioLogger *aioLogger = new TFileAioLogger();
aioLogger->setFileName(fileName);
Expand Down
2 changes: 1 addition & 1 deletion src/taccesslogstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class T_CORE_EXPORT TAccessLogStream
void flush();

private:
TLogger *logger;
TLogger *logger {nullptr};

// Disable
TAccessLogStream();
Expand Down
8 changes: 3 additions & 5 deletions src/tappsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <QMutexLocker>
#include <cstdio>

static TAppSettings *appSettings = 0;
static TAppSettings *appSettings = nullptr;


class AttributeMap : public QMap<int, QString>
Expand Down Expand Up @@ -118,10 +118,8 @@ TAppSettings *TAppSettings::instance()

static void cleanup()
{
if (appSettings) {
delete appSettings;
appSettings = 0;
}
delete appSettings;
appSettings = nullptr;
}


Expand Down
6 changes: 2 additions & 4 deletions src/tdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ void Tf::setupAppLoggers()
*/
void Tf::releaseAppLoggers()
{
if (stream) {
delete stream;
stream = 0;
}
delete stream;
stream = nullptr;

for (auto &logger : (const QList<TLogger*>&)loggers) {
delete logger;
Expand Down
4 changes: 1 addition & 3 deletions src/tepoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ void TEpoll::dispatchSendData()

default:
tSystemError("Logic error [%s:%d]", __FILE__, __LINE__);
if (sd->buffer) {
delete sd->buffer;
}
delete sd->buffer;
break;
}

Expand Down
4 changes: 1 addition & 3 deletions src/tfileaiologger_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class TFileAioLoggerData : public QSharedData
void TFileAioLoggerData::clearSyncBuffer()
{
for (auto cb : (const List<struct aiocb*> &)syncBuffer) {
if (cb->aio_buf) {
delete (char *)cb->aio_buf;
}
delete (char *)cb->aio_buf;
delete cb;
}
syncBuffer.clear();
Expand Down
4 changes: 1 addition & 3 deletions src/tfileaiowriter_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class TFileAioWriterData
void TFileAioWriterData::clearSyncBuffer()
{
for (auto ab : (const QList<aiobuf_t *> &)syncBuffer) {
if (ab->aio_buf) {
delete (char *)ab->aio_buf;
}
delete (char *)ab->aio_buf;
delete ab;
}
syncBuffer.clear();
Expand Down
15 changes: 4 additions & 11 deletions src/thttpresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ THttpResponse::THttpResponse(const THttpResponseHeader &header, const QByteArray
*/
THttpResponse::~THttpResponse()
{
if (bodyDevice) {
delete bodyDevice;
}
delete bodyDevice;
}

/*!
Expand All @@ -55,10 +53,7 @@ bool THttpResponse::isBodyNull() const
*/
void THttpResponse::setBody(const QByteArray &body)
{
if (bodyDevice) {
delete bodyDevice;
}

delete bodyDevice;
tmpByteArray = body;
bodyDevice = (tmpByteArray.isNull()) ? nullptr : new QBuffer(&tmpByteArray);
}
Expand All @@ -68,10 +63,8 @@ void THttpResponse::setBody(const QByteArray &body)
*/
void THttpResponse::setBodyFile(const QString &filePath)
{
if (bodyDevice) {
delete bodyDevice;
bodyDevice = nullptr;
}
delete bodyDevice;
bodyDevice = nullptr;

QFile *fp = new QFile(filePath);
if (fp->exists()) {
Expand Down
4 changes: 1 addition & 3 deletions src/tjsmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ TJSModule::TJSModule(QObject *parent)

TJSModule::~TJSModule()
{
if (funcObj) {
delete funcObj;
}
delete funcObj;
delete jsEngine;
}

Expand Down
8 changes: 2 additions & 6 deletions src/tkvsdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ TKvsDatabase TKvsDatabase::addDatabase(const QString &driver, const QString &con
// Removes it if exists
if (dict->contains(connectionName)) {
auto data = dict->take(connectionName);
if (data.driver) {
delete data.driver;
}
delete data.driver;
}

TKvsDatabaseData data;
Expand All @@ -103,9 +101,7 @@ void TKvsDatabase::removeDatabase(const QString &connectionName)
TKvsDatabase db(dict->take(connectionName));

db.close();
if (db.drv) {
delete db.drv;
}
delete db.drv;
}


Expand Down
6 changes: 2 additions & 4 deletions src/tkvsdatabasepool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ Q_GLOBAL_STATIC(KvsTypeHash, kvsTypeHash)

static void cleanup()
{
if (databasePool) {
delete databasePool;
databasePool = 0;
}
delete databasePool;
databasePool = nullptr;
}


Expand Down
11 changes: 3 additions & 8 deletions src/tmongodriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {


TMongoDriver::TMongoDriver()
: mongoClient(nullptr), dbName(), mongoCursor(new TMongoCursor()), lastStatus(nullptr), errorCode(0), errorString()
: mongoCursor(new TMongoCursor())
{
mongoc_init();
}
Expand All @@ -26,10 +26,7 @@ TMongoDriver::~TMongoDriver()
{
close();
delete mongoCursor;

if (lastStatus) {
delete lastStatus;
}
delete lastStatus;
}


Expand Down Expand Up @@ -279,8 +276,6 @@ QVariantMap TMongoDriver::getLastCommandStatus() const

void TMongoDriver::setLastCommandStatus(const void *bson)
{
if (lastStatus) {
delete lastStatus;
}
delete lastStatus;
lastStatus = new TBson((const TBsonObject *)bson);
}
8 changes: 4 additions & 4 deletions src/tmongodriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class T_CORE_EXPORT TMongoDriver : public TKvsDriver
void setLastCommandStatus(const void *bson);

typedef struct _mongoc_client_t mongoc_client_t;
mongoc_client_t *mongoClient;
mongoc_client_t *mongoClient {nullptr};
QString dbName;
TMongoCursor *mongoCursor;
TBson *lastStatus;
int errorCode;
TMongoCursor *mongoCursor {nullptr};
TBson *lastStatus {nullptr};
int errorCode {0};
QString errorString;

T_DISABLE_COPY(TMongoDriver)
Expand Down
6 changes: 2 additions & 4 deletions src/tmultiplexingserver_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ static TMultiplexingServer *multiplexingServer = 0;

static void cleanup()
{
if (multiplexingServer) {
delete multiplexingServer;
multiplexingServer = 0;
}
delete multiplexingServer;
multiplexingServer = nullptr;
}


Expand Down
12 changes: 8 additions & 4 deletions src/tpopmailer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
emails by POP.
*/

TPopMailer::TPopMailer(QObject *parent)
: QObject(parent), socket(new QTcpSocket), popPort(0), apopEnabled(false)
TPopMailer::TPopMailer(QObject *parent) :
QObject(parent),
socket(new QTcpSocket)
{ }


TPopMailer::TPopMailer(const QString &hostName, quint16 port, QObject *parent)
: QObject(parent), socket(new QTcpSocket), popHostName(hostName), popPort(port), apopEnabled(false)
TPopMailer::TPopMailer(const QString &hostName, quint16 port, QObject *parent) :
QObject(parent),
socket(new QTcpSocket),
popHostName(hostName),
popPort(port)
{ }


Expand Down
6 changes: 3 additions & 3 deletions src/tpopmailer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class T_CORE_EXPORT TPopMailer : public QObject
T_DISABLE_COPY(TPopMailer)
T_DISABLE_MOVE(TPopMailer)

QTcpSocket *socket;
QTcpSocket *socket {nullptr};
QString popHostName;
quint16 popPort;
quint16 popPort {0};
QByteArray userName;
QByteArray password;
bool apopEnabled;
bool apopEnabled {false};
};


Expand Down
4 changes: 1 addition & 3 deletions src/tredisdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ TRedisDriver::TRedisDriver()
TRedisDriver::~TRedisDriver()
{
close();
if (client) {
delete client;
}
delete client;
}


Expand Down
2 changes: 1 addition & 1 deletion src/tscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

TScheduler::TScheduler(QObject *parent)
: TDatabaseContextThread(parent), timer(new QTimer()), rollback(false)
: TDatabaseContextThread(parent), timer(new QTimer())
{
moveToThread(Tf::app()->thread());
timer->moveToThread(Tf::app()->thread());
Expand Down
7 changes: 3 additions & 4 deletions src/tsendbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


TSendBuffer::TSendBuffer(const QByteArray &header, const QFileInfo &file, bool autoRemove, const TAccessLogger &logger)
: arrayBuffer(header), bodyFile(0), fileRemove(autoRemove), accesslogger(logger), startPos(0)
: arrayBuffer(header), fileRemove(autoRemove), accesslogger(logger)
{
if (file.exists() && file.isFile()) {
bodyFile = new QFile(file.absoluteFilePath());
Expand All @@ -30,12 +30,11 @@ TSendBuffer::TSendBuffer(const QByteArray &header, const QFileInfo &file, bool a


TSendBuffer::TSendBuffer(const QByteArray &header)
: arrayBuffer(header), bodyFile(0), fileRemove(false), accesslogger(), startPos(0)
: arrayBuffer(header)
{ }


TSendBuffer::TSendBuffer(int statusCode, const QHostAddress &address, const QByteArray &method)
: arrayBuffer(), bodyFile(0), fileRemove(false), accesslogger(), startPos(0)
{
accesslogger.open();
accesslogger.setStatusCode(statusCode);
Expand Down Expand Up @@ -65,7 +64,7 @@ void TSendBuffer::release()
bodyFile->remove();
}
delete bodyFile;
bodyFile = 0;
bodyFile = nullptr;
}
}

Expand Down
Loading

0 comments on commit 6f60994

Please sign in to comment.