Revision: 4295
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4295&view=rev
Author:   hofman
Date:     2008-07-24 17:38:41 +0000 (Thu, 24 Jul 2008)

Log Message:
-----------
check arguments of method replacement function and combine repeating code

Modified Paths:
--------------
    trunk/NSObject_SKExtensions.m

Modified: trunk/NSObject_SKExtensions.m
===================================================================
--- trunk/NSObject_SKExtensions.m       2008-07-24 17:20:34 UTC (rev 4294)
+++ trunk/NSObject_SKExtensions.m       2008-07-24 17:38:41 UTC (rev 4295)
@@ -42,26 +42,31 @@
 
 @implementation NSObject (SKExtensions)
 
-+ (IMP)setMethod:(IMP)anImp typeEncoding:(const char *)types 
forSelector:(SEL)aSelector {
-    Method method = class_getClassMethod(self, aSelector);
-    IMP imp = method ? SK_method_getImplementation(method) : NULL;
-    if (method && types == NULL)
-        types = SK_method_getTypeEncoding(method);
-    SK_class_replaceMethod(SK_object_getClass(self), aSelector, anImp, types);
+static inline IMP SKReplaceMethodImplementation(Class aClass, SEL aSelector, 
IMP anImp, const char *types, BOOL isInstance) {
+    IMP imp = NULL;
+    if (anImp) {
+        Method method = isInstance ? class_getClassMethod(aClass, aSelector) : 
class_getClassMethod(aClass, aSelector);
+        if (method) {
+            imp = SK_method_getImplementation(method);
+            if (types == NULL)
+                types = SK_method_getTypeEncoding(method);
+        }
+        if (types)
+            SK_class_replaceMethod(isInstance ? aClass : 
SK_object_getClass(aClass), aSelector, anImp, types);
+    }
     return imp;
 }
 
++ (IMP)setMethod:(IMP)anImp typeEncoding:(const char *)types 
forSelector:(SEL)aSelector {
+    return SKReplaceMethodImplementation(self, aSelector, anImp, types, NO);
+}
+
 - (IMP)setMethod:(IMP)anImp typeEncoding:(const char *)types 
forSelector:(SEL)aSelector {
        return [[self class] setInstanceMethod:anImp typeEncoding:types 
forSelector:aSelector];
 }
 
 + (IMP)setInstanceMethod:(IMP)anImp typeEncoding:(const char *)types 
forSelector:(SEL)aSelector {
-    Method method = class_getInstanceMethod(self, aSelector);
-    IMP imp = method ? SK_method_getImplementation(method) : NULL;
-    if (method && types == NULL)
-        types = SK_method_getTypeEncoding(method);
-    SK_class_replaceMethod(self, aSelector, anImp, types);
-    return imp;
+    return SKReplaceMethodImplementation(self, aSelector, anImp, types, YES);
 }
 
 + (IMP)setMethodFromSelector:(SEL)impSelector forSelector:(SEL)aSelector {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to