basic_streambuf::seekoff what should be returned when ios_base::in | ios_base::out is specified?

StackOverflow https://stackoverflow.com/questions/6800811

  •  22-10-2019
  •  | 
  •  

Pergunta

27.6.3.4.2 Buffer management and positioning

pos_type seekoff(off_type off, ios_base::seekdir way,
    ios_base::openmode which = ios_base::in | ios_base::out);
  • Effects: Alters the stream positions within one or more of the controlled sequences in a way that is defined separately for each class derived from basic_streambuf in this Clause (27.8.2.4, 27.9.1.5).
  • Default behavior: Returns pos_type(off_type(-1)).

So far, so good. The basic_streambuf derivation I'm using can alter its position separately for ios_base::in and/or ios_base::out. But, what do I need to return when both are specified?

If you specify ios_base::in or ios_base::out, we would return new stream position of the specific sequence.

Foi útil?

Solução

It is a bit up to your stream to define what happens. The built in streams differ, in that some can have separate read and write positions (stringstream) while others just have one (fstream).

If the user does a reposition and specify both in and out, perhaps you should move both. If it is a seek with a zero offset to get the current position, it is not unreasonable to fail if the positions differ.

Outras dicas

Following seekoff from 27.8.2.4 it seems that you are expected to fail.

Check the condition table 130, which states that both input and output sequences should be positioned only if

(which & (ios_base::in | ios_base::out)) == (ios_base::in) | ios_base::out))
and way == either ios_base::beg or ios_base::end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top