Some tidying up of macros.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26357 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-03-19 06:59:43 +00:00
parent a91867ac8c
commit c895d41e78
6 changed files with 336 additions and 381 deletions

View file

@ -1,3 +1,16 @@
2008-03-19 Richard Frith-Macdonald <rfm@gnu.org>
* Source/DocMakefile: include GNUstep.h
* Headers/Foundation/NSObject.h: include GNUstep.h for macros
* Headers/Foundation/NSBundle.h: move gnustep specific macros out
* Headers/Additions/GNUstepBase/GSFunctions.h: undeprecate and add
GSLocalizedStringFromTableInFramework from NSBundle.h
* Headers/Additions/GNUstepBase/GNUstep.h: Add comments etc.
Code changes to avoid duplication of macro definitions, make
GNUstep.h usable anywhere, and rename a couple of GNUstep specific
extensions to use the GS prefix rather than the (reserved by Apple)
NS prefix.
2008-03-18 Riccardo Mottola <rmottola@users.sf.net>
* Source/GNUMakefile: Added FoundationErrors.h

View file

@ -25,59 +25,316 @@
#ifndef __GNUSTEP_GNUSTEP_H_INCLUDED_
#define __GNUSTEP_GNUSTEP_H_INCLUDED_
#ifndef GNUSTEP
/* The contents of this file are designed to be usable with either
* GNUstep-base or MacOS-X Foundation.
*/
#define AUTORELEASE(object) [object autorelease]
#define TEST_AUTORELEASE(object) ({ if (object) [object autorelease]; })
#if GS_WITH_GC
#define RELEASE(object) [object release]
#define TEST_RELEASE(object) ({ if (object) [object release]; })
#ifndef RETAIN
#define RETAIN(object) ((id)object)
#endif
#ifndef RELEASE
#define RELEASE(object)
#endif
#ifndef AUTORELEASE
#define AUTORELEASE(object) ((id)object)
#endif
#define RETAIN(object) [object retain]
#define TEST_RETAIN(object) ({ if (object) [object retain]; })
#ifndef TEST_RETAIN
#define TEST_RETAIN(object) ((id)object)
#endif
#ifndef TEST_RELEASE
#define TEST_RELEASE(object)
#endif
#ifndef TEST_AUTORELEASE
#define TEST_AUTORELEASE(object) ((id)object)
#endif
#define ASSIGN(object,value) ({\
id __value = (id)(value); \
id __object = (id)(object); \
if (__value != __object) \
{ \
if (__value != nil) \
{ \
[__value retain]; \
} \
object = __value; \
if (__object != nil) \
{ \
[__object release]; \
} \
} \
})
#ifndef ASSIGN
#define ASSIGN(object,value) (object = value)
#endif
#ifndef ASSIGNCOPY
#define ASSIGNCOPY(object,value) (object = [value copy])
#endif
#ifndef DESTROY
#define DESTROY(object) (object = nil)
#endif
#define ASSIGNCOPY(object,value) ASSIGN(object, [[value copy] autorelease]);
#ifndef CREATE_AUTORELEASE_POOL
#define CREATE_AUTORELEASE_POOL(X)
#endif
#define DESTROY(object) ({ \
if (object) \
{ \
id __o = object; \
object = nil; \
[__o release]; \
} \
})
#ifndef RECREATE_AUTORELEASE_POOL
#define RECREATE_AUTORELEASE_POOL(X)
#endif
#define CREATE_AUTORELEASE_POOL(X) \
NSAutoreleasePool *(X) = [NSAutoreleasePool new]
#define IF_NO_GC(X)
#define NSLocalizedString(key, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
#else
#define _(X) NSLocalizedString (X, nil)
#ifndef RETAIN
/**
* Basic retain operation ... calls [NSObject-retain]
*/
#define RETAIN(object) [object retain]
#endif
#ifndef RELEASE
/**
* Basic release operation ... calls [NSObject-release]
*/
#define RELEASE(object) [object release]
#endif
#ifndef AUTORELEASE
/**
* Basic autorelease operation ... calls [NSObject-autorelease]
*/
#define AUTORELEASE(object) [object autorelease]
#endif
#ifndef TEST_RETAIN
/**
* Tested retain - only invoke the
* objective-c method if the receiver is not nil.
*/
#define TEST_RETAIN(object) ({\
id __object = (id)(object); (__object != nil) ? [__object retain] : nil; })
#endif
#ifndef TEST_RELEASE
/**
* Tested release - only invoke the
* objective-c method if the receiver is not nil.
*/
#define TEST_RELEASE(object) ({\
id __object = (id)(object); if (__object != nil) [__object release]; })
#endif
#ifndef TEST_AUTORELEASE
/**
* Tested autorelease - only invoke the
* objective-c method if the receiver is not nil.
*/
#define TEST_AUTORELEASE(object) ({\
id __object = (id)(object); (__object != nil) ? [__object autorelease] : nil; })
#endif
#ifndef ASSIGN
/**
* ASSIGN(object,value) assigns the value to the object with
* appropriate retain and release operations.
*/
#define ASSIGN(object,value) ({\
id __value = (id)(value); \
id __object = (id)(object); \
if (__value != __object) \
{ \
if (__value != nil) \
{ \
[__value retain]; \
} \
object = __value; \
if (__object != nil) \
{ \
[__object release]; \
} \
} \
})
#endif
#ifndef ASSIGNCOPY
/**
* ASSIGNCOPY(object,value) assigns a copy of the value to the object
* with release of the original.
*/
#define ASSIGNCOPY(object,value) ({\
id __value = (id)(value); \
id __object = (id)(object); \
if (__value != __object) \
{ \
if (__value != nil) \
{ \
__value = [__value copy]; \
} \
object = __value; \
if (__object != nil) \
{ \
[__object release]; \
} \
} \
})
#endif
#ifndef DESTROY
/**
* DESTROY() is a release operation which also sets the variable to be
* a nil pointer for tidiness - we can't accidentally use a DESTROYED
* object later. It also makes sure to set the variable to nil before
* releasing the object - to avoid side-effects of the release trying
* to reference the object being released through the variable.
*/
#define DESTROY(object) ({ \
if (object) \
{ \
id __o = object; \
object = nil; \
[__o release]; \
} \
})
#endif
#ifndef CREATE_AUTORELEASE_POOL
/**
* Declares an autorelease pool variable and creates and initialises
* an autorelease pool object.
*/
#define CREATE_AUTORELEASE_POOL(X) \
NSAutoreleasePool *(X) = [NSAutoreleasePool new]
#endif
#ifndef RECREATE_AUTORELEASE_POOL
/**
* Similar, but allows reuse of variables. Be sure to use DESTROY()
* so the object variable stays nil.
*/
#define RECREATE_AUTORELEASE_POOL(X) \
if (X == nil) \
(X) = [NSAutoreleasePool new]
#endif
#define IF_NO_GC(X) X
#endif
/**
* <p>
* This function (macro) is a GNUstep extension.
* </p>
* <p>
* <code>_(@"My string to translate")</code>
* </p>
* <p>
* is exactly the same as
* </p>
* <p>
* <code>NSLocalizedString (@"My string to translate", @"")</code>
* </p>
* <p>
* It is useful when you need to translate an application
* very quickly, as you just need to enclose all strings
* inside <code>_()</code>. But please note that when you
* use this macro, you are not taking advantage of comments
* for the translator, so consider using
* <code>NSLocalizedString</code> instead when you need a
* comment.
* </p>
*/
#define _(X) NSLocalizedString (X, @"")
/* The quickest possible way to localize a static string:
static NSString *string = __(@"New Game");
NSLog (_(string)); */
/**
* <p>
* This function (macro) is a GNUstep extension.
* </p>
* <p>
* <code>__(@"My string to translate")</code>
* </p>
* <p>
* is exactly the same as
* </p>
* <p>
* <code>GSLocalizedStaticString (@"My string to translate", @"")</code>
* </p>
* <p>
* It is useful when you need to translate an application very
* quickly. You would use it as follows for static strings:
* </p>
* <p>
* <code>
* NSString *message = __(@"Hello there");
* ... more code ...
* NSLog (_(messages));
* </code>
* </p>
* <p>
* But please note that when you use this macro, you are not
* taking advantage of comments for the translator, so
* consider using <code>GSLocalizedStaticString</code>
* instead when you need a comment.
* </p>
*/
#define __(X) X
#define NSLocalizedStaticString(X, Y) X
/* The better way for a static string, with a comment - use as follows -
static NSString *string = GSLocalizedStaticString (@"New Game",
@"Menu Option");
#include <GNUstepBase/GSVersionMacros.h>
NSLog (_(string));
If you need anything more complicated than this, please initialize
the static strings manually.
*/
/**
* <p>
* This function (macro) is a GNUstep extensions, and it is used
* to localize static strings. Here is an example of a static
* string:
* </p>
* <p>
* <code>
* NSString *message = @"Hi there";
* ... some code ...
* NSLog (message);
* </code>
* </p>
* <p>
* This string can not be localized using the standard
* openstep functions/macros. By using this gnustep extension,
* you can localize it as follows:
* </p>
* <p>
* <code>
* NSString *message = GSLocalizedStaticString (@"Hi there",
* @"Greeting");
*
* ... some code ...
*
* NSLog (NSLocalizedString (message, @""));
* </code>
* </p>
* <p>
* When the tools generate the
* <code>Localizable.strings</code> file from the source
* code, they will ignore the <code>NSLocalizedString</code>
* call while they will extract the string (and the comment)
* to localize from the <code>GSLocalizedStaticString</code>
* call.
* </p>
* <p>
* When the code is compiled, instead, the
* <code>GSLocalizedStaticString</code> call is ignored (discarded,
* it is a macro which simply expands to <code>key</code>), while
* the <code>NSLocalizedString</code> will actually look up the
* string for translation in the <code>Localizable.strings</code>
* file.
* </p>
* <p>
* 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.
* </p>
*/
#define GSLocalizedStaticString(key, comment) key
#endif /* GNUSTEP */
#endif /* __GNUSTEP_GNUSTEP_H_INCLUDED_ */

