=?UTF-8?Q?Re=3A_custom_streambuf_implementation=E2=80=8F?=
On Nov 19, 7:51 pm, ma740988 <ma740...@gmail.com> wrote:
On Nov 19, 3:31 am, James Kanze <james.ka...@gmail.com> wrote:
If you already have the data in memory (in an array of
unsigned char), then streambuf is probably not what you're
looking for; streambuf is for sinking and sourcing data,
more than anything else.
Interesting. My question was somewhat vague, nonetheless my
requirement goes beyond unsigned shorts. Part of the
motiviation is the need for a library (outside of Boost - not
able to use that) that's akin to your response at link below.
Having said that I'm assuming a streambuf is (still) a good
way to go.
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/99f...
No, the streambuf is *not* what you're looking for. The
streambuf is for getting bytes into or out of your program.
What you need is a new type of stream (which will probably use
streambuf for synching and sourcing its bytes. The code I
posted in the thread you quote is, in fact, extracted (and
slightly modified) from my xdrstream; the actual function names
would be operator<< and operator>>, with the first argument an
oxdrstream or an ixdrstream. From there, it's pretty
straightforward to modify the standard iostream iterators to
provide xdrstream iterators, so that you can write things like:
std::vector< unsigned short > v(
(ixdrstream_iterator< unsigned short >( mySource )),
(ixdrstream_iterator< unsigned short >()) ) ;
(If the file contains only unsigned short. Otherwise, you might
want to use a filtering streambuf to artificially return end of
file when you reach the end of the unsigned shorts.)
--
James Kanze