Hi,
I'd like advise on passing ownership of an iostream.
The idea is that my factory class/function should open a file,
read enough to detect file type (eg which soundfile format),
then create a Reader object of the appropriate type for the file.
Of course I can call close(), then pass the filename to
the reader constructor and reopen the file there.
But I'd prefer to let the Reader class have an istream (no "f")
- then, if the file is small, the factory could perhaps read it
into a string and pass a stringstream instead of the file handle
(just an example, didn't look at this yet).
So is it safe to let the factory create an ifstream by new,
pass the pointer to reader and dereference it so the Reader
can use an istream& (reference)?
Or would it be better to pass just the streambuf?
- or should I go for reopening (which pretty much rules out
having an istream& in the Reader
Thanks,
Sören