View file

@ -1,4 +1,4 @@
/** Additional functions for GNUStep
/** Additional functions and macros for GNUStep
Copyright (C) 2005 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <rfm@gnu.org>
@ -26,24 +26,36 @@
#ifndef __GSFunctions_h_GNUSTEP_BASE_INCLUDE
#define __GSFunctions_h_GNUSTEP_BASE_INCLUDE
#include "GNUstepBase/GSVersionMacros.h"
#include "GNUstepBase/GNUstep.h"
#include "GNUstepBase/preface.h"
#include "GNUstepBase/GSObjCRuntime.h"
#include "GNUstepBase/GNUstep.h"
#warning "deprecated header ... will be removed in a later release"
#if defined(__cplusplus)
extern "C" {
#endif
#define GSLocalizedStringFromTableInFramework(key, tbl, fpth, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" \
table: [bundle pathForGNUstepResource:(tbl) ofType: nil inDirectory: (fpth)]
/* Now Support for Quick Localization */
/* The quickest possible way to localize a string:
NSLog (_(@"New Game"));
Please make use of the longer functions taking a comment when you
get the time to localize seriously your code.
*/
#if GS_API_VERSION(GS_API_NONE,011500)
@class NSArray;
@class NSString;
/**
* Try to locate file/directory (aName).(anExtension) in paths.
* Will return the first found or nil if nothing is found.
* Will return the first found or nil if nothing is found.<br />
* Deprecated ... may be removed in later release.
*/
GS_EXPORT NSString *GSFindNamedFile(NSArray *paths, NSString *aName,
NSString *anExtension);

