Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-01-22 02:15:00

Robert Ramey wrote:

>>Consider standard iostream usage
>> string s;
>> while(getline(is, s)) {
>> }
>>Here, two cases are possible when getline returns false. First is when eof
>>is seen, in which case line is done. Second is when something's really
>>wrong with the stream, in which case badbit is set. For serialization
>> some_object obj;
>> while(ia >> obj) {
>> }
>>there's possibility that data ended half-way though next object. How can I
>>tell if that's the case?
> I don't see the difference in the two cases.

The difference if when you see eof while reading a string, you know you've
got the string. You need to do other checks. But when you get eof reading an
object, things are more complex. If you've got eof right when you've started
reading, it means stream has ended. If you've got eof in the middle of
object, your data is corrupt.

Anyway, it seems that implementing this distinction in serialization lib
will be hard, and I've created a solution that will work for me:

    while(ifs.peek() != -1) {
            ia >> obj;
    if ( || ifs.bad()) {
       throw something;

Here, if I see eof at the beginning, I don't read anything. In all other
cases the error is property reported.

So I no longer think serialization should have extra support for this,
other than throwning on stream problems.

- Volodya

After each i/o operations
> good()
> is checked. If its false, archive::exception::stream_error is thrown. At
> that point the io state is the same can be checked fro badbit, eof or any
> thing else.
> Robert Ramey
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at