2019-08-22 20:13:46 +08:00
|
|
|
//
|
|
|
|
// FileLoader.hpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2019/07/04.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
2024-04-19 11:58:21 +08:00
|
|
|
#ifndef MNN_FileLoader_hpp
|
|
|
|
#define MNN_FileLoader_hpp
|
2019-08-22 20:13:46 +08:00
|
|
|
#include <vector>
|
2021-09-18 15:52:30 +08:00
|
|
|
#include <mutex>
|
2019-12-27 22:16:57 +08:00
|
|
|
#include "core/AutoStorage.h"
|
2019-08-22 20:13:46 +08:00
|
|
|
namespace MNN {
|
|
|
|
class MNN_PUBLIC FileLoader {
|
|
|
|
public:
|
2024-04-19 11:58:21 +08:00
|
|
|
FileLoader(const char* file, bool init = false);
|
2019-08-22 20:13:46 +08:00
|
|
|
|
|
|
|
~FileLoader();
|
|
|
|
|
|
|
|
bool read();
|
2021-09-18 15:52:30 +08:00
|
|
|
|
2022-01-04 10:50:40 +08:00
|
|
|
static bool write(const char* filePath, std::pair<const void*, size_t> cacheInfo);
|
2019-08-22 20:13:46 +08:00
|
|
|
|
|
|
|
bool valid() const {
|
|
|
|
return mFile != nullptr;
|
|
|
|
}
|
|
|
|
inline size_t size() const {
|
|
|
|
return mTotalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool merge(AutoStorage<uint8_t>& buffer);
|
|
|
|
|
2022-12-30 15:18:58 +08:00
|
|
|
int offset(int64_t offset);
|
|
|
|
|
|
|
|
bool read(char* buffer, int64_t size);
|
2019-08-22 20:13:46 +08:00
|
|
|
private:
|
2024-04-19 11:58:21 +08:00
|
|
|
void _init();
|
2019-08-22 20:13:46 +08:00
|
|
|
std::vector<std::pair<size_t, void*>> mBlocks;
|
|
|
|
FILE* mFile = nullptr;
|
|
|
|
static const int gCacheSize = 4096;
|
|
|
|
size_t mTotalSize = 0;
|
2024-04-19 11:58:21 +08:00
|
|
|
std::string mFilePath;
|
|
|
|
bool mInited = false;
|
2019-08-22 20:13:46 +08:00
|
|
|
};
|
|
|
|
} // namespace MNN
|
2024-04-19 11:58:21 +08:00
|
|
|
#endif
|