View file

@ -529,157 +529,6 @@ GS_EXPORT NSString* const NSLoadedClasses;
#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
[bundle localizedStringForKey:(key) value:@"" table:(tbl)]
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
#define NSLocalizedStringFromTableInFramework(key, tbl, fpth, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" \
table: [bundle pathForGNUstepResource:(tbl) ofType: nil inDirectory: (fpth)]
#endif /* GNUSTEP */
/* Now Support for Quick Localization */
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
/* The quickest possible way to localize a string:
NSLog (_(@"New Game"));
Please make use of the longer functions taking a comment when you
get the time to localize seriously your code.
*/
/**
* <p>
* This function (macro) is a GNUstep extension.
* </p>
* <p>
* <code>_(@"My string to translate")</code>
* </p>
* <p>
* is exactly the same as
* </p>
* <p>
* <code>NSLocalizedString (@"My string to translate", @"")</code>
* </p>
* <p>
* It is useful when you need to translate an application
* very quickly, as you just need to enclose all strings
* inside <code>_()</code>. But please note that when you
* use this macro, you are not taking advantage of comments
* for the translator, so consider using
* <code>NSLocalizedString</code> instead when you need a
* comment.
* </p>
*/
#define _(X) NSLocalizedString (X, @"")
/* The quickest possible way to localize a static string:
static NSString *string = __(@"New Game");
NSLog (_(string)); */
/**
* <p>
* This function (macro) is a GNUstep extension.
* </p>
* <p>
* <code>__(@"My string to translate")</code>
* </p>
* <p>
* is exactly the same as
* </p>
* <p>
* <code>NSLocalizedStaticString (@"My string to translate", @"")</code>
* </p>
* <p>
* It is useful when you need to translate an application very
* quickly. You would use it as follows for static strings:
* </p>
* <p>
* <code>
* NSString *message = __(@"Hello there");
* ... more code ...
* NSLog (_(messages));
* </code>
* </p>
* <p>
* But please note that when you use this macro, you are not
* taking advantage of comments for the translator, so
* consider using <code>NSLocalizedStaticString</code>
* instead when you need a comment.
* </p>
*/
#define __(X) X
/* The better way for a static string, with a comment - use as follows -
static NSString *string = NSLocalizedStaticString (@"New Game",
@"Menu Option");
NSLog (_(string));
If you need anything more complicated than this, please initialize
the static strings manually.
*/
/**
* <p>
* This function (macro) is a GNUstep extensions, and it is used
* to localize static strings. Here is an example of a static
* string:
* </p>
* <p>
* <code>
* NSString *message = @"Hi there";
* ... some code ...
* NSLog (message);
* </code>
* </p>
* <p>
* This string can not be localized using the standard
* openstep functions/macros. By using this gnustep extension,
* you can localize it as follows:
* </p>
* <p>
* <code>
* NSString *message = NSLocalizedStaticString (@"Hi there",
* @"Greeting");
*
* ... some code ...
*
* NSLog (NSLocalizedString (message, @""));
* </code>
* </p>
* <p>
* When the tools generate the
* <code>Localizable.strings</code> file from the source
* code, they will ignore the <code>NSLocalizedString</code>
* call while they will extract the string (and the comment)
* to localize from the <code>NSLocalizedStaticString</code>
* call.
* </p>
* <p>
* When the code is compiled, instead, the
* <code>NSLocalizedStaticString</code> call is ignored (discarded,
* it is a macro which simply expands to <code>key</code>), while
* the <code>NSLocalizedString</code> will actually look up the
* string for translation in the <code>Localizable.strings</code>
* file.
* </p>
* <p>
* 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.
* </p>
*/
#define NSLocalizedStaticString(key, comment) key
#endif /* GS_API_NONE */
#if defined(__cplusplus)
}

View file

@ -27,11 +27,18 @@
#ifndef __NSObject_h_GNUSTEP_BASE_INCLUDE
#define __NSObject_h_GNUSTEP_BASE_INCLUDE
#import <Foundation/NSObjCRuntime.h>
#import <objc/objc.h>
#import <objc/typedstream.h>
#import <Foundation/NSZone.h>
#ifndef GS_WITH_GC
#define GS_WITH_GC 0
#endif
#import <GNUstepBase/GNUstep.h>
#if defined(__cplusplus)
extern "C" {
#endif
@ -408,190 +415,6 @@ GS_EXPORT NSRecursiveLock *gnustep_global_lock;
inModes: (NSArray*)modes;
@end
/*
* RETAIN(), RELEASE(), and AUTORELEASE() are placeholders for the
* future day when we have garbage collecting.
*/
#ifndef GS_WITH_GC
#define GS_WITH_GC 0
#endif
#if GS_WITH_GC
#ifndef RETAIN
#define RETAIN(object) ((id)object)
#endif
#ifndef RELEASE
#define RELEASE(object)
#endif
#ifndef AUTORELEASE
#define AUTORELEASE(object) ((id)object)
#endif
#ifndef TEST_RETAIN
#define TEST_RETAIN(object) ((id)object)
#endif
#ifndef TEST_RELEASE
#define TEST_RELEASE(object)
#endif
#ifndef TEST_AUTORELEASE
#define TEST_AUTORELEASE(object) ((id)object)
#endif
#ifndef ASSIGN
#define ASSIGN(object,value) (object = value)
#endif
#ifndef ASSIGNCOPY
#define ASSIGNCOPY(object,value) (object = [value copy])
#endif
#ifndef DESTROY
#define DESTROY(object) (object = nil)
#endif
#ifndef CREATE_AUTORELEASE_POOL
#define CREATE_AUTORELEASE_POOL(X)
#endif
#ifndef RECREATE_AUTORELEASE_POOL
#define RECREATE_AUTORELEASE_POOL(X)
#endif
#define IF_NO_GC(X)
#else
#ifndef RETAIN
/**
* Basic retain operation ... calls [NSObject-retain]
*/
#define RETAIN(object) [object retain]
#endif
#ifndef RELEASE
/**
* Basic release operation ... calls [NSObject-release]
*/
#define RELEASE(object) [object release]
#endif
#ifndef AUTORELEASE
/**
* Basic autorelease operation ... calls [NSObject-autorelease]
*/
#define AUTORELEASE(object) [object autorelease]
#endif
#ifndef TEST_RETAIN
/**
* Tested retain - only invoke the
* objective-c method if the receiver is not nil.
*/
#define TEST_RETAIN(object) ({\
id __object = (id)(object); (__object != nil) ? [__object retain] : nil; })
#endif
#ifndef TEST_RELEASE
/**
* Tested release - only invoke the
* objective-c method if the receiver is not nil.
*/
#define TEST_RELEASE(object) ({\
id __object = (id)(object); if (__object != nil) [__object release]; })
#endif
#ifndef TEST_AUTORELEASE
/**
* Tested autorelease - only invoke the
* objective-c method if the receiver is not nil.
*/
#define TEST_AUTORELEASE(object) ({\
id __object = (id)(object); (__object != nil) ? [__object autorelease] : nil; })
#endif
#ifndef ASSIGN
/**
* ASSIGN(object,value) assigns the value to the object with
* appropriate retain and release operations.
*/
#define ASSIGN(object,value) ({\
id __value = (id)(value); \
id __object = (id)(object); \
if (__value != __object) \
{ \
if (__value != nil) \
{ \
[__value retain]; \
} \
object = __value; \
if (__object != nil) \
{ \
[__object release]; \
} \
} \
})
#endif
#ifndef ASSIGNCOPY
/**
* ASSIGNCOPY(object,value) assigns a copy of the value to the object
* with release of the original.
*/
#define ASSIGNCOPY(object,value) ({\
id __value = (id)(value); \
id __object = (id)(object); \
if (__value != __object) \
{ \
if (__value != nil) \
{ \
__value = [__value copy]; \
} \
object = __value; \
if (__object != nil) \
{ \
[__object release]; \
} \
} \
})
#endif
#ifndef DESTROY
/**
* DESTROY() is a release operation which also sets the variable to be
* a nil pointer for tidiness - we can't accidentally use a DESTROYED
* object later. It also makes sure to set the variable to nil before
* releasing the object - to avoid side-effects of the release trying
* to reference the object being released through the variable.
*/
#define DESTROY(object) ({ \
if (object) \
{ \
id __o = object; \
object = nil; \
[__o release]; \
} \
})
#endif
#ifndef CREATE_AUTORELEASE_POOL
/**
* Declares an autorelease pool variable and creates and initialises
* an autorelease pool object.
*/
#define CREATE_AUTORELEASE_POOL(X) \
NSAutoreleasePool *(X) = [NSAutoreleasePool new]
#endif
#ifndef RECREATE_AUTORELEASE_POOL
/**
* Similar, but allows reuse of variables. Be sure to use DESTROY()
* so the object variable stays nil.
*/
#define RECREATE_AUTORELEASE_POOL(X) \
if (X == nil) \
(X) = [NSAutoreleasePool new]
#endif
#define IF_NO_GC(X) X
#endif
#if defined(__cplusplus)
}
#endif

View file

@ -126,6 +126,7 @@ NSZone.h
BaseAdditions_AGSDOC_FILES = \
../Documentation/BaseAdditions.gsdoc \
GNUstep.h \
GSCategories.h \
GSIArray.h \
GSIMap.h \