Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -121,10 +121,16 @@ * \return The implementation of the instance method for the specified selector * or nil if it isn't implemented */ + (IMP)instanceMethodForSelector: (SEL)selector; +/** + * \param selector The selector for which the type encoding should be returned + * \return The type encoding of the instance method for the specified selector + */ ++ (const char*)typeEncodingForInstanceSelector: (SEL)selector; + /** * Replaces a class method implementation with another implementation. * * \param newimp The new implementation for the class method * \param selector The selector of the class method to replace @@ -207,10 +213,17 @@ * * \return The implementation for the specified selector */ - (IMP)methodForSelector: (SEL)selector; +/** + * \param selector The selector for which the type encoding should be returned + * + * \return The type encoding for the specified selector + */ +- (const char*)typeEncodingForSelector: (SEL)selector; + /** * Checks two objects for equality. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -226,10 +226,42 @@ return class_getMethodImplementation(self, selector); #else return method_get_imp(class_get_instance_method(self, selector)); #endif } + ++ (const char*)typeEncodingForInstanceSelector: (SEL)selector +{ +#if defined(OF_APPLE_RUNTIME) + Method m; + const char *ret; + + if ((m = class_getInstanceMethod(self, selector)) == NULL || + (ret = method_getTypeEncoding(m)) == NULL) + @throw [OFNotImplementedException newWithClass: self + selector: selector]; + + return ret; +#elif defined(OF_GNU_RUNTIME) + Method_t m; + + if ((m = class_get_instance_method(self, selector)) == NULL || + m->method_types == NULL) + @throw [OFNotImplementedException newWithClass: self + selector: selector]; + + return m->method_types; +#elif defined(OF_OBJFW_RUNTIME) + const char *ret; + + if ((ret = objc_get_type_encoding(self, selector)) == NULL) + @throw [OFNotImplementedException newWithClass: self + selector: selector]; + + return ret; +#endif +} + (IMP)setImplementation: (IMP)newimp forClassMethod: (SEL)selector { #if defined(OF_OBJFW_RUNTIME) @@ -400,10 +432,42 @@ return class_getMethodImplementation(isa, selector); #else return objc_msg_lookup(self, selector); #endif } + +- (const char*)typeEncodingForSelector: (SEL)selector +{ +#if defined(OF_APPLE_RUNTIME) + Method m; + const char *ret; + + if ((m = class_getInstanceMethod(isa, selector)) == NULL || + (ret = method_getTypeEncoding(m)) == NULL) + @throw [OFNotImplementedException newWithClass: isa + selector: selector]; + + return ret; +#elif defined(OF_GNU_RUNTIME) + Method_t m; + + if ((m = class_get_instance_method(isa, selector)) == NULL || + m->method_types == NULL) + @throw [OFNotImplementedException newWithClass: isa + selector: selector]; + + return m->method_types; +#elif defined(OF_OBJFW_RUNTIME) + const char *ret; + + if ((ret = objc_get_type_encoding(isa, selector)) == NULL) + @throw [OFNotImplementedException newWithClass: isa + selector: selector]; + + return ret; +#endif +} - (BOOL)isEqual: (id)obj { /* Classes containing data should reimplement this! */ return (self == obj ? YES : NO);