2004-10-21 14:14:02 +02:00
|
|
|
#ifndef NXS_MFILE_H
|
|
|
|
#define NXS_MFILE_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2004-11-30 23:50:30 +01:00
|
|
|
#include "file.h"
|
|
|
|
#include "nxstypes.h"
|
|
|
|
|
2004-10-21 14:14:02 +02:00
|
|
|
namespace nxs {
|
|
|
|
|
2004-11-30 23:50:30 +01:00
|
|
|
/*#ifdef WIN32
|
2004-10-21 15:40:16 +02:00
|
|
|
typedef __int64 int64;
|
|
|
|
#else
|
|
|
|
typedef unsigned long long int64;
|
2004-11-30 23:50:30 +01:00
|
|
|
#endif*/
|
2004-10-21 14:14:02 +02:00
|
|
|
|
2004-10-21 17:05:39 +02:00
|
|
|
#define MFILE_MAX_SIZE (1<<30)
|
|
|
|
|
2004-10-21 14:14:02 +02:00
|
|
|
class MFile {
|
|
|
|
public:
|
|
|
|
|
|
|
|
MFile() {}
|
|
|
|
~MFile() { Close(); }
|
|
|
|
|
|
|
|
//max is so default is 1 G
|
|
|
|
bool Create(const std::string &filename,
|
2004-10-21 17:05:39 +02:00
|
|
|
unsigned int max_file_size = MFILE_MAX_SIZE);
|
2004-10-21 14:14:02 +02:00
|
|
|
bool Load(const std::string &filename, bool readonly = false);
|
|
|
|
void Close();
|
2004-11-18 19:30:15 +01:00
|
|
|
void Delete();
|
2004-10-21 14:14:02 +02:00
|
|
|
|
2005-01-14 16:25:29 +01:00
|
|
|
int64 Length() { return _size; }
|
2004-10-21 15:40:16 +02:00
|
|
|
void Redim(int64 size);
|
2004-10-21 14:14:02 +02:00
|
|
|
|
2004-10-21 15:40:16 +02:00
|
|
|
void SetPosition(int64 pos);
|
2004-10-21 14:14:02 +02:00
|
|
|
void ReadBuffer(void *data, unsigned int size);
|
|
|
|
void WriteBuffer(void *data, unsigned int size);
|
|
|
|
|
2005-01-14 16:25:29 +01:00
|
|
|
bool Opened() { return files.size() > 0; }
|
2004-10-21 14:14:02 +02:00
|
|
|
bool IsReadOnly() { return readonly; }
|
2004-12-04 17:14:40 +01:00
|
|
|
void SetReadOnly(bool rd) { readonly = rd; } //USE WITH CARE!!!!
|
2004-10-21 14:14:02 +02:00
|
|
|
protected:
|
|
|
|
std::string filename;
|
2004-11-28 02:23:26 +01:00
|
|
|
std::vector<File *> files;
|
2004-10-21 14:14:02 +02:00
|
|
|
unsigned int curr_pos;
|
|
|
|
unsigned int curr_fp;
|
2005-01-14 16:25:29 +01:00
|
|
|
int64 _size;
|
2004-10-21 14:14:02 +02:00
|
|
|
unsigned int max_size;
|
|
|
|
bool readonly;
|
|
|
|
private:
|
|
|
|
//all theese refer to the last in the fp.
|
2004-10-21 15:40:16 +02:00
|
|
|
bool AddFile();
|
2004-10-21 14:14:02 +02:00
|
|
|
void RemoveFile();
|
|
|
|
void RedimLast(unsigned int sz);
|
|
|
|
unsigned int GetSize();
|
|
|
|
std::string Name(unsigned int n);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|