Boost logo

Boost :

From: Dylan Trotter (trotterdylan_at_[hidden])
Date: 2005-09-09 16:24:11

The more I think about this problem, the more I think it's about stream
buffers instead of the actual streams. In particular, you have a
temp_filebuf class whose lifetime determines the lifetime of the
filesystem object:

template <class Char, class Traits>
class temp_filebuf :
     public std::basic_streambuf<Char, Traits>
     temp_filebuf(std::ios_base::openmode mode);

     /* streambuf impementation */

The private implementation could use the pimpl idiom so that the
strengths of particular platforms can be leveraged instead of using
standard constructs.

The usage would then be:

temp_filebuf buf(std::ios_base::in | std::ios_base::out);
std::iostream io(&buf);
/* use io */

So as long as the temp_filebuf exists, the temporary file can be used by
a stream.

I'd be interested to hear what people think about this solution. Thanks,


Tomek wrote:
> Hi,
> Can you add to boost::filesystem namespace class for temporary files
> which will remove file on object destruction ?
> I prepared same sample code :
> If you say that this is ok, I will write it using boost library and
> also working on win32.
> Thanks
> Tom
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at