Topic: Whay setstate() not in ios_base?


Author: maciej@maciejsobczak.com (Maciej Sobczak)
Date: Tue, 22 Apr 2003 19:34:24 +0000 (UTC)
Raw View
Hi,

This post considers the IOStreams library.

Consider the following facts:
1. The state flags are defined in ios_base (27.4.2, 27.4.2.1.3).
2. The setstate() method is defined in basic_ios (27.4.4, 27.4.4.3/6).
2a. In effect, there is no way to set the stream state if the only thing
we have is a pointer or reference to ios_base, without the confidence
that it can be safely downcast to basic_ios (*usually* true, but which
instantiation of basic_ios?).
3. The iword and pword (in ios_base) are defined to set badbit if they
cannot allocate the slots (27.4.2.5).

My understanding is: 3. requires that:
- ios_base stores the state,
- ios_base knows how to change the state
I can imagine that implementers provide the setstate() functionality in
ios_base and reuse it in basic_ios.

My question is: why setstate() is not defined to be in ios_base from the
very beginning? Is there any reason for this, other that annoying poor
programmers ;) with problems like 2a?

--
Maciej Sobczak
http://www.maciejsobczak.com/

Distributed programming lib for C, C++, Python & Tcl:
http://www.maciejsobczak.com/prog/yami/

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: bop2@telia.com ("Bo Persson")
Date: Tue, 22 Apr 2003 21:36:46 +0000 (UTC)
Raw View
"Maciej Sobczak" <maciej@maciejsobczak.com> skrev i meddelandet
news:b83u77$dql$1@SunSITE.icm.edu.pl...
> Hi,
>
> This post considers the IOStreams library.
>
> Consider the following facts:
> 1. The state flags are defined in ios_base (27.4.2, 27.4.2.1.3).
> 2. The setstate() method is defined in basic_ios (27.4.4, 27.4.4.3/6).
> 2a. In effect, there is no way to set the stream state if the only thing
> we have is a pointer or reference to ios_base, without the confidence
> that it can be safely downcast to basic_ios (*usually* true, but which
> instantiation of basic_ios?).
> 3. The iword and pword (in ios_base) are defined to set badbit if they
> cannot allocate the slots (27.4.2.5).
>
> My understanding is: 3. requires that:
> - ios_base stores the state,
> - ios_base knows how to change the state
> I can imagine that implementers provide the setstate() functionality in
> ios_base and reuse it in basic_ios.

It is one possibility, but not a requirement. There is a Defect Report

http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#41

saying that ios_base must somehow know if it is part of a basic_ios
structure, and (if so) agree on how to set the flags.


>
> My question is: why setstate() is not defined to be in ios_base from the
> very beginning? Is there any reason for this, other that annoying poor
> programmers ;) with problems like 2a?

Just a guess:

setstate() is defined in terms of clear(), that depends on rdbuf(), whose
return type depends on the templated character type of basic_ios...    :-)


>
> --
> Maciej Sobczak
> http://www.maciejsobczak.com/
>

Bo Persson
bop2@telia.com



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]