Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -84,28 +84,11 @@ { return (id)[[OFConcreteArray alloc] initWithObjects: objects count: count]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFArray + (void)initialize { Index: src/OFCharacterSet.m ================================================================== --- src/OFCharacterSet.m +++ src/OFCharacterSet.m @@ -54,28 +54,11 @@ - (instancetype)initWithRange: (OFRange)range { return (id)[[OFRangeCharacterSet alloc] initWithRange: range]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFCharacterSet + (void)initialize { @@ -148,29 +131,10 @@ initWithCharacterSet: self] autorelease]; } @end @implementation OFWhitespaceCharacterSet -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} - - (bool)characterIsMember: (OFUnichar)character { switch (character) { case 0x0009: case 0x0020: @@ -193,6 +157,8 @@ return true; default: return false; } } + +OF_SINGLETON_METHODS @end Index: src/OFColor.m ================================================================== --- src/OFColor.m +++ src/OFColor.m @@ -24,11 +24,11 @@ #import "OFTaggedPointerColor.h" @interface OFColorSingleton: OFConcreteColor @end -@interface OFColorPlaceholder: OFColorSingleton +@interface OFColorPlaceholder: OFColor @end static struct { Class isa; } placeholder; @@ -63,31 +63,16 @@ return (id)[[OFConcreteColor alloc] initWithRed: red green: green blue: blue alpha: alpha]; } + +OF_SINGLETON_METHODS @end @implementation OFColorSingleton -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} +OF_SINGLETON_METHODS @end @implementation OFColor + (void)initialize { Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -50,33 +50,11 @@ + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFConstantString + (void)load { @@ -133,33 +111,11 @@ + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS /* * In all following methods, the constant string is converted to an * OFConstantUTF8String and the message sent again. */ Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -68,28 +68,11 @@ { return (id)[[OFCountedMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFCountedSet + (void)initialize { Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -122,10 +122,12 @@ - (instancetype)initWithBase64EncodedString: (OFString *)string { return (id)[[OFConcreteData alloc] initWithBase64EncodedString: string]; } + +OF_SINGLETON_METHODS @end @implementation OFData + (void)initialize { Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -260,28 +260,11 @@ return seconds; } @implementation OFDateSingleton -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} +OF_SINGLETON_METHODS @end @implementation OFDatePlaceholder #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ @@ -319,10 +302,12 @@ initWithTimeIntervalSince1970: seconds]; } #ifdef __clang__ # pragma clang diagnostic pop #endif + +OF_SINGLETON_METHODS @end @implementation OFConcreteDate - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds { Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -103,28 +103,11 @@ { return (id)[[OFMapTableDictionary alloc] initWithKey: firstKey arguments: arguments]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFDictionary + (void)initialize { Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -994,28 +994,11 @@ } #endif @end @implementation OFDefaultFileManager -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} +OF_SINGLETON_METHODS @end @implementation OFDictionary (FileAttributes) - (unsigned long long)fileSize { Index: src/OFIRI.m ================================================================== --- src/OFIRI.m +++ src/OFIRI.m @@ -189,28 +189,11 @@ return false; } @implementation OFIRIAllowedCharacterSetBase -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} +OF_SINGLETON_METHODS @end @implementation OFIRIAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -122,28 +122,11 @@ { return (id)[[OFConcreteMutableArray alloc] initWithObjects: objects count: count]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFMutableArray + (void)initialize { Index: src/OFMutableData.m ================================================================== --- src/OFMutableData.m +++ src/OFMutableData.m @@ -111,10 +111,12 @@ - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { return (id)[[OFConcreteMutableData alloc] initWithItemSize: itemSize capacity: capacity]; } + +OF_SINGLETON_METHODS @end @implementation OFMutableData + (void)initialize { Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -84,28 +84,11 @@ { return (id)[[OFMutableMapTableDictionary alloc] initWithCapacity: capacity]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFMutableDictionary + (void)initialize { Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -72,28 +72,11 @@ - (instancetype)initWithCapacity: (size_t)capacity { return (id)[[OFMutableMapTableSet alloc] initWithCapacity: capacity]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFMutableSet + (void)initialize { Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -185,28 +185,11 @@ return (id)[[OFMutableUTF8String alloc] initWithContentsOfIRI: IRI encoding: encoding]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFMutableString + (void)initialize { Index: src/OFNotificationCenter.m ================================================================== --- src/OFNotificationCenter.m +++ src/OFNotificationCenter.m @@ -381,24 +381,7 @@ objc_autoreleasePoolPop(pool); } @end @implementation OFDefaultNotificationCenter -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} +OF_SINGLETON_METHODS @end Index: src/OFNull.m ================================================================== --- src/OFNull.m +++ src/OFNull.m @@ -72,29 +72,7 @@ { uint8_t type = 0xC0; return [OFData dataWithItems: &type count: 1]; } -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -376,31 +376,16 @@ return (id)[[OFNumber of_alloc] initWithDouble: value]; } #ifdef __clang__ # pragma clang diagnostic pop #endif + +OF_SINGLETON_METHODS @end @implementation OFNumberSingleton -- (instancetype)autorelease -{ - return self; -} - -- (instancetype)retain -{ - return self; -} - -- (void)release -{ -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} +OF_SINGLETON_METHODS @end #ifdef OF_OBJFW_RUNTIME @implementation OFTaggedPointerNumber - (const char *)objCType Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -70,28 +70,11 @@ { return (id)[[OFMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFSet + (void)initialize { Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -590,28 +590,11 @@ { return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI encoding: encoding]; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end @implementation OFString + (void)initialize { Index: src/OFTaggedPointerColor.m ================================================================== --- src/OFTaggedPointerColor.m +++ src/OFTaggedPointerColor.m @@ -48,25 +48,8 @@ if (alpha != NULL) *alpha = 1; } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS @end #endif Index: src/exceptions/OFAllocFailedException.m ================================================================== --- src/exceptions/OFAllocFailedException.m +++ src/exceptions/OFAllocFailedException.m @@ -32,34 +32,12 @@ - (instancetype)init { OF_INVALID_INIT_METHOD } -- (instancetype)retain -{ - return self; -} - -- (instancetype)autorelease -{ - return self; -} - -- (unsigned int)retainCount -{ - return OFMaxRetainCount; -} - -- (void)release -{ -} - -- (void)dealloc -{ - OF_DEALLOC_UNSUPPORTED -} +OF_SINGLETON_METHODS - (OFString *)description { return @"Allocating an object failed!"; } @end Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -407,10 +407,34 @@ \ abort(); \ \ [super dealloc]; /* Get rid of a stupid warning */ #endif +#define OF_SINGLETON_METHODS \ + - (instancetype)autorelease \ + { \ + return self; \ + } \ + \ + - (instancetype)retain \ + { \ + return self; \ + } \ + \ + - (void)release \ + { \ + } \ + \ + - (unsigned int)retainCount \ + { \ + return OFMaxRetainCount; \ + } \ + \ + - (void)dealloc \ + { \ + OF_DEALLOC_UNSUPPORTED \ + } #define OF_CONSTRUCTOR(prio) \ static void __attribute__((__constructor__(prio))) \ OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void) #define OF_DESTRUCTOR(prio) \