vcglib/apps/nexus/mfile.h

60 lines
1.1 KiB
C
Raw Normal View History

2004-10-21 14:14:02 +02:00
#ifndef NXS_MFILE_H
#define NXS_MFILE_H
#include "file.h"
#include <string>
#include <vector>
namespace nxs {
2004-10-21 15:40:16 +02:00
#ifdef WIN32
typedef __int64 int64;
#else
typedef unsigned long long int64;
#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-10-21 15:40:16 +02:00
int64 Length() { return size; }
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);
bool IsReadOnly() { return readonly; }
protected:
std::string filename;
std::vector<File> files;
unsigned int curr_pos;
unsigned int curr_fp;
2004-10-21 15:40:16 +02: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