make EMUFILE not require RTTI

This commit is contained in:
zeromus 2010-09-26 06:45:46 +00:00
parent 436358a51b
commit ec51fa5be0
2 changed files with 23 additions and 17 deletions

View File

@ -12,20 +12,6 @@ bool EMUFILE::readAllBytes(std::vector<u8>* dstbuf, const std::string& fname)
return true;
}
EMUFILE* EMUFILE::memwrap(EMUFILE* fp)
{
EMUFILE_FILE* file;
EMUFILE_MEMORY* mem;
file = dynamic_cast<EMUFILE_FILE*>(fp);
mem = dynamic_cast<EMUFILE_MEMORY*>(fp);
if(mem) return mem;
mem = new EMUFILE_MEMORY(file->size());
if(file->size()==0) return mem;
file->fread(mem->buf(),file->size());
delete file;
return mem;
}
size_t EMUFILE_MEMORY::_fread(const void *ptr, size_t bytes){
u32 remain = len-pos;
u32 todo = std::min<u32>(remain,(u32)bytes);
@ -62,4 +48,20 @@ void EMUFILE_FILE::truncate(s32 length)
fclose(fp);
fp = NULL;
open(fname.c_str(),mode);
}
}
EMUFILE* EMUFILE_FILE::memwrap()
{
EMUFILE_MEMORY* mem = new EMUFILE_MEMORY(size());
if(size()==0) return mem;
fread(mem->buf(),size());
return mem;
}
EMUFILE* EMUFILE_MEMORY::memwrap()
{
return this;
}

View File

@ -43,8 +43,8 @@ public:
{}
//takes control of the provided EMUFILE and returns a new EMUFILE which is guranteed to be in memory
static EMUFILE* memwrap(EMUFILE* fp);
//returns a new EMUFILE which is guranteed to be in memory. the EMUFILE you call this on may be deleted. use the returned EMUFILE in its place
virtual EMUFILE* memwrap() = 0;
virtual ~EMUFILE() {}
@ -116,6 +116,8 @@ public:
if(ownvec) delete vec;
}
virtual EMUFILE* memwrap();
virtual void truncate(s32 length)
{
vec->resize(length);
@ -241,6 +243,8 @@ public:
return fp;
}
virtual EMUFILE* memwrap();
bool is_open() { return fp != NULL; }
virtual void truncate(s32 length);