Topic: How do I derive from streambuf in standard C++ library?
Author: Kevin Jacobs <jacobs@darwin.EPBI.CWRU.Edu>
Date: 1999/04/28 Raw View
In comp.std.c++ Paul Elliott <pelliott@io.com> wrote:
> I have derived from streambuf before, but that was before
> iostreams was templateized an began using traits.
> Is there any documentation anywhere on how to derive from
> streambuf under the complications of the standard C++ library.
I don't know of any formal documentation, but its trivial to inherit a
streambuf and extend its implementation. It is sometimes non-trivial to have
it work with existing stream types, though. It depends on what you want to
do with the derived streambuf class.
My suggestion is that you read the relevant portions of the C++ standard and
the header files for your particular implementation to see how it is done.
stringstream_buf is a good place to start, since it is a fairly simple
derived streambuf. After all, the standard library is (mostly) implemented
in C++, and thus follows (mostly) the same rules as your code does.
-Kevin
--
-----------> Kevin Jacobs <-----------|-------> (216) 778-8487 <--------
S.A.G.E. Project Technical Coordinator | Department of Epidemiology
& System Administrator | & Biostatistics
Internet E-mail: jacobs@darwin.cwru.edu | Case Western Reserve University
----------------------------------------------------------------------------
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: endh1b@right.now (Marcus Vinicius)
Date: 1999/04/28 Raw View
In article <slrn7i9dv7.1l.pelliott@io.com>, pelliott@io.com wrote:
>I have derived from streambuf before, but that was before
>iostreams was templateized an began using traits.
>
>Is there any documentation anywhere on how to derive from
>streambuf under the complications of the standard C++ library.
What I do is ignore the templates and just do it like it always was done:
derive from streambuf rather than the template version.
John - N8086N
Big brother is watching. Disable cookies in your web browser.
-------------------------------------------
Wise man says "Never use a bank with the initials F. U."
-------------------------------------------
Are you interested in a professional society or
guild for programmers? Want to fight section 1706?
See www.programmersguild.org
Newsgroup: us.issues.occupations.computer-programmers
EMail Address:
_m-i-a-n-o_@_c_o_l_o_s_s_e_u_m_b_u_i_l_d_e_r_s._c_o_m_
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James.Kanze@dresdner-bank.com
Date: 1999/04/29 Raw View
In article <slrn7i9dv7.1l.pelliott@io.com>,
pelliott@io.com wrote:
> I have derived from streambuf before, but that was before
> iostreams was templateized an began using traits.
>
> Is there any documentation anywhere on how to derive from
> streambuf under the complications of the standard C++ library.
If you don't need for your streambuf to be templatized, you can do it
exactly as before. About the only difference is the definition of eof.
Of course, you get a slight bit more for free: the standard guarantees
default versions of the functions overflow and underflow, so if your
streambuf is bidirectional, you don't have to implement the one that
doesn't interest you, and the standard guarantees that the base class
doesn't do anything with regards to memory management, so you don't have
to worry about that either.
My article in the Sept., 1998 C++ Report only treated the classical
streambuf, but the examples that are on the net
(http://www.oma.com/C++Report/Issues/Sep98/Kanze/) include code for both
the classical and the standard versions. You might want to compare the
two.
--
James Kanze mailto: James.Kanze@dresdner-bank.com
Conseils en informatique orientie objet/
Beratung in objekt orientierter Datenverarbeitung
Ziegelh|ttenweg 17a, 60598 Frankfurt, Germany Tel. +49 (069) 63 19 86 27
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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. --- ]
Author: pelliott@io.com (Paul Elliott)
Date: 1999/04/27 Raw View
I have derived from streambuf before, but that was before
iostreams was templateized an began using traits.
Is there any documentation anywhere on how to derive from
streambuf under the complications of the standard C++ library.
------
Paul Elliott Telephone: 1(512)837-9345
pelliott@io.com Address: 11900 Metric Blvd Suite J-181
http://www.io.com/~pelliott/pme/ Austin TX 78758-3117
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]