diff --git a/ChangeLog b/ChangeLog
index 1ed653368..bab1aaa93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2002-08-20 Richard Frith-Macdonald
+ * This function (macro) is used to get the localized
+ * translation of the string
+ * Technically, the function works by calling
+ *
+ *
+ * in the source code, the tools will generate a comment and the line
+ *
+ *
+ * in the
+ * If you don't have a comment (because the string is so
+ * self-explanatory that it doesn't need it), you can leave
+ * it blank, by using
+ * This function (macro) is a GNUstep extension.
+ *
+ *
+ * is exactly the same as
+ *
+ *
+ * It is useful when you need to translate an application
+ * very quickly, as you just need to enclose all strings
+ * inside
+ * This function (macro) is a GNUstep extension.
+ *
+ *
+ * is exactly the same as
+ *
+ *
+ * It is useful when you need to translate an application very
+ * quickly. You would use it as follows for static strings:
+ *
+ *
+ * But please note that when you use this macro, you are not
+ * taking advantage of comments for the translator, so
+ * consider using
+ * This function (macro) is a GNUstep extensions, and it is used
+ * to localize static strings. Here is an example of a static
+ * string:
+ *
+ *
+ * This string can not be localized using the standard
+ * openstep functions/macros. By using this gnustep extension,
+ * you can localize it as follows:
+ *
+ *
+ * When the tools generate the
+ *
+ * When the code is compiled, instead, the
+ *
+ * Please note that there is currently no macro/function to
+ * localize static strings using different tables. If you
+ * need that functionality, you have either to prepare the
+ * localization tables by hand, or to rewrite your code in
+ * such a way as not to use static strings.
+ *
+ * The NSRange type is used to specify ranges of locations,
+ * typically items in an array, characters in a string, and bytes
+ * in a data object.
+ *
+ * As 'boundary' or 'fencepost' errors are a particularly common
+ * problem in programming, it is important that you understand
+ * how an NSRange works.
+ *
+ * An NSRange consists of a location and a length. The points
+ * that are considered to lie in a range are the integers from
+ * the location to the location plus the length, so the number
+ * of points in a range is the length of the range plus one.key
.
+ * key
is looked up in the
+ * Localizable.strings
file for the current
+ * language. The current language is determined by the
+ * available languages in which the application is
+ * translated, and by using the NSLanguages
user
+ * defaults (which should contain an array of the languages
+ * preferred by the user, in order of preference).
+ * localizedStringForKey:value:table:
on the
+ * main bundle, using @""
as value, and
+ * nil
as the table. The comment
+ * is ignored when the macro is expanded; but when we have
+ * tools which can generate the
+ * Localizable.strings
files automatically from
+ * source code, the comment
will be used by the
+ * tools and added as a comment before the string to
+ * translate. Upon finding something like
+ *
+ * NSLocalizedString (@"My useful string",
+ * @"My useful comment about the string");
+ *
+ *
+ * " My useful string" = "My useful string";
+ *
+ * Localizable.strings
file (the
+ * translator then can use this as a skeleton for the
+ * Localizable.strings
for his/her own language,
+ * where she/he can replace the right hand side with the
+ * translation in her/his own language). The comment can
+ * help the translator to decide how to translate when it is
+ * not clear how to translate (because the original string is
+ * now out of context, and out of context might not be so
+ * clear what the string means). The comment is totally
+ * ignored by the library code.
+ * @""
as a comment. If the
+ * string might be unclear out of context, it is recommended
+ * that you add a comment (even if it is unused for now).
+ * NSLocalizedString
, but uses the table
+ * table
rather than the default table. This
+ * means that the string to translate will be looked up in a
+ * different file than Localizable.strings
. For
+ * example, if you pass DatabaseErrors
as the
+ * table
, the string will be looked up for
+ * translation in the file
+ * DatabaseErrors.strings
. This allows you to
+ * have the same string translated in different ways, by
+ * having a different translation in different tables, and
+ * choosing between the different translation by choosing a
+ * different table.
+ */
#define NSLocalizedStringFromTable(key, tbl, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
+
+/*
+ * This function is the full-blown localization function (it
+ * is actually a macro). It looks up the string
+ * key
for translation in the table
+ * table
of the bundle bundle
+ * (please refer to the NSBundle documentation for more
+ * information on how this lookup is done).
+ * comment
is a comment, which is ignored by the
+ * library (it is discarded when the macro is expanded) but which
+ * can be used by tools which parse the source code and generate
+ * strings table to provide a comment which the translator can
+ * use when translating the string.
+ */
#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
[bundle localizedStringForKey:(key) value:@"" table:(tbl)]
@@ -146,33 +234,145 @@ GS_EXPORT NSString* NSLoadedClasses;
/* Now Support for Quick Localization */
#ifndef NO_GNUSTEP
- /* The quickest possible way to localize a string:
-
+ /* The quickest possible way to localize a string:
+
NSLog (_(@"New Game"));
-
- Please make use of the longer functions taking a comment when you
+
+ Please make use of the longer functions taking a comment when you
get the time to localize seriously your code.
*/
+
+/*
+ * _(@"My string to translate")
+ * NSLocalizedString (@"My string to translate", @"")
+ * _()
. But please note that when you
+ * use this macro, you are not taking advantage of comments
+ * for the translator, so consider using
+ * NSLocalizedString
instead when you need a
+ * comment.
+ * __(@"My string to translate")
+ * NSLocalizedStaticString (@"My string to translate", @"")
+ *
+ * NSString *message = __(@"Hello there");
+
+ * ... more code ...
+
+ * NSLog (_(messages));
+ *
+ * NSLocalizedStaticString
+ * instead when you need a comment.
+ *
+ * NSString *message = @"Hi there";
+
+ * ... some code ...
+
+ * NSLog (message);
+ *
+ *
+ * NSString *message = NSLocalizedStaticString (@"Hi there",
+ * @"Greeting");
+
+ * ... some code ...
+
+ * NSLog (NSLocalizedString (message, @""));
+ *
+ * Localizable.strings
file from the source
+ * code, they will ignore the NSLocalizedString
+ * call while they will extract the string (and the comment)
+ * to localize from the NSLocalizedStaticString
+ * call.
+ * NSLocalizedStaticString
call is ignored (discarded,
+ * it is a macro which simply expands to key
), while
+ * the NSLocalizedString
will actually look up the
+ * string for translation in the Localizable.strings
+ * file.
+ *
+ * However, if you consider these points like the marks on a
+ * ruler, you can only store information between
+ * points. So the number of items that can be stored in a range
+ * is the length of the range.
+ *
- Eventually the goal is to center round three classes - + The idea is to center round two classes -
+ * This class maintains a stack of autorelease pools objects + * in each thread. + *
+ *+ * When an autorelease pool is created, it is automatically + * added to the stack of pools in the thread. + *
+ *+ * When a pool is destroyed, it (and any pool later in + * the stack) is removed from the stack. + *
+ */ @implementation NSAutoreleasePool static IMP allocImp; @@ -133,10 +147,13 @@ static IMP initImp; } } +/** + * Allocate and return an autorelease pool instance.+ * Counts the number of times that the specified object occurs + * in autorelease pools in the current thread. + *
+ *+ * This method is slow and should probably only be + * used for debugging purposes. + *
+ */ - (unsigned) autoreleaseCountForObject: (id)anObject { unsigned count = 0; @@ -232,9 +260,16 @@ static IMP initImp; return count; } -/* This method not in OpenStep */ -/* xxx This count should be made for *all* threads, but currently is - only madefor the current thread! */ +/** + *+ * Counts the number of times that the specified object occurs + * in autorelease pools in the current thread. + *
+ *+ * This method is slow and should probably only be + * used for debugging purposes. + *
+ */ + (unsigned) autoreleaseCountForObject: (id)anObject { unsigned count = 0; @@ -247,11 +282,19 @@ static IMP initImp; return count; } +/** + * Return the currently active autorelease pool. + */ + (id) currentPool { return ARP_THREAD_VARS->current_pool; } +/** + * Adds the specified object to the current autorelease pool. + * If there is no autorelease pool in the thread, + * a warning is logged. + */ + (void) addObject: (id)anObj { NSAutoreleasePool *pool = ARP_THREAD_VARS->current_pool; @@ -278,6 +321,9 @@ static IMP initImp; } } +/** + * Adds the specified object to this autorelease pool. + */ - (void) addObject: (id)anObj { /* If the global, static variable AUTORELEASE_ENABLED is not set, @@ -329,6 +375,9 @@ static IMP initImp; _released_count++; } +/** + * Raises an exception ... pools should not be retained. + */ - (id) retain { [NSException raise: NSGenericException @@ -336,6 +385,9 @@ static IMP initImp; return self; } +/** + * Destroys the receiver (calls -dealloc). + */ - (oneway void) release { [self dealloc]; @@ -416,6 +468,9 @@ static IMP initImp; [super dealloc]; } +/** + * Raises an exception - pools should not be autoreleased. + */ - (id) autorelease { [NSException raise: NSGenericException @@ -449,16 +504,50 @@ static IMP initImp; return ARP_THREAD_VARS->total_objects_count; } +/** + *+ * Specifies whether objects contained in autorelease pools are to + * be released when the pools are deallocated (by default YES). + *
+ *+ * You can set this to NO for debugging purposes. + *
+ */ + (void) enableRelease: (BOOL)enable { autorelease_enabled = enable; } +/** + *+ * When autorelease pools are deallocated, the memory they used + * is retained in a cache for re-use so that new polls can be + * created very quickly. + *
+ *+ * This method may be used to empty that cache, ensuring that + * the minimum memory is used by the application. + *
+ */ + (void) freeCache { free_pool_cache(ARP_THREAD_VARS); } +/** + *+ * Specifies a limit to the number of objects that may be added to + * an autorelease pool. When this limit is reached an exception is + * raised. + *
+ *+ * You can set this to a smallish value to catch problems with code + * that autoreleases too many objects to operate efficiently. + *
+ *+ * Default value is maxint. + *
+ */ + (void) setPoolCountThreshhold: (unsigned)c { pool_count_warning_threshhold = c; diff --git a/Source/NSCharacterSet.m b/Source/NSCharacterSet.m index 0656a790e..e01a69e66 100644 --- a/Source/NSCharacterSet.m +++ b/Source/NSCharacterSet.m @@ -144,16 +144,28 @@ static NSLock* cache_lock = nil; return [self _bitmapForSet: @"controlCharSet" number: 1]; } +/** + * Returns a character set containing characters that represent + * the decimal digits 0 through 9. + */ + (NSCharacterSet*) decimalDigitCharacterSet { return [self _bitmapForSet: @"decimalDigitCharSet" number: 2]; } +/** + * Returns a character set containing individual charactars that + * can be represented also by a composed character sequence. + */ + (NSCharacterSet*) decomposableCharacterSet { return [self _bitmapForSet: @"decomposableCharSet" number: 3]; } +/** + * Returns a character set containing unassigned (illegal) + * character values. + */ + (NSCharacterSet*) illegalCharacterSet { return [self _bitmapForSet: @"illegalCharSet" number: 4]; @@ -164,6 +176,11 @@ static NSLock* cache_lock = nil; return [self _bitmapForSet: @"letterCharSet" number: 5]; } +/** + * Returns a character set that contains the lowercase characters. + * This set does not include caseless characters, only those that + * have corresponding characters in uppercase and/or titlecase. + */ + (NSCharacterSet*) lowercaseLetterCharacterSet { return [self _bitmapForSet: @"lowercaseLetterCharSet" number: 6]; @@ -184,16 +201,28 @@ static NSLock* cache_lock = nil; return [self _bitmapForSet: @"symbolAndOperatorCharSet" number: 9]; } +/** + * Returns a character set that contains the uppercase characters. + * This set does not include caseless characters, only those that + * have corresponding characters in lowercase and/or titlecase. + */ + (NSCharacterSet*) uppercaseLetterCharacterSet { return [self _bitmapForSet: @"uppercaseLetterCharSet" number: 10]; } +/** + * Returns a character set that contains the whitespace characters, + * plus the newline characters, values 0x000A and 0x000D. + */ + (NSCharacterSet*) whitespaceAndNewlineCharacterSet { return [self _bitmapForSet: @"whitespaceAndNlCharSet" number: 11]; } +/** + * Returns a character set that contains the whitespace characters. + */ + (NSCharacterSet*) whitespaceCharacterSet { return [self _bitmapForSet: @"whitespaceCharSet" number: 12]; @@ -201,6 +230,10 @@ static NSLock* cache_lock = nil; // Creating custom character sets +/** + * Returns a character set containing characters as encoded in the + * data object. + */ + (NSCharacterSet*) characterSetWithBitmapRepresentation: (NSData*)data { return AUTORELEASE([[NSBitmapCharSet alloc] initWithBitmap: data]); @@ -264,12 +297,20 @@ static NSLock* cache_lock = nil; return nil; } +/** + * Returns a bitmap representation of the receiver's character set + * suitable for archiving or writing to a file, in an NSData object. + */ - (NSData*) bitmapRepresentation { [self subclassResponsibility: _cmd]; return 0; } +/** + * Returns YES if the receiver contains aCharacter, NO if + * it does not. + */ - (BOOL) characterIsMember: (unichar)aCharacter { [self subclassResponsibility: _cmd]; @@ -308,6 +349,10 @@ static NSLock* cache_lock = nil; return NO; } +/** + * Returns a character set containing only characters that the + * receiver does not contain. + */ - (NSCharacterSet*) invertedSet { unsigned i; diff --git a/Source/NSCountedSet.m b/Source/NSCountedSet.m index 8f12af6e7..c59cb1c37 100644 --- a/Source/NSCountedSet.m +++ b/Source/NSCountedSet.m @@ -52,6 +52,17 @@ static BOOL uniquing = NO; + (void) _becomeThreaded: (id)notification; @end +/** + *+ * The NSCountedSet class is used to maintain a set of objects where + * the number of times each object has been added (wiithout a + * corresponding removal) is kept track of. + *
+ *+ * In GNUstep, extra methods are provided to make use of a counted + * set for uniquing objects easier. + *
+ */ @implementation NSCountedSet static Class NSCountedSet_abstract_class; @@ -90,6 +101,11 @@ static Class NSCountedSet_concrete_class; } } +/** + * Returns the number of times that an object that is equal to the + * specified object (as determined byt the [-isEqual:] method) has + * been added to the set and not removed from it. + */ - (unsigned int) countForObject: (id)anObject { [self subclassResponsibility: _cmd]; @@ -201,6 +217,17 @@ static Class NSCountedSet_concrete_class; return self; } +/** + *+ * This method removes from the set all objects whose count is + * less than or equal to the specified value. + *
+ *+ * This is useful where a counted set is used for uniquing objects. + * The set can be periodically purged of objects that have only + * been added once - and are therefore simply wasting space. + *
+ */ - (void) purge: (int)level { if (level > 0) @@ -236,6 +263,22 @@ static Class NSCountedSet_concrete_class; } } +/** + *+ * If the supplied object (or one equal to it as determined by + * the [-isEqual:] method) is already present in the set, the + * count for that object is incremented, the supplied object + * is released, and the object in the set is retained and returned. + * Otherwise, the supplied object is added to the set and returned. + *
+ *
+ * This method is useful for uniquing objects - the init method of
+ * a class need simply end with -
+ *
+ * return [myUniquingSet unique: self];
+ *
+ *
+ * Sets the length of the NSMutableData object. + * If the length is increased, the newly allocated data area + * is filled with zero bytes. + *
+ *+ * This is a 'primitive' method ... you need to implement it + * if you write a subclass of NSMutableData. + *
+ */ - (void) setLength: (unsigned int)size { [self subclassResponsibility: _cmd]; } +/** + *
+ * Returns a pointer to the data storage of the receiver.
+ * Modifications to the memory pointed to by this pointer will
+ * change the contents of the object. It is important that
+ * your code should not try to modify the memory beyond the
+ * number of bytes given by the -length
method.
+ *
+ * NB. if the object is released, or any method that changes its + * size or content is called, then the pointer previously returned + * by this method may cease to be valid. + *
+ *+ * This is a 'primitive' method ... you need to implement it + * if you write a subclass of NSMutableData. + *
+ */ - (void*) mutableBytes { [self subclassResponsibility: _cmd]; @@ -1604,9 +1633,16 @@ failure: [self appendBytes: [other bytes] length: [other length]]; } - -// Modifying Data - +/** + * Replaces the bytes of data in the specified range with a + * copy of the new bytes supplied.[self length] < range.location
)
+ * then a range exception is raised.+ * This function is a GNUstep extension. Returns the number + * of instances of the specified class which are currently + * allocated. This number is very important to detect memory + * leaks. If you notice that this number is constantly + * increasing without apparent reason, it is very likely a + * memory leak - you need to check that you are correctly + * releasing objects of this class, otherwise when your + * application runs for a long time, it will eventually + * allocate so many objects as to eat up all your system's + * memory ... + *
+ *+ * This function, like the ones below, returns the number of + * objects allocated/released from the time when + * GSDebugAllocationActive was first called. A negative + * number means that in total, there are less objects of this + * class allocated now than there were when you called + * GSDebugAllocationActive; a positive one means there are + * more. + *
+ */ int GSDebugAllocationCount(Class c) { @@ -266,6 +316,23 @@ GSDebugAllocationCount(Class c) return 0; } +/** + * This function is a GNUstep extension. Returns the total + * number of instances of the specified class which have been + * allocated - basically the number of times you have + * allocated an object of this class. If this number is very + * high, it means you are creating a lot of objects of this + * class; even if you are releasing them correctly, you must + * not forget that allocating and deallocating objects is + * usually one of the slowest things you can do, so you might + * want to consider whether you can reduce the number of + * allocations and deallocations that you are doing - for + * example, by recycling objects of this class, uniquing + * them, and/or using some sort of flyweight pattern. It + * might also be possible that you are unnecessarily creating + * too many objects of this class. Well - of course some times + * there is nothing you can do about it. + */ int GSDebugAllocationTotal(Class c) { @@ -281,6 +348,18 @@ GSDebugAllocationTotal(Class c) return 0; } +/** + * This function is a GNUstep extension. Returns the peak + * number of instances of the specified class which have been + * concurrently allocated. If this number is very high, it + * means at some point in time you had a situation with a + * huge number of objects of this class allocated - this is + * an indicator that probably at some point in time your + * application was using a lot of memory - so you might want + * to investigate whether you can prevent this problem by + * inserting autorelease pools in your application's + * processing loops. + */ int GSDebugAllocationPeak(Class c) { @@ -296,6 +375,15 @@ GSDebugAllocationPeak(Class c) return 0; } +/** + * This function is a GNUstep extension. Returns a NULL + * terminated array listing all the classes for which + * statistical information has been collected. Usually, you + * call this function, and then loop on all the classes returned, + * and for each one you get current, peak and total count by + * using GSDebugAllocationCount, GSDebugAllocationPeak and + * GSDebugAllocationTotal. + */ Class * GSDebugAllocationClassList() { @@ -321,11 +409,15 @@ GSDebugAllocationClassList() return ans; } -/* - * This function returns a string listing all those classes for which - * either objects are currently allocated (difference == 0), or there - * has been a change in the number of objects allocated since the last - * call (difference != 0). +/** + * This function is a GNUstep extension. Returns a newline + * separated list of the classes which have instances + * allocated, and the instance counts. If the 'changeFlag' + * argument is YES then the list gives the number of + * instances allocated/deallocated since the function was + * last called. This function only returns the current count + * of instances (not the peak or total count), but its output + * is ready to be displayed or logged. */ const char* GSDebugAllocationList(BOOL changeFlag) @@ -415,6 +507,15 @@ _GSDebugAllocationList(BOOL difference) return buf; } +/** + * This function is a GNUstep extension. Returns a newline + * separated list of the classes which have had instances + * allocated at any point, and the total count of the number + * of instances allocated for each class. The difference with + * GSDebugAllocationList is that this function returns also + * classes which have no objects allocated at the moment, but + * which had in the past. + */ const char* GSDebugAllocationListAll() { @@ -537,6 +638,16 @@ GSDebugAllocationRemove(Class c, id o) } } +/** + * This function is a GNUstep extension. Returns an array + * containing all the allocated objects of a certain class + * which have been recorded (to start the recording, you need + * to invoke GSDebugAllocationActiveRecordedObjects). + * Presumably, you will immediately call -description on them + * to find out the objects you are leaking. The objects are + * returned in an array, so until the array is autoreleased, + * the objects are not released. + */ NSArray * GSDebugAllocationListRecordedObjects(Class c) { diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index 8805ad593..ff465821b 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -90,7 +90,8 @@ static SEL appSel; } } -/* This is the designated initializer */ +/**+ * Return a flag to indicate whether compression has been turned on for + * the file handle ... this is only available on systems where GNUstep + * was built with 'zlib' support for compressing/decompressing data. + *
+ *+ * On systems which support it, this method may be called after + * a file handle has been initialised to turn on compression or + * decompression of the data being written/read. + *
+ * Returns YES on success, NO on failure.+ * Produces a string representation of the number. For a boolean + * this will be either 'true' or 'false'. For other numbers the + * format is produced using the initWithFormat:locale:... method + * of NSString, and the format depends on the type of number as + * follows - + *
+ *
+ * NSObject
is the root class (a root class is
+ * a class with no superclass) of the gnustep base library
+ * class hierarchy, so all classes normally inherit from
+ * NSObject
. There is an exception though:
+ * NSProxy
(which is used for remote messaging)
+ * does not inherit from NSObject
.
+ *
+ * Unless you are really sure of what you are doing, all
+ * your own classes should inherit (directly or indirectly)
+ * from NSObject
(or in special cases from
+ * NSProxy
). NSObject
provides
+ * the basic common functionality shared by all gnustep
+ * classes and objects.
+ *
+ * The essential methods which must be implemented by all
+ * classes for their instances to be usable within gnustep
+ * are declared in a separate protocol, which is the
+ * NSObject
protocol. Both
+ * NSObject
and NSProxy
conform to
+ * this protocol, which means all objects in a gnustep
+ * application will conform to this protocol (btw, if you
+ * don't find a method of NSObject
you are
+ * looking for in this documentation, make sure you also
+ * look into the documentation for the NSObject
+ * protocol).
+ *
+ * Theoretically, in special cases you might need to
+ * implement a new root class. If you do, you need to make
+ * sure that your root class conforms (at least) to the
+ * NSObject
protocol, otherwise it will not
+ * interact correctly with the gnustep framework. Said
+ * that, I must note that I have never seen a case in which
+ * a new root class is needed.
+ *
+ * NSObject
is a root class, which implies that
+ * instance methods of NSObject
are treated in
+ * a special way by the Objective-C runtime. This is an
+ * exception to the normal way messaging works with class
+ * and instance methods: if the Objective-C runtime can't
+ * find a class method for a class object, as a last resort
+ * it looks for an instance method of the root class with
+ * the same name, and executes it if it finds it. This
+ * means that instance methods of the root class (such as
+ * NSObject
) can be performed by class objects
+ * which inherit from that root class ! This can only
+ * happen if the class doesn't have a class method with the
+ * same name, otherwise that method - of course - takes the
+ * precedence. Because of this exception,
+ * NSObject
's instance methods are written in
+ * such a way that they work both on NSObject
's
+ * instances and on class objects.
+ *
NSDefaultMallocZone()
as the zone argument.
+ * Memory for an instance of the receiver is allocated; a
+ * pointer to this newly created instance is returned. All
+ * instance variables are set to 0 except the
+ * isa
pointer which is set to point to the
+ * object class. No initialization of the instance is
+ * performed: it is your responsibility to initialize the
+ * instance by calling an appropriate init
+ * method. If you are not using the garbage collector, it is
+ * also your responsibility to make sure the returned
+ * instance is destroyed when you finish using it, by calling
+ * the release
method to destroy the instance
+ * directly, or by using autorelease
and
+ * autorelease pools.
+ *
+ * You do not normally need to override this method in + * subclasses, unless you are implementing a class which for + * some reasons silently allocates instances of another class + * (this is typically needed to implement class clusters and + * similar design schemes). + *
+ *
+ * If you have turned on debugging of object allocation (by
+ * calling the GSDebugAllocationActive
+ * function), this method will also update the various
+ * debugging counts and monitors of allocated objects, which
+ * you can access using the GSDebugAllocation...
+ * functions.
+ *
+ * This method is a short-hand for alloc followed by init, that is, + *
+ *
+ * NSObject *object = [NSObject new];
+ *
+ * NSObject *object = [[NSObject alloc] init];
+ *
+ * This is a general convention: all new...
+ * methods are supposed to return a newly allocated and
+ * initialized instance, as would be generated by an
+ * alloc
method followed by a corresponding
+ * init...
method. Please note that if you are
+ * not using a garbage collector, this means that instances
+ * generated by the new...
methods are not
+ * autoreleased, that is, you are responsible for releasing
+ * (autoreleasing) the instances yourself. So when you use
+ * new
you typically do something like:
+ *
+ *
+ * NSMutableArray *array = AUTORELEASE ([NSMutableArray new]);
+ *
+ *
+ * You do no normally need to override new
in
+ * subclasses, because if you override init
(and
+ * optionally allocWithZone:
if you really
+ * need), new
will automatically use your
+ * subclass methods.
+ *
+ * You might need instead to define new new...
+ * methods specific to your subclass to match any
+ * init...
specific to your subclass. For
+ * example, if your subclass defines an instance method
+ *
+ * initWithName:
+ *
+ * it might be handy for you to have a class method + *
+ *
+ * newWithName:
+ *
+ * which combines alloc
and
+ * initWithName:
. You would implement it as follows:
+ *
+ *
+ * + (id) newWithName: (NSString *)aName
+ * {
+ * return [[self alloc] initWithName: aName];
+ * }
+ *
+ *
+ * You should normally call the superclass implementation of this method + * when you override it in a subclass, or the memory occupied by your + * object will not be released. + *
+ *
+ * NSObject
's implementation of this method
+ * destroys the receiver, by returning the memory allocated
+ * to the receiver to the system. After this method has been
+ * called on an instance, you must not refer the instance in
+ * any way, because it does not exist any longer. If you do,
+ * it is a bug and your program might even crash with a
+ * segmentation fault.
+ *
+ * If you have turned on the debugging facilities for
+ * instance allocation, NSObject
's
+ * implementation of this method will also update the various
+ * counts and monitors of allocated instances (see the
+ * GSDebugAllocation...
functions for more
+ * info).
+ *
+ * Normally you are supposed to manage the memory taken by
+ * objects by using the high level interface provided by the
+ * retain
, release
and
+ * autorelease
methods (or better by the
+ * corresponding macros RETAIN
,
+ * RELEASE
and AUTORELEASE
), and by
+ * autorelease pools and such; whenever the
+ * release/autorelease mechanism determines that an object is
+ * no longer needed (which happens when its retain count
+ * reaches 0), it will call the dealloc
method
+ * to actually deallocate the object. This means that normally,
+ * you should not need to call dealloc
directly as
+ * the gnustep base library automatically calls it for you when
+ * the retain count of an object reaches 0.
+ *
+ * Because the dealloc
method will be called
+ * when an instance is being destroyed, if instances of your
+ * subclass use objects or resources (as it happens for most
+ * useful classes), you must override dealloc
in
+ * subclasses to release all objects and resources which are
+ * used by the instance, otherwise these objects and
+ * resources would be leaked. In the subclass
+ * implementation, you should first release all your subclass
+ * specific objects and resources, and then invoke super's
+ * implementation (which will do the same, and so on up in
+ * the class hierarchy to NSObject
's
+ * implementation, which finally destroys the object). Here
+ * is an example of the implementation of
+ * dealloc
for a subclass whose instances have a
+ * single instance variable name
which needs to
+ * be released when an instance is deallocated:
+ *
+ *
+ * - (void) dealloc
+ * {
+ * RELEASE (name);
+ * [super dealloc];
+ * }
+ *
+ *
+ * dealloc
might contain code to release not
+ * only objects, but also other resources, such as open
+ * files, network connections, raw memory allocated in other
+ * ways, etc.
+ *
+ * If you have allocated the memory using a non-standard mechanism, you
+ * will not call the superclass (NSObject) implementation of the method
+ * as you will need to handle the deallocation specially.
+ * In some circumstances, an object may wish to prevent itsself from
+ * being deallocated, it can do this simply be refraining from calling
+ * the superclass implementation.
+ *
+ * The NSScanner class cluster (currently a single class in GNUstep) + * provides a mechanism to parse the contents of a string into number + * and string values by making a sequence of scan operations to + * step through the string retrieving successive items. + *
+ *+ * You can tell the scanner whether its scanning is supposed to be + * case sensitive or not, and you can specify a set of characters + * to be skipped before each scanning operation (by default, + * whitespace and newlines). + *
+ */ @implementation NSScanner @class GSCString; @@ -104,7 +118,8 @@ typedef struct { } /* - * Create and return a scanner that scans aString. + * Create and return a scanner that scans aString.+ * NSString objects represent an immutable string of characters. + * NSString itself is an abstract class which provides factory + * methods to generate objects of unspecified subclasses. + *
+ *
+ * A constant NSString can be created using the following syntax:
+ * @"..."
, where the contents of the quotes are the
+ * string, using only ASCII characters.
+ *
+ * To create a concrete subclass of NSString, you must have your + * class inherit from NSString and override at least the two + * primitive methods - length and characterAtIndex: + *
+ *+ * In general the rule is that your subclass must override any + * initialiser that you want to use with it. The GNUstep + * implementation relaxes that to say that, you may override + * only the designated initialiser and the other + * initialisation methods should work. + *
+ */ @implementation NSString static NSStringEncoding _DefaultStringEncoding; @@ -541,7 +564,11 @@ handle_printf_atsign (FILE *stream, // Initializing Newly Allocated Strings -/* This is the designated initializer. */ +/**+ * Returns the encoding used for any method accepting a C string. + * This value is determined automatically from the programs + * environment and cannot be changed programmatically. + *
+ *+ * You should NOT override this method in an attempt to + * change the encoding being used... it won't work. + *
+ *
+ * In GNUstep, this encoding is determined by the initial value
+ * of the GNUSTEP_STRING_ENCODING
environment
+ * variable. If this is not defined,
+ * NSISOLatin1StringEncoding
is assumed.
+ *
+ * This function is a GNUstep extension. It pretty much + * duplicates the functionality of [NSThread +currentThread] + * but is more efficient and is used internally throughout + * GNUstep. + *
+ *
+ * Returns the current thread. Could perhaps return nil
+ * if executing a thread that was started outside the GNUstep
+ * environment and not registered (this should not happen in a
+ * well-coded application).
+ *
+ * Returns the NSThread object corresponding to the current thread. + *
+ *+ * NB. In GNUstep the library internals use the GSCurrentThread() + * function as a more efficient mechanism for doing this job - so + * you cannot use a category to override this method and expect + * the library internals to use your implementation. + *
*/ + (NSThread*) currentThread { @@ -457,6 +476,22 @@ gnustep_base_thread_callback() typedef struct { @defs(NSThread) } NSThread_ivars; +/** + *+ * This function is provided to let threads started by some other + * software library register themselves to be used with the + * GNUstep system. All such threads should call this function + * before attempting to use any GNUstep objects. + *
+ *
+ * Returns YES
if the thread can be registered,
+ * NO
if it is already registered.
+ *
+ * Sends out a NSWillBecomeMultiThreadedNotification
+ * if the process was not already multithreaded.
+ *
+ * This function is provided to let threads started by some other + * software library unregister themselves from the GNUstep threading + * system. + *
+ *
+ * Calling this function causes a
+ * NSThreadWillExitNotification
+ * to be sent out, and destroys the GNUstep NSThread object
+ * associated with the thread.
+ *
+ * If the GNUstep time zone datafiles become too out of date, one
+ * can download an updated database from