2010-02-14 10:48:10 +00:00
|
|
|
/** Declaration of extension methods for base additions
|
|
|
|
|
|
|
|
Copyright (C) 2003-2010 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
|
|
|
and: Adam Fedor <fedor@gnu.org>
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_NSObject_GNUstepBase_h
|
|
|
|
#define INCLUDED_NSObject_GNUstepBase_h
|
|
|
|
|
|
|
|
#import <GNUstepBase/GSVersionMacros.h>
|
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
|
|
|
|
|
|
|
|
@interface NSObject (GNUstepBase)
|
2010-02-25 08:19:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
WARNING: The -compare: method for NSObject is deprecated
|
|
|
|
due to subclasses declaring the same selector with
|
|
|
|
conflicting signatures.
|
|
|
|
Comparision of arbitrary objects is not just meaningless
|
|
|
|
but also dangerous as most concrete implementations
|
|
|
|
expect comparable objects as arguments often accessing
|
|
|
|
instance variables directly.
|
|
|
|
This method will be removed in a future release.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compare: (id)anObject;
|
|
|
|
|
|
|
|
/** For backward compatibility only ... use class_isMetaClass() on the
|
|
|
|
* class of the receiver instead.
|
|
|
|
*/
|
|
|
|
- (BOOL) isInstance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transmutes the receiver into an immutable version of the same object
|
|
|
|
* and returns the result.<br />
|
|
|
|
* If the receiver is not a mutable object or cannot be simply transmuted,
|
|
|
|
* then this method either returns the receiver unchanged or,
|
|
|
|
* if the force flag is set to YES, returns an autoreleased copy of the
|
|
|
|
* receiver.<br />
|
|
|
|
* Mutable classes should override this default implementation.<br />
|
|
|
|
* This method is used in methods which are declared to return immutable
|
|
|
|
* objects (eg. an NSArray), but which create and build mutable ones
|
|
|
|
* internally.
|
|
|
|
*/
|
|
|
|
- (id) makeImmutableCopyOnFail: (BOOL)force;
|
|
|
|
|
2010-02-14 10:48:10 +00:00
|
|
|
/**
|
|
|
|
* Message sent when an implementation wants to explicitly exclude a method
|
|
|
|
* (but cannot due to compiler constraint), and wants to make sure it is not
|
|
|
|
* called by mistake. Default implementation raises an exception at runtime.
|
|
|
|
*/
|
2011-02-11 14:38:09 +00:00
|
|
|
- (id) notImplemented: (SEL)aSel GS_NORETURN_METHOD;
|
2010-02-14 10:48:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Message sent when an implementation wants to explicitly require a subclass
|
|
|
|
* to implement a method (but cannot at compile time since there is no
|
|
|
|
* <code>abstract</code> keyword in Objective-C). Default implementation
|
|
|
|
* raises an exception at runtime to alert developer that he/she forgot to
|
|
|
|
* override a method.
|
|
|
|
*/
|
2011-02-11 14:38:09 +00:00
|
|
|
- (id) subclassResponsibility: (SEL)aSel GS_NORETURN_METHOD;
|
2010-02-14 10:48:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Message sent when an implementation wants to explicitly exclude a method
|
|
|
|
* (but cannot due to compiler constraint) and forbid that subclasses
|
|
|
|
* implement it. Default implementation raises an exception at runtime. If a
|
|
|
|
* subclass <em>does</em> implement this method, however, the superclass's
|
|
|
|
* implementation will not be called, so this is not a perfect mechanism.
|
|
|
|
*/
|
2011-02-11 14:38:09 +00:00
|
|
|
- (id) shouldNotImplement: (SEL)aSel GS_NORETURN_METHOD;
|
2010-02-25 08:19:52 +00:00
|
|
|
|
2010-02-14 10:48:10 +00:00
|
|
|
@end
|
|
|
|
|
2011-06-19 09:26:03 +00:00
|
|
|
/** Category for methods handling leaked memory cleanup on exit of process
|
|
|
|
* (for use when debugging memory leaks).<br />
|
|
|
|
* You enable this by calling the +setShouldCleanUp: method (done implicitly
|
|
|
|
* by gnustep-base if the GNUSTEP_SHOULD_CLEAN_UP environment variable is
|
|
|
|
* set to YES).<br />
|
|
|
|
* Your class then has two options for performing cleanup when the process
|
|
|
|
* ends:
|
|
|
|
* <p>1. Use the +leak: method to register objects which are simply to be
|
|
|
|
* retained until the process ends, and then either ignored or released
|
|
|
|
* depending on the cleanup setting in force. This mechanism is simple
|
|
|
|
* and should be sufficient for many classes.
|
|
|
|
* </p>
|
|
|
|
* <p>2. Implement a +atExit method to be run when the process ends and,
|
|
|
|
* within that method call +shouldCleanUp to determine whether cleanup
|
|
|
|
* should be done, and if it returns YES then perform any complex cleanup
|
|
|
|
* tasks for the class.
|
|
|
|
* </p>
|
|
|
|
*/
|
|
|
|
@interface NSObject(atExit)
|
|
|
|
|
|
|
|
/** This method is called on exit for any class which implements it.<br />
|
|
|
|
* The order in which methods for different classes is called is indeterminate
|
|
|
|
* so the method must not depend on any other class being in a usable state
|
|
|
|
* at the point when the method is called (rather like +load).<br />
|
|
|
|
* Typical use would be to release memory occupied by class data structures
|
|
|
|
* so that memory usage analysis software will not think the memory has
|
|
|
|
* been leaked.
|
|
|
|
*/
|
|
|
|
+ (void) atExit;
|
|
|
|
|
|
|
|
/** Activates support for the +atExit method.
|
|
|
|
*/
|
|
|
|
+ (void) enableAtExit;
|
|
|
|
|
|
|
|
/** This method simply retains its argument so that it will never be
|
|
|
|
* deallocated during normal operation, but keeps track of it so that
|
|
|
|
* it is released during process exit (at the point immediately before
|
|
|
|
* calls to +atExit methods are performed) if cleanup is enabled.<br />
|
|
|
|
* Returns its argument.
|
|
|
|
*/
|
|
|
|
+ (id) leak: (id)anObject;
|
|
|
|
|
|
|
|
/** Specifies the default cleanup behavior on process exit ... the value
|
|
|
|
* returned by the NSObject implementation of the +shouldClanUp method.<br />
|
|
|
|
* Calling this method with a YES argument implicitly calls the +enableAtExit
|
|
|
|
* method as well.<br />
|
|
|
|
* The GNUstep Base library calls this method with the value obtained from
|
|
|
|
* the GNUSTEP_SHOULD_CLEAN_UP environment variable when NSObject is
|
|
|
|
* initialised.
|
|
|
|
*/
|
|
|
|
+ (void) setShouldCleanUp: (BOOL)aFlag;
|
|
|
|
|
|
|
|
/** Returns a flag indicating whether the receiver should clean up
|
|
|
|
* its data structures etc at process exit.<br />
|
|
|
|
* The NSObject implementation returns the value set by the +setShouldCleanUp:
|
|
|
|
* method but subclasses may override this.
|
|
|
|
*/
|
|
|
|
+ (BOOL) shouldCleanUp;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-02-14 10:48:10 +00:00
|
|
|
#endif /* OS_API_VERSION */
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* INCLUDED_NSObject_GNUstepBase_h */
|
|
|
|
|