pipeline with iostream

G

Guest

I want to construct these classes derived from istream:
bz2_istream
gz_istream
png_istream
jpeg_istream (etc)

so, if I have a jpeg file I will use:
ifstream >> jpeg_istream >> (void*) raw_image_data;

If I have a bz2 file with a png image inside I will use:
ifstream >> bz2_istream >> png_istream >> (void*) raw_image_data;


Please answer these questions or (better) give me a link with a such example

It is clever to derive from istream, or it is better to create my classes from my own base class (similar to istream)?
My experience in streams is only with files, so, how can I change the data in stream? It will be done in operator>>?


Thank you
 
V

Victor Bazarov

I want to construct these classes derived from istream:
bz2_istream
gz_istream
png_istream
jpeg_istream (etc)

so, if I have a jpeg file I will use:
ifstream >> jpeg_istream >> (void*) raw_image_data;

This is nonsense. Please lose the 'ifstream >>' at the beginning of your
expression. BTW, how do you know how much to allocate in 'raw_image_data'?

My guess is that you need to think a bit more about such things...
If I have a bz2 file with a png image inside I will use:
ifstream >> bz2_istream >> png_istream >> (void*) raw_image_data;

Same note here.
Please answer these questions or (better) give me a link with a such example

www.google.com


It is clever to derive from istream, or it is better to create my classes
from my own base class (similar to istream)?

You could derive from istream. String-based streams and file-based streams
all derive from basic_* streams (and all of them are templates, actually).
My experience in streams is only with files, so, how can I change the data
in stream? It will be done in operator>>?

You don't need to change the data in the stream, you just need to interpret
it differently, for example, skip some irrelevant things...

V
 
E

Evan Carew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chameleon,

Well, I think you have a resonable design there, it just needs some
fleshing out. For instance, when you say:

ifstream >> jpeg_istream >> (void*) raw_image_data;

One assumes you are implying that jpeg_istream is a class which sets the
size of the subsequent read operation. This is perfectly acceptable,
however, I have to ask, why don't you try to let the target object
determine how much to read? For instance:

ifstream_obj >> jpegobj;

I ask, because the read operation is handled by a friend (overloaded
operator) of jpegobj which determines how much to read. If you had some
header info saved in the file, then, this could be read into jpegobj
prior to reading the raw image data to follow.

If you need some code examples, let me know & we can come up with something
I want to construct these classes derived from istream:
bz2_istream
gz_istream
png_istream
jpeg_istream (etc)

so, if I have a jpeg file I will use:
ifstream >> jpeg_istream >> (void*) raw_image_data;

If I have a bz2 file with a png image inside I will use:
ifstream >> bz2_istream >> png_istream >> (void*) raw_image_data;


Please answer these questions or (better) give me a link with a such example

It is clever to derive from istream, or it is better to create my classes from my own base class (similar to istream)?
My experience in streams is only with files, so, how can I change the data in stream? It will be done in operator>>?


Thank you

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFAKTugoo/Prlj9GScRAjVcAJ9RWc8KCMRXgTnCp+Jmgn0BBL7yKwCeIzvJ
LQ+f130zGT+JlfbDYwEijag=
=TjUN
-----END PGP SIGNATURE-----
 
G

Guest

As I told before, I have little knowlenge about streams (I have read "Thinking in C++" fast)

I don't want to "eat" your time but I you have no problem to help me more, can you code this simple code to understand better?

A simpleclass from istream (like jpeg_istream) which takes the input stream (e.g. from an ifstream), and increases every char of
stream by 1 (instead of jpeg decompression).

Thank you VERY MUCH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top