mirror of https://github.com/libAthena/athena.git
* Fix FileReader
This commit is contained in:
parent
0d0da95200
commit
b7c359ea40
|
@ -73,4 +73,11 @@ private:
|
||||||
} // io
|
} // io
|
||||||
} // Athena
|
} // Athena
|
||||||
|
|
||||||
|
#ifndef FILEREADER_BASE
|
||||||
|
#define FILEREADER_BASE \
|
||||||
|
private: \
|
||||||
|
typedef Athena::io::FileReader base;
|
||||||
|
|
||||||
|
#endif // FILEREADER_BASE
|
||||||
|
|
||||||
#endif // FILESTREAM_HPP
|
#endif // FILESTREAM_HPP
|
||||||
|
|
|
@ -69,4 +69,11 @@ private:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} // Athena
|
} // Athena
|
||||||
|
|
||||||
|
#ifndef FILEWRITER_BASE
|
||||||
|
#define FILEWRITER_BASE \
|
||||||
|
private: \
|
||||||
|
typedef Athena::io::FileWriter base;
|
||||||
|
|
||||||
|
#endif // FILEWRITER_BASE
|
||||||
#endif // FILEWRITER_HPP
|
#endif // FILEWRITER_HPP
|
||||||
|
|
|
@ -133,11 +133,7 @@ Uint64 BinaryReader::length() const
|
||||||
void BinaryReader::setData(const Uint8* data, Uint64 length)
|
void BinaryReader::setData(const Uint8* data, Uint64 length)
|
||||||
{
|
{
|
||||||
if (m_data)
|
if (m_data)
|
||||||
#ifdef HW_RVL
|
|
||||||
free(m_data);
|
|
||||||
#else
|
|
||||||
delete[] m_data;
|
delete[] m_data;
|
||||||
#endif
|
|
||||||
|
|
||||||
m_data = (Uint8*)data;
|
m_data = (Uint8*)data;
|
||||||
m_length = length;
|
m_length = length;
|
||||||
|
@ -238,11 +234,7 @@ Uint8* BinaryReader::readUBytes(Int64 length)
|
||||||
THROW_IO_EXCEPTION("Position passed stream bounds");
|
THROW_IO_EXCEPTION("Position passed stream bounds");
|
||||||
|
|
||||||
Uint8* ret;
|
Uint8* ret;
|
||||||
#ifdef HW_RVL
|
|
||||||
ret = (Uint8*)memalign(32, length);
|
|
||||||
#else
|
|
||||||
ret = new Uint8[length];
|
ret = new Uint8[length];
|
||||||
#endif
|
|
||||||
|
|
||||||
memcpy(ret, (const Uint8*)(m_data + m_position), length);
|
memcpy(ret, (const Uint8*)(m_data + m_position), length);
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
|
|
@ -196,8 +196,8 @@ Uint16 FileReader::readUint16()
|
||||||
Uint16 val;
|
Uint16 val;
|
||||||
fread(&val, 1, sizeof(Uint16), m_fileHandle);
|
fread(&val, 1, sizeof(Uint16), m_fileHandle);
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapU16(val);
|
val = utility::swapU16(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -219,8 +219,8 @@ Uint32 FileReader::readUint32()
|
||||||
Uint32 val;
|
Uint32 val;
|
||||||
fread(&val, 1, sizeof(Uint32), m_fileHandle);
|
fread(&val, 1, sizeof(Uint32), m_fileHandle);
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapU64(val);
|
val = utility::swapU32(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -242,8 +242,8 @@ Uint64 FileReader::readUint64()
|
||||||
Uint64 val;
|
Uint64 val;
|
||||||
fread(&val, 1, sizeof(Uint64), m_fileHandle);
|
fread(&val, 1, sizeof(Uint64), m_fileHandle);
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapU64(val);
|
val = utility::swapU64(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -265,8 +265,8 @@ double FileReader::readDouble()
|
||||||
double val;
|
double val;
|
||||||
fread(&val, 1, sizeof(double), m_fileHandle);
|
fread(&val, 1, sizeof(double), m_fileHandle);
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapDouble(val);
|
val = utility::swapDouble(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -280,8 +280,8 @@ float FileReader::readFloat()
|
||||||
float val;
|
float val;
|
||||||
fread(&val, 1, sizeof(float), m_fileHandle);
|
fread(&val, 1, sizeof(float), m_fileHandle);
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapFloat(val);
|
val = utility::swapFloat(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,8 +180,8 @@ void FileWriter::writeUint16(Uint16 val)
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapU16(val);
|
val = utility::swapU16(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(Uint16), m_fileHandle) != sizeof(Uint16))
|
if (fwrite(&val, 1, sizeof(Uint16), m_fileHandle) != sizeof(Uint16))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
|
@ -199,8 +199,8 @@ void FileWriter::writeUint32(Uint32 val)
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapU32(val);
|
val = utility::swapU32(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(Uint32), m_fileHandle) != sizeof(Uint32))
|
if (fwrite(&val, 1, sizeof(Uint32), m_fileHandle) != sizeof(Uint32))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
|
@ -218,8 +218,8 @@ void FileWriter::writeUint64(Uint64 val)
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapU32(val);
|
val = utility::swapU32(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(Uint64), m_fileHandle) != sizeof(Uint64))
|
if (fwrite(&val, 1, sizeof(Uint64), m_fileHandle) != sizeof(Uint64))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
|
@ -237,8 +237,8 @@ void FileWriter::writeDouble(double val)
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapDouble(val);
|
val = utility::swapDouble(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(double), m_fileHandle) != sizeof(double))
|
if (fwrite(&val, 1, sizeof(double), m_fileHandle) != sizeof(double))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
|
@ -251,8 +251,8 @@ void FileWriter::writeFloat(float val)
|
||||||
|
|
||||||
m_bitValid = false;
|
m_bitValid = false;
|
||||||
|
|
||||||
if ((utility::isSystemBigEndian() && !isBigEndian()) || (!utility::isSystemBigEndian() && isBigEndian()))
|
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||||
utility::swapFloat(val);
|
val = utility::swapFloat(val);
|
||||||
|
|
||||||
if (fwrite(&val, 1, sizeof(float), m_fileHandle) != sizeof(float))
|
if (fwrite(&val, 1, sizeof(float), m_fileHandle) != sizeof(float))
|
||||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||||
|
|
Loading…
Reference in New Issue