IReadFile::read now returning size_t (like fread in c-lib) instead of s32. Also sizeToRead parameter changed from u32 to size_t.

(corresponding change to IWriteFile::write is planned for next days)


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5333 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2016-09-07 22:01:04 +00:00
parent d3ac819504
commit 1756e4700d
12 changed files with 27 additions and 26 deletions

View File

@ -1,6 +1,7 @@
--------------------------
Changes in 1.9 (not yet released)
- IReadFile::read now returning size_t (like fread in c-lib). Also sizeToRead parameter changed from u32 to size_t.
- add clear function to strings.
- Collision manager now using const camera pointers.
- Several fixes for SceneNodeAnimatorCollisionResponse, based on http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=33098&p=290746

View File

@ -21,7 +21,7 @@ namespace io
/** \param buffer Pointer to buffer where read bytes are written to.
\param sizeToRead Amount of bytes to read from the file.
\return How many bytes were read. */
virtual s32 read(void* buffer, u32 sizeToRead) = 0;
virtual size_t read(void* buffer, size_t sizeToRead) = 0;
//! Changes position in file
/** \param finalPos Destination position in the file.

View File

@ -37,18 +37,18 @@ CLimitReadFile::~CLimitReadFile()
//! returns how much was read
s32 CLimitReadFile::read(void* buffer, u32 sizeToRead)
size_t CLimitReadFile::read(void* buffer, size_t sizeToRead)
{
#if 1
if (0 == File)
return 0;
s32 r = AreaStart + Pos;
s32 toRead = core::s32_min(AreaEnd, r + sizeToRead) - core::s32_max(AreaStart, r);
#if 1
long r = AreaStart + Pos;
long toRead = core::min_(AreaEnd, r + (long)sizeToRead) - core::max_(AreaStart, r);
if (toRead < 0)
return 0;
File->seek(r);
r = File->read(buffer, toRead);
r = (long)File->read(buffer, toRead);
Pos += r;
return r;
#else

View File

@ -30,7 +30,7 @@ namespace io
virtual ~CLimitReadFile();
//! returns how much was read
virtual s32 read(void* buffer, u32 sizeToRead) _IRR_OVERRIDE_;
virtual size_t read(void* buffer, size_t sizeToRead) _IRR_OVERRIDE_;
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,

View File

@ -28,9 +28,9 @@ CMemoryReadFile::~CMemoryReadFile()
//! returns how much was read
s32 CMemoryReadFile::read(void* buffer, u32 sizeToRead)
size_t CMemoryReadFile::read(void* buffer, size_t sizeToRead)
{
s32 amount = static_cast<s32>(sizeToRead);
long amount = static_cast<long>(sizeToRead);
if (Pos + amount > Len)
amount -= Pos + amount - Len;
@ -42,7 +42,7 @@ s32 CMemoryReadFile::read(void* buffer, u32 sizeToRead)
Pos += amount;
return amount;
return static_cast<size_t>(amount);
}
//! changes position in file, returns true if successful

View File

@ -29,7 +29,7 @@ namespace io
virtual ~CMemoryReadFile();
//! returns how much was read
virtual s32 read(void* buffer, u32 sizeToRead) _IRR_OVERRIDE_;
virtual size_t read(void* buffer, size_t sizeToRead) _IRR_OVERRIDE_;
//! changes position in file, returns true if successful
virtual bool seek(long finalPos, bool relativeMovement = false) _IRR_OVERRIDE_;

View File

@ -29,12 +29,12 @@ CReadFile::~CReadFile()
//! returns how much was read
s32 CReadFile::read(void* buffer, u32 sizeToRead)
size_t CReadFile::read(void* buffer, size_t sizeToRead)
{
if (!isOpen())
return 0;
return (s32)fread(buffer, 1, sizeToRead, File);
return fread(buffer, 1, sizeToRead, File);
}

View File

@ -27,7 +27,7 @@ namespace io
virtual ~CReadFile();
//! returns how much was read
virtual s32 read(void* buffer, u32 sizeToRead) _IRR_OVERRIDE_;
virtual size_t read(void* buffer, size_t sizeToRead) _IRR_OVERRIDE_;
//! changes position in file, returns true if successful
virtual bool seek(long finalPos, bool relativeMovement = false) _IRR_OVERRIDE_;

View File

@ -250,15 +250,15 @@ namespace scene
Mesh->MeshBuffers.clear();
const s32 bytesPerPixel = bitsPerPixel / 8;
const size_t bytesPerPixel = (size_t)bitsPerPixel / 8;
// Get the dimension of the heightmap data
const s32 filesize = file->getSize();
const long filesize = file->getSize();
if (!width)
TerrainData.Size = core::floor32(sqrtf((f32)(filesize / bytesPerPixel)));
else
{
if ((filesize-file->getPos())/bytesPerPixel>width*width)
if ((filesize-file->getPos())/bytesPerPixel>(size_t)(width*width))
{
os::Printer::log("Error reading heightmap RAW file", "File is too small.");
return false;

View File

@ -411,7 +411,7 @@ bool CXMeshFileLoader::readFileIntoMemory(io::IReadFile* file)
Buffer = new c8[size];
//! read all into memory
if (file->read(Buffer, size) != size)
if (file->read(Buffer, size) != static_cast<size_t>(size))
{
os::Printer::log("Could not read from x file.", ELL_WARNING);
return false;

View File

@ -75,20 +75,20 @@ long CMemoryReadWriteFile::getSize() const
}
s32 CMemoryReadWriteFile::read(void* buffer, u32 sizeToRead)
size_t CMemoryReadWriteFile::read(void* buffer, size_t sizeToRead)
{
// cant read past the end
if (Pos + sizeToRead >= Data.size())
sizeToRead = Data.size() - Pos;
if ((size_t)Pos + sizeToRead >= Data.size())
sizeToRead = Data.size() - (size_t)Pos;
// cant read 0 bytes
if (!sizeToRead)
return 0;
// copy data
memcpy( buffer, (void*) &Data[Pos], (size_t) sizeToRead);
memcpy( buffer, (void*) &Data[Pos], sizeToRead);
Pos += sizeToRead;
Pos += (long)sizeToRead;
return sizeToRead;
}

View File

@ -16,7 +16,7 @@ namespace irr
namespace io
{
//! Provides write acess to an array as if it is a file.
//! Provides write access to an array as if it is a file.
class CMemoryReadWriteFile : public virtual IWriteFile, public virtual IReadFile
{
public:
@ -25,7 +25,7 @@ namespace io
//! Reads an amount of bytes from the file.
//! \param buffer: Pointer to buffer of bytes to write.
//! \param sizeToWrite: Amount of bytes to wrtie to the file.
//! \param sizeToWrite: Amount of bytes to written to the file.
//! \return Returns how much bytes were written.
virtual s32 write(const void* buffer, u32 sizeToWrite);
@ -45,7 +45,7 @@ namespace io
//! \param buffer: Pointer to buffer where to read bytes will be written to.
//! \param sizeToRead: Amount of bytes to read from the file.
//! \return Returns how much bytes were read.
virtual s32 read(void* buffer, u32 sizeToRead);
virtual size_t read(void* buffer, size_t sizeToRead);
//! Returns the current position in the file.
//! \return Returns the current position in the file in bytes.