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>
{
public:
     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,

Dylan

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 : http://psycho.pl/pub/src/tmpfile.cc
>
> If you say that this is ok, I will write it using boost library and
> also working on win32.
>
>
> Thanks
> Tom
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk