mirror of
https://github.com/jaredtao/TaoQuick.git
synced 2025-01-19 20:22:56 +08:00
update 3rdparty
This commit is contained in:
parent
8d63eac60d
commit
5df35700a1
36
3rdparty/TaoCommon/Common/package.h
vendored
Normal file
36
3rdparty/TaoCommon/Common/package.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include <QByteArray>
|
||||
#include <QByteArrayList>
|
||||
#include <QDataStream>
|
||||
|
||||
const int static headerLength = sizeof(quint32);
|
||||
|
||||
static QByteArray pack(const QByteArray &data)
|
||||
{
|
||||
QByteArray header(headerLength, 0);
|
||||
QDataStream os(&header, QIODevice::WriteOnly);
|
||||
os << static_cast<quint32>(data.length());
|
||||
return header + data;
|
||||
}
|
||||
static QByteArrayList unpack(const QByteArray &data)
|
||||
{
|
||||
QByteArrayList list;
|
||||
QDataStream inStream(data);
|
||||
quint32 sum = data.size();
|
||||
quint32 pos = 0;
|
||||
quint32 packageLen = 0;
|
||||
while (pos + headerLength < sum)
|
||||
{
|
||||
packageLen = 0;
|
||||
inStream >> packageLen;
|
||||
if (packageLen <= 0 || packageLen + headerLength > sum - pos)
|
||||
{
|
||||
break;
|
||||
}
|
||||
QByteArray subPackage = data.mid(pos + headerLength, packageLen);
|
||||
inStream.skipRawData(packageLen);
|
||||
list.append(subPackage);
|
||||
pos += headerLength + packageLen;
|
||||
}
|
||||
return list;
|
||||
}
|
42
3rdparty/TaoCommon/Common/singleton.h
vendored
42
3rdparty/TaoCommon/Common/singleton.h
vendored
@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
namespace TaoCommon
|
||||
{
|
||||
//单例模板
|
||||
template <typename T>
|
||||
class Singleton
|
||||
{
|
||||
public:
|
||||
static T &instance()
|
||||
{
|
||||
static T t;
|
||||
return t;
|
||||
}
|
||||
virtual ~Singleton() {}
|
||||
|
||||
Singleton(const Singleton &) = delete;
|
||||
Singleton &operator=(const Singleton &) = delete;
|
||||
|
||||
protected:
|
||||
Singleton() {}
|
||||
};
|
||||
/*
|
||||
使用示例:
|
||||
|
||||
定义:
|
||||
class DataManager : public Singleton<DataManager>
|
||||
{
|
||||
friend class Singleton<DataManager>;
|
||||
public:
|
||||
void loadData();
|
||||
protected:
|
||||
DataManager();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
调用:
|
||||
DataManager::instance().loadData();
|
||||
*/
|
||||
|
||||
} // namespace TaoCommon
|
1
3rdparty/TaoCommon/TaoCommon.pri
vendored
1
3rdparty/TaoCommon/TaoCommon.pri
vendored
@ -12,6 +12,7 @@ HEADERS += \
|
||||
$$PWD/Common/objectmap.h \
|
||||
$$PWD/Common/singleton.h \
|
||||
$$PWD/Common/subject.h \
|
||||
$$PWD/Common/package.h \
|
||||
$$PWD/Logger/loggertemplate.h \
|
||||
$$PWD/Logger/logger.h \
|
||||
$$PWD/Thread/threadcommon.h \
|
||||
|
Loading…
x
Reference in New Issue
Block a user