With.m
author Jens Alfke <jens@mooseyard.com>
Tue Apr 15 18:02:40 2008 -0700 (2008-04-15)
changeset 5 c9f2e0c7359a
child 11 e5976864dfe9
permissions -rw-r--r--
Added some set utils.
     1 //
     2 //  With.m
     3 //  MYUtilities
     4 //
     5 //  Copyright 2008 Jens Alfke. All rights reserved.
     6 //
     7 
     8 #import "With.h"
     9 #import "Logging.h"
    10 
    11 
    12 @interface NSObject (With)
    13 - (BOOL) endWith: (NSException*)x;
    14 @end
    15 
    16 
    17 void _catchWith( id with, NSException *x )
    18 {
    19     Warn(@"Exception thrown from WITH(%@) block: %@",[with class],x);
    20     if( [with respondsToSelector: @selector(endWith:)] ) {
    21         if( ! [with endWith: x] )
    22             @throw x;                           // propagate the exception if -endWith: returns NO
    23     } else {
    24         [with endWith];
    25     }
    26 }
    27 
    28 
    29 
    30 @implementation NSAutoreleasePool (With)
    31 + (NSAutoreleasePool*) beginWith    {return [self new];}
    32 - (void) endWith                    {[self drain];}
    33 - (BOOL) endWith: (NSException*)x   {[self drain]; return YES;}
    34 @end