Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -51,10 +51,17 @@ /** * \return The name of the class as a C string */ + (const char*)name; +/** + * \param protocol The protocol which should be checked for conformance + * + * \return A boolean whether the class conforms to the specified protocol + */ ++ (BOOL)conformsTo: (Protocol*)protocol; + /** * Replace a method with a method from another class. * * \param selector The selector of the method to replace * \param class The class from which the new method should be taken @@ -91,16 +98,23 @@ * \return A boolean whether the object is of the specified kind */ - (BOOL)isKindOf: (Class)class; /** - * \param selector The selector which should be checked + * \param selector The selector which should be checked for respondance * * \return A boolean whether the objects responds to the specified selector */ - (BOOL)respondsTo: (SEL)selector; +/** + * \param protocol The protocol which should be checked for conformance + * + * \return A boolean whether the objects conforms to the specified protocol + */ +- (BOOL)conformsTo: (Protocol*)protocol; + /** * \param selector The selector for which the method should be returned * * \return The implementation for the specified selector */ Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -92,10 +92,35 @@ return class_get_class_name(self); #else return class_getName(self); #endif } + ++ (BOOL)conformsTo: (Protocol*)protocol +{ +#ifdef __objc_INCLUDE_GNU + Class c; + struct objc_protocol_list *pl; + size_t i; + + for (c = self; c != Nil; c = class_get_super_class(c)) + for (pl = c->protocols; pl != NULL; pl = pl->next) + for (i = 0; i < pl->count; i++) + if ([pl->list[i] conformsTo: protocol]) + return YES; + + return NO; +#else + Class c; + + for (c = self; c != Nil; c = class_getSuperclass(c)) + if (class_conformsToProtocol(c, protocol)) + return YES; + + return NO; +#endif +} + (IMP)replaceMethod: (SEL)selector withMethodFromClass: (Class)class; { #ifdef __objc_INCLUDE_GNU @@ -170,10 +195,15 @@ return class_get_class_method(isa, selector) != METHOD_NULL; #else return class_respondsToSelector(isa, selector); #endif } + +- (BOOL)conformsTo: (Protocol*)protocol +{ + return [isa conformsTo: protocol]; +} - (IMP)methodFor: (SEL)selector { #ifdef __objc_INCLUDE_GNU if (object_is_instance(self))