Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2003-12-19 15:22:16


How about using a smart pointer-style management system, e.g. (using my
implementation, but adabtable to others like Loki, et. al.):

struct FILEResource
{
   static void Free( FILE * f )
   {
      ::fclose( f );
   }
};

{
   adl::ptr::pointer< FILE *, FILEResource > hFile = ::fopen( "Foo", "w" );
   // ...
   hFile = ::fopen( "Foo2", "w" ); // will close the other file
}

This would then give additional advantages that sm art pointers provide. If
you want to make it easier to supply the resource function, you could
implement a ptr_fun style helper class:

   adl::ptr::pointer< FILE *, resource< ::fclose > > ...;

NOTE: If there is interest in my smart pointer implementation (based on
Loki, CComPointer, and others), let me know and I'll post it to the files
section. (I am not sure how portable the code is, though).

Regards,
Reece H Dunn

_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection
http://www.msn.co.uk/specials/btbroadband


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