This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
RE: [PATCH] New stream buffer for cin, cout etc.
- From: Pétur Runólfsson <peturr02 at ru dot is>
- To: "Benjamin Kosnik" <bkoz at redhat dot com>
- Cc: <libstdc++ at gcc dot gnu dot org>
- Date: Sun, 11 May 2003 11:55:07 -0000
- Subject: RE: [PATCH] New stream buffer for cin, cout etc.
> >The only thing I'm aware of that is still missing is seeking on the
> >wide streams. It should be possible to implement seekpos and seekoff
> >with off == 0 using fgetpos, fsetpos and fseek, but doing so requires
> >a way to convert between fpos_t and streampos.
>
> Yes, this is a later patch. There needs to be some kind of
> correspondance between C's fpos_t (__c_streampos) and std::fpos<T>.
> Perhaps a member and access operator should be added?
I was thinking of something like this:
template <>
class fpos<mbstate_t>
{
public:
// Non-portable, but probably easy to implement for any given
// platform.
fpos(const fpos_t&);
operator fpos_t() const;
// ...
};
Then seekpos and seekoff are trivial:
pos_type
seekpos(pos_type pos, ios_base::openmode mode)
{
pos_type ret(-1);
fpos_t tmp = pos; // Use fpos<mbstate_t>::operator fpos_t()
if (!fsetpos(_M_file, &tmp) && !fgetpos(_M_file, &tmp))
ret = tmp; // Use fpos<mbstate_t>::fpos(const fpos_t&)
return ret;
}
pos_type
seekoff(off_type off, ios_base::seekdir dir, ios_base::openmode mode)
{
pos_type ret(-1);
fpos_t tmp;
if (!fseek(_M_file, off, dir) && !fgetpos(_M_file, &tmp))
ret = tmp; // Use fpos<mbstate_t>::fpos(const fpos_t&)
return ret;
}
> There
> is already a
> basic_streambuf::_M_pos that was added with this intention, which
> probably should be moved to basic_filebuf.
I agree, it doesn't appear to be needed by strstreambuf or stringbuf,
is not needed by streambuf, and can't be used here, as the user can
change the stream position directly in any number of ways by using
stdio calls on the FILE*.
Petur