stdex::idrec reading fixed
This commit is contained in:
parent
32391e55a3
commit
f5a2b04caa
@ -40,16 +40,15 @@ namespace stdex {
|
|||||||
template <class T_SIZE, unsigned int ALIGN>
|
template <class T_SIZE, unsigned int ALIGN>
|
||||||
inline bool ignore(std::istream& stream)
|
inline bool ignore(std::istream& stream)
|
||||||
{
|
{
|
||||||
T_SIZE size;
|
|
||||||
|
|
||||||
// Read record size.
|
// Read record size.
|
||||||
stream.read(&size, sizeof(size));
|
T_SIZE size;
|
||||||
if (stream.fail()) return false;
|
stream.read((char*)&size, sizeof(size));
|
||||||
|
if (!stream.good()) return false;
|
||||||
|
|
||||||
// Skip the record data.
|
// Skip the record data.
|
||||||
size += (T_SIZE)(ALIGN - size) % ALIGN;
|
size += (T_SIZE)(ALIGN - size) % ALIGN;
|
||||||
stream.ignore(size);
|
stream.ignore(size);
|
||||||
if (stream.fail()) return false;
|
if (!stream.good()) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -72,8 +71,8 @@ namespace stdex {
|
|||||||
T_ID _id;
|
T_ID _id;
|
||||||
|
|
||||||
while (end == (std::streamoff)-1 || stream.tellg() < end) {
|
while (end == (std::streamoff)-1 || stream.tellg() < end) {
|
||||||
stream.read(&_id, sizeof(_id));
|
stream.read((char*)&_id, sizeof(_id));
|
||||||
if (stream.fail()) return false;
|
if (!stream.good()) return false;
|
||||||
|
|
||||||
if (_id == id) {
|
if (_id == id) {
|
||||||
// The record was found.
|
// The record was found.
|
||||||
@ -237,13 +236,9 @@ inline std::ostream& operator <<(std::ostream& stream, const stdex::idrec::recor
|
|||||||
{
|
{
|
||||||
// Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
|
// Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
|
||||||
|
|
||||||
if (stream.fail()) return stream;
|
|
||||||
std::streamoff start = r.open(stream);
|
std::streamoff start = r.open(stream);
|
||||||
|
|
||||||
if (stream.fail()) return stream;
|
if (stream.fail()) return stream;
|
||||||
stream << r.data;
|
stream << r.data;
|
||||||
|
|
||||||
if (stream.fail()) return stream;
|
|
||||||
r.close(stream, start);
|
r.close(stream, start);
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
@ -265,15 +260,12 @@ inline std::istream& operator >>(std::istream& stream, stdex::idrec::record<T, T
|
|||||||
|
|
||||||
// Read data size.
|
// Read data size.
|
||||||
T_SIZE size;
|
T_SIZE size;
|
||||||
stream.read(size, sizeof(size));
|
stream.read((char*)&size, sizeof(size));
|
||||||
if (stream.fail()) return stream;
|
if (!stream.good()) return stream;
|
||||||
|
|
||||||
// Read data.
|
// Read data.
|
||||||
std::streamoff start = stream.tellg();
|
std::streamoff start = stream.tellg();
|
||||||
{
|
stream >> r.data; // TODO: operator >> should not read past the record data! Make a size limited stream and read from it instead.
|
||||||
ROmejenaDatoteka _stream(&stream, start, size);
|
|
||||||
_stream >> r.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
size += (T_SIZE)(ALIGN - size) % ALIGN;
|
size += (T_SIZE)(ALIGN - size) % ALIGN;
|
||||||
stream.seekg(start + size);
|
stream.seekg(start + size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user