Add binary caches for import

master
huxingyi 2020-03-25 07:54:29 +09:30
parent 7913229e47
commit bfcf9af037
3 changed files with 73 additions and 0 deletions

View File

@ -508,6 +508,9 @@ HEADERS += src/simulateclothmeshes.h
SOURCES += src/ddsfile.cpp
HEADERS += src/ddsfile.h
SOURCES += src/fileforever.cpp
HEADERS += src/fileforever.h
SOURCES += src/main.cpp
HEADERS += src/version.h

54
src/fileforever.cpp Normal file
View File

@ -0,0 +1,54 @@
#include <map>
#include <QMutex>
#include <QMutexLocker>
#include <QtCore/qbuffer.h>
#include <QFile>
#include "fileforever.h"
struct FileForeverItem
{
QString name;
QUuid id;
QByteArray *byteArray;
};
static std::map<QUuid, FileForeverItem> g_foreverMap;
static QMutex g_mapMutex;
const QString *FileForever::getName(const QUuid &id)
{
QMutexLocker locker(&g_mapMutex);
auto findResult = g_foreverMap.find(id);
if (findResult == g_foreverMap.end())
return nullptr;
return &findResult->second.name;
}
const QByteArray *FileForever::getContent(const QUuid &id)
{
QMutexLocker locker(&g_mapMutex);
auto findResult = g_foreverMap.find(id);
if (findResult == g_foreverMap.end())
return nullptr;
return findResult->second.byteArray;
}
QUuid FileForever::add(const QString &name, const QByteArray &content, QUuid toId)
{
QMutexLocker locker(&g_mapMutex);
QUuid newId = toId.isNull() ? QUuid::createUuid() : toId;
if (g_foreverMap.find(newId) != g_foreverMap.end())
return newId;
QByteArray *byteArray = new QByteArray(content);
g_foreverMap[newId] = {name, newId, byteArray};
return newId;
}
void FileForever::remove(const QUuid &id)
{
QMutexLocker locker(&g_mapMutex);
auto findFile = g_foreverMap.find(id);
if (findFile == g_foreverMap.end())
return;
delete findFile->second.byteArray;
g_foreverMap.erase(id);
}

16
src/fileforever.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef DUST3D_FILE_FOREVER_H
#define DUST3D_FILE_FOREVER_H
#include <QUuid>
#include <QByteArray>
#include <QString>
class FileForever
{
public:
static const QString *getName(const QUuid &id);
static const QByteArray *getContent(const QUuid &id);
static QUuid add(const QString &name, const QByteArray &content, QUuid toId=QUuid());
static void remove(const QUuid &id);
};
#endif