@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -29,11 +29,11 @@ #endif #import "OFInvalidArgumentException.h" @implementation OFTimer -@synthesize timeInterval = _interval, repeating = _repeats, valid = _valid; +@synthesize timeInterval = _interval, repeats = _repeats, valid = _valid; + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats @@ -664,6 +664,60 @@ } @finally { [_condition unlock]; } } #endif + +- (OFString *)description +{ +#ifdef OF_HAVE_BLOCKS + if (_block != NULL) + return [OFString stringWithFormat: + @"<%@:\n" + @"\tFire date: %@\n" + @"\tInterval: %lf\n" + @"\tRepeats: %s\n" + @"\tBlock: %@\n" + @"\tValid: %s\n" + @">", + self.class, _fireDate, _interval, (_repeats ? "yes" : "no"), + _block, (_valid ? "yes" : "no")]; + else { +#endif + void *pool = objc_autoreleasePoolPush(); + OFString *objects = @"", *ret; + + if (_arguments >= 1) + objects = [objects stringByAppendingFormat: + @"\tObject: %@\n", _object1]; + if (_arguments >= 2) + objects = [objects stringByAppendingFormat: + @"\tObject: %@\n", _object2]; + if (_arguments >= 3) + objects = [objects stringByAppendingFormat: + @"\tObject: %@\n", _object3]; + if (_arguments >= 4) + objects = [objects stringByAppendingFormat: + @"\tObject: %@\n", _object4]; + + ret = [[OFString alloc] initWithFormat: + @"<%@:\n" + @"\tFire date: %@\n" + @"\tInterval: %lf\n" + @"\tRepeats: %s\n" + @"\tTarget: %@\n" + @"\tSelector: %s\n" + @"%@" + @"\tValid: %s\n" + @">", + self.class, _fireDate, _interval, (_repeats ? "yes" : "no"), + _target, sel_getName(_selector), objects, + (_valid ? "yes" : "no")]; + + objc_autoreleasePoolPop(pool); + + return [ret autorelease]; +#ifdef OF_HAVE_BLOCKS + } +#endif +} @end