This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Q] Problem with derived from streambuf class
- From: zaufi at sendmail dot ru
- To: libstdc++ at gcc dot gnu dot org
- Date: Sat, 16 Oct 2004 21:26:26 +0400
- Subject: [Q] Problem with derived from streambuf class
hi list
For my project recently I develop two classes for streammed output to syslog.
First is a syslogbuf which is derived from std::streambuf. It uses THREAD
SPECIFIC std::string to hold string to be output to syslog. This class have
redefined xsputn() function to append content to buffer.
Second class is a syslog_stream class (derived from ostream). It have
syslogbuf as datamember and calls ostream constructor with pointer to it.
The problem raise when user (me :) output std::endl manipulator. Ex.:
syslog_stream sout("ident");
sout << "This will be printed" << std::endl;
s.out << "This will not appear...\n";
As I investigate call sequence look like th following:
1) std::endl uses ostream::put('\n')
2) ostream::put() gets pointer to streambuf (which is set by ostreams'
constructor to syslogbuf data member of syslog_stream)
3) ostream::put() calls NON VIRTUAL function base_streambuf::sputc() !! -- so
there is no way to redefine it in derived classes... :(((
4) streambuf::sputc() set my syslogbuf in error state (after check pptr() for
0) 'bcouse my class do not use pointers inherited from base_streambuf (they
are not thread safe)
It looks like base_streambuf forces all derived classes to use buffer
management from base_streambuf and there is no way (or I still can't see it)
to avoid this behavior (i.e. I can't add (use) smth different than pointers
(strings for example))...
I want to ask gurus/developers of libstdc++: Is this normal and I miss
something important??
I'm in doubt...
regards