home *** CD-ROM | disk | FTP | other *** search
- /*
- File: HandleObjectOwner.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __HANDLEOBJECTOWNER__
- #define __HANDLEOBJECTOWNER__
-
- #ifndef __HANDLEOBJECT__
- #include "HandleObject.h"
- #endif
-
- #pragma push
- #pragma segment HandleObject
-
- /***********************************|****************************************
-
- this is a class which can be instantiated on the stack that owns a
- handle object, that is when the THandleObjectOwner is deleted upon
- exit of its scope the owned handle object is deleted automatically
-
- for example:
-
- void foo ()
- {
- TVirtualFile* file = new TSomeVirtualFile;
- THandleObjectOwner fileOwner ( file );
-
- if ( noErr != file->Write ( "hello" ) )
- return;
-
- if ( noErr != file->Write ( " world" ) )
- return;
-
- // the fileOwner automatically deletes the virtual file
- // upon exit of the Foo () function, thus allowing the
- // programmer to worry less about memory management.
- }
-
- ***********************************|****************************************/
-
- class THandleObjectOwner
- {
- public: THandleObjectOwner ( THandleObject* object );
- ~THandleObjectOwner ();
-
- private: THandleObject* fObject;
- };
-
- /***********************************|****************************************/
-
- #pragma pop
-
- #endif // __HANDLEOBJECTOWNER__
-