2018-04-15 02:36:23 +00:00
|
|
|
#pragma once
|
|
|
|
#include <fnd/IFile.h>
|
|
|
|
#include <string>
|
2018-05-25 14:54:30 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
2018-04-15 02:36:23 +00:00
|
|
|
#include <cstdio>
|
2018-05-25 14:54:30 +00:00
|
|
|
#endif
|
2018-04-15 02:36:23 +00:00
|
|
|
|
|
|
|
namespace fnd
|
|
|
|
{
|
|
|
|
class SimpleFile : public IFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum OpenMode
|
|
|
|
{
|
|
|
|
Read,
|
|
|
|
Edit,
|
|
|
|
Create
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleFile();
|
2018-06-03 08:47:28 +00:00
|
|
|
SimpleFile(const std::string& path, OpenMode mode);
|
2018-04-15 02:36:23 +00:00
|
|
|
~SimpleFile();
|
|
|
|
|
|
|
|
void open(const std::string& path, OpenMode mode);
|
|
|
|
bool isOpen() const;
|
|
|
|
void close();
|
|
|
|
size_t size();
|
|
|
|
void seek(size_t offset);
|
|
|
|
size_t pos();
|
2018-04-15 06:01:24 +00:00
|
|
|
void read(byte_t* out, size_t len);
|
2018-04-15 02:36:23 +00:00
|
|
|
void read(byte_t* out, size_t offset, size_t len);
|
2018-04-15 06:01:24 +00:00
|
|
|
void write(const byte_t* out, size_t len);
|
2018-04-15 02:36:23 +00:00
|
|
|
void write(const byte_t* out, size_t offset, size_t len);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string kModuleName = "SimpleFile";
|
|
|
|
|
|
|
|
bool mOpen;
|
|
|
|
OpenMode mMode;
|
|
|
|
|
2018-05-25 14:54:30 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE mFileHandle;
|
|
|
|
DWORD getOpenModeFlag(OpenMode mode) const;
|
|
|
|
DWORD getShareModeFlag(OpenMode mode) const;
|
|
|
|
DWORD getCreationModeFlag(OpenMode mode) const;
|
|
|
|
#else
|
|
|
|
FILE* mFp;
|
|
|
|
const char* getOpenModeStr(OpenMode mode);
|
|
|
|
#endif
|
2018-04-15 02:36:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|