X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/e1c9d15e410c3ce93c566a64e6514bc339bd526d..4ad564f9120afcd0f1ca486c501f72c93a8cdfb1:/ITCategory-NSObject.m?ds=inline diff --git a/ITCategory-NSObject.m b/ITCategory-NSObject.m index 09281e8..36b59c5 100644 --- a/ITCategory-NSObject.m +++ b/ITCategory-NSObject.m @@ -1,129 +1,103 @@ #import "ITCategory-NSObject.h" #import -@implementation NSObject (ITCategory) +@implementation NSObject (ITFoundationCategory) + (NSArray *)subclasses { - NSMutableArray *tempArray; - NSArray *resultArray; - Class *classes; - struct objc_class *superClass; - Class *current; - int count, newCount, index; - - tempArray = [[NSMutableArray allocWithZone:nil] initWithCapacity:12]; - resultArray = nil; - - if (tempArray) - { - classes = NULL; - count = objc_getClassList(NULL, 0); - if (count) - { - classes = malloc(sizeof(Class) * count); - if (classes) - { - newCount = objc_getClassList(classes, count); - while (count < newCount) - { - count = newCount; - free(classes); - classes = malloc(sizeof(Class) * count); - if (classes) - newCount = objc_getClassList(classes, count); - } - count = newCount; - } - } - - if (classes) - { - const Class thisClass = [self class]; - current = classes; - - for (index = 0; index < count; ++index) - { - superClass = (*current)->super_class; - if (superClass) - { - do - { - if (superClass == thisClass) - { - [tempArray addObject:*current]; - break; - } - superClass = superClass->super_class; - } while (superClass); - } - - ++current; - } - - free(classes); - } - - resultArray = [NSArray arrayWithArray:tempArray]; - [tempArray release]; - } - - return resultArray; + NSMutableArray *tempArray; + NSArray *resultArray; + Class *classes; + struct objc_class *superClass; + Class *current; + int count, newCount, index; + tempArray = [[NSMutableArray allocWithZone:nil] initWithCapacity:12]; + resultArray = nil; + if (tempArray) { + classes = NULL; + count = objc_getClassList(NULL, 0); + if (count) { + classes = malloc(sizeof(Class) * count); + if (classes) { + newCount = objc_getClassList(classes, count); + while (count < newCount) { + count = newCount; + free(classes); + classes = malloc(sizeof(Class) * count); + if (classes) { + newCount = objc_getClassList(classes, count); + } + } + count = newCount; + } + } + if (classes) { + const Class thisClass = [self class]; + current = classes; + for (index = 0; index < count; ++index) { + superClass = (*current)->super_class; + if (superClass) { + do { + if (superClass == thisClass) { + [tempArray addObject:*current]; + break; + } + superClass = superClass->super_class; + } while (superClass); + } + ++current; + } + free(classes); + } + resultArray = [NSArray arrayWithArray:tempArray]; + [tempArray release]; + } + return resultArray; } + (NSArray *)directSubclasses { - NSMutableArray *tempArray; - NSArray *resultArray; - Class *classes; - Class *current; - int count, newCount, index; - - tempArray = [[NSMutableArray allocWithZone:nil] initWithCapacity:12]; - resultArray = nil; - - if (tempArray) - { - classes = NULL; - count = objc_getClassList(NULL, 0); - if (count) - { - classes = malloc(sizeof(Class) * count); - if (classes) - { - newCount = objc_getClassList(classes, count); - while (count < newCount) - { - count = newCount; - free(classes); - classes = malloc(sizeof(Class) * count); - if (classes) - newCount = objc_getClassList(classes, count); - } - count = newCount; - } - } - - if (classes) - { - const Class thisClass = [self class]; - current = classes; - - for (index = 0; index < count; ++index) - { - if ((*current)->super_class == thisClass) - [tempArray addObject:*current]; - ++current; - } - - free(classes); - } - - resultArray = [NSArray arrayWithArray:tempArray]; - [tempArray release]; - } - - return resultArray; + NSMutableArray *tempArray; + NSArray *resultArray; + Class *classes; + Class *current; + int count, newCount, index; + tempArray = [[NSMutableArray allocWithZone:nil] initWithCapacity:12]; + resultArray = nil; + if (tempArray) { + classes = NULL; + count = objc_getClassList(NULL, 0); + if (count) { + classes = malloc(sizeof(Class) * count); + if (classes) { + newCount = objc_getClassList(classes, count); + while (count < newCount) { + count = newCount; + free(classes); + classes = malloc(sizeof(Class) * count); + if (classes) { + newCount = objc_getClassList(classes, count); + } + } + count = newCount; + } + } + if (classes) { + const Class thisClass = [self class]; + current = classes; + + for (index = 0; index < count; ++index) { + if ((*current)->super_class == thisClass) { + [tempArray addObject:*current]; + } + ++current; + } + free(classes); + } + resultArray = [NSArray arrayWithArray:tempArray]; + [tempArray release]; + } + return resultArray; } @end \ No newline at end of file