1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "CMemoryFile.h"
14
CMemoryFile::CMemoryFile(void* memory, long len, const io::path& fileName, bool d)
15
: Buffer(memory), Len(len), Pos(0), Filename(fileName), deleteMemoryWhenDropped(d)
18
setDebugName("CMemoryFile");
23
CMemoryFile::~CMemoryFile()
25
if (deleteMemoryWhenDropped)
26
delete [] (c8*)Buffer;
30
//! returns how much was read
31
s32 CMemoryFile::read(void* buffer, u32 sizeToRead)
33
s32 amount = static_cast<s32>(sizeToRead);
34
if (Pos + amount > Len)
35
amount -= Pos + amount - Len;
41
memcpy(buffer, p + Pos, amount);
48
//! returns how much was written
49
s32 CMemoryFile::write(const void* buffer, u32 sizeToWrite)
51
s32 amount = static_cast<s32>(sizeToWrite);
52
if (Pos + amount > Len)
53
amount -= Pos + amount - Len;
59
memcpy(p + Pos, buffer, amount);
68
//! changes position in file, returns true if successful
69
//! if relativeMovement==true, the pos is changed relative to current pos,
70
//! otherwise from begin of file
71
bool CMemoryFile::seek(long finalPos, bool relativeMovement)
75
if (Pos + finalPos > Len)
92
//! returns size of file
93
long CMemoryFile::getSize() const
99
//! returns where in the file we are.
100
long CMemoryFile::getPos() const
106
//! returns name of file
107
const io::path& CMemoryFile::getFileName() const
113
IReadFile* createMemoryReadFile(void* memory, long size, const io::path& fileName, bool deleteMemoryWhenDropped)
115
CMemoryFile* file = new CMemoryFile(memory, size, fileName, deleteMemoryWhenDropped);
120
} // end namespace io
121
} // end namespace irr