With.m
author Jens Alfke <jens@mooseyard.com>
Thu Jul 17 13:29:34 2008 -0700 (2008-07-17)
changeset 18 d6ab9f52b4d7
parent 0 d84d25d6cdbb
permissions -rw-r--r--
Initial checkin of MYAddressField, a combo-box for entering email or IM addresses.
jens@0
     1
//
jens@0
     2
//  With.m
jens@0
     3
//  MYUtilities
jens@0
     4
//
jens@0
     5
//  Copyright 2008 Jens Alfke. All rights reserved.
jens@0
     6
//
jens@0
     7
jens@0
     8
#import "With.h"
jens@0
     9
#import "Logging.h"
jens@0
    10
jens@0
    11
jens@0
    12
@interface NSObject (With)
jens@0
    13
- (BOOL) endWith: (NSException*)x;
jens@0
    14
@end
jens@0
    15
jens@0
    16
jens@0
    17
void _catchWith( id with, NSException *x )
jens@0
    18
{
jens@0
    19
    Warn(@"Exception thrown from WITH(%@) block: %@",[with class],x);
jens@0
    20
    if( [with respondsToSelector: @selector(endWith:)] ) {
jens@0
    21
        if( ! [with endWith: x] )
jens@0
    22
            @throw x;                           // propagate the exception if -endWith: returns NO
jens@0
    23
    } else {
jens@0
    24
        [with endWith];
jens@0
    25
    }
jens@0
    26
}
jens@0
    27
jens@0
    28
jens@0
    29
jens@0
    30
@implementation NSAutoreleasePool (With)
jens@0
    31
+ (NSAutoreleasePool*) beginWith    {return [self new];}
jens@0
    32
- (void) endWith                    {[self drain];}
jens@0
    33
- (BOOL) endWith: (NSException*)x   {[self drain]; return YES;}
jens@11
    34
@end
jens@11
    35
jens@11
    36
jens@11
    37
/*
jens@11
    38
 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
jens@11
    39
 
jens@11
    40
 Redistribution and use in source and binary forms, with or without modification, are permitted
jens@11
    41
 provided that the following conditions are met:
jens@11
    42
 
jens@11
    43
 * Redistributions of source code must retain the above copyright notice, this list of conditions
jens@11
    44
 and the following disclaimer.
jens@11
    45
 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
jens@11
    46
 and the following disclaimer in the documentation and/or other materials provided with the
jens@11
    47
 distribution.
jens@11
    48
 
jens@11
    49
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
jens@11
    50
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
jens@11
    51
 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
jens@11
    52
 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
jens@11
    53
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
jens@11
    54
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
jens@11
    55
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
jens@11
    56
 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jens@11
    57
 */