Source

Murky / Source / Predicate.m

//
//  Predicate.m
//  Murky
//
//  Copyright 2008-2009 Jens Alfke. All rights reserved.
//

#import "Predicate.h"
#import <objc/message.h>


BOOL FnPredicateInvoker(Predicate p,id objectToTest)
{
    return ((const FnPredicate*)p)->fn(objectToTest);
}

BOOL FnArgPredicateInvoker(Predicate p,id objectToTest)
{
    return ((const FnArgPredicate*)p)->fn(objectToTest, ((const FnArgPredicate*)p)->arg);
}


typedef BOOL (*SelArgDispatcher)( id self, SEL _cmd, void *arg );

BOOL SelPredicateInvoker(Predicate p,id objectToTest)
{
    return ((SelArgDispatcher)&objc_msgSend)(objectToTest, 
                                             ((const SelPredicate*)p)->sel,
                                             NULL);
}

BOOL SelArgPredicateInvoker(Predicate p,id objectToTest)
{
    return ((SelArgDispatcher)&objc_msgSend)(objectToTest,
                                             ((const SelArgPredicate*)p)->sel,
                                             ((const SelArgPredicate*)p)->arg);
}


static BOOL TruePredicateInvoker(Predicate p,id objectToTest)
{
    return YES;
}

const struct Predicate TruePredicateStruct = {TruePredicateInvoker};
const Predicate TruePredicate = &TruePredicateStruct;