2002-11-15 22:57:05 +00:00
|
|
|
/**
|
|
|
|
EOSortOrdering.m <title>EOSortOrdering</title>
|
|
|
|
|
2005-08-17 08:07:57 +00:00
|
|
|
Copyright (C) 2000-2002,2003,2004,2005 Free Software Foundation, Inc.
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2006-09-14 16:06:21 +00:00
|
|
|
Author: Mirko Viviani <mirko.viviani@gmail.com>
|
2002-11-15 22:57:05 +00:00
|
|
|
Date: February 2000
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
$Date$
|
|
|
|
|
|
|
|
<abstract></abstract>
|
|
|
|
|
|
|
|
This file is part of the GNUstep Database Library.
|
|
|
|
|
|
|
|
<license>
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
2007-07-12 06:39:22 +00:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
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 Library General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
2005-08-17 08:07:57 +00:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-11-15 22:57:05 +00:00
|
|
|
</license>
|
|
|
|
**/
|
|
|
|
|
2002-12-31 16:25:21 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
RCS_ID("$Id$")
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2004-03-19 16:41:21 +00:00
|
|
|
#ifdef GNUSTEP
|
2003-03-31 00:24:15 +00:00
|
|
|
#include <Foundation/NSCoder.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
#else
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#endif
|
2002-12-30 22:10:43 +00:00
|
|
|
|
2003-07-11 19:04:05 +00:00
|
|
|
#ifndef GNUSTEP
|
2003-08-25 20:01:59 +00:00
|
|
|
#include <GNUstepBase/GNUstep.h>
|
2003-07-11 19:04:05 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-31 00:24:15 +00:00
|
|
|
#include <EOControl/EOSortOrdering.h>
|
|
|
|
#include <EOControl/EOKeyValueCoding.h>
|
|
|
|
#include <EOControl/EOKeyValueArchiver.h>
|
2005-03-02 14:10:36 +00:00
|
|
|
#include <EOControl/EONull.h>
|
2003-03-31 00:24:15 +00:00
|
|
|
#include <EOControl/EODebug.h>
|
* EOControl/EOPriv.h/m: Split into...
* EOControl/EOPrivat.h/m: ... and ...
* EOAccess/EOPrivat.h/m: ... files.
* EOAccess/EOAdaptorChannel.m: Include new privat header.
* EOAccess/EOAttribute.m, EOAccess/EODatabase.m,
* EOAccess/EODatabaseChannel.m, EOAccess/EOEntity.m,
* EOAccess/EORelationship.m, EOAccess/EOSQLExpression.m,
* EOAccess/EOSQLQualifier.m, EOAccess/EOUtilities.m: Ditto.
(+initialize): Call new private function.
* EOAccess/EODatabaseContext.m: Ditto.
(EODatabaseContext_snapshotForGlobalIDWithImpPtr)
(EODatabaseContext_globalIDForObjectWithImpPtr): Move to
EOPrivate.m.
* EOAccess/EODatabaseContextPriv.h:
(EODatabaseContext_snapshotForGlobalIDWithImpPtr)
(EODatabaseContext_globalIDForObjectWithImpPtr): Move to
EOPrivate.h.
* EOAccess/GNUmakefile: Compile EOPrivate.m.
* EOControl/EOClassDescription.m, EOControl/EOGenericRecord.m
* EOControl/EOKeyGlobalID.m, EOControl/EOKeyValueCoding.m
* EOControl/EOKeyValueQualifier.m, EOControl/EONSAddOns.m
* EOControl/EOSortOrdering.m: Include new private header.
* EOControl/EOEditingContext.h/m: Ditto.
(EOEditingContext_objectForGlobalIDWithImpPtr)
(EOEditingContext_recordObjectGlobalIDWithImpPtr): Move to
EOPrivate.h/m.
* EOControl/EOMutableKnownKeyDictionary.h/m: Include new
private header.
(EOMKKD_objectForKeyWithImpPtr, EOMKKD_setObjectForKeyWithImpPtr)
(EOMKKD_removeObjectForKeyWithImpPtr, EOMKKD_hasKeyWithImpPtr)
(EOMKKD_indexForKeyWithImpPtr)
(EOMKKDInitializer_indexForKeyWithImpPtr): Move to EOPrivate.m
* EOControl/EOFault.m: (+isFault:): Update comment.
* EOControl/GNUmakefile: Build EOPrivate.m instead of EOPriv.m.
Do not install private header.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20759 72102866-910b-0410-8b05-ffd578937521
2005-02-20 10:52:57 +00:00
|
|
|
|
|
|
|
#include "EOPrivate.h"
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
@implementation EOSortOrdering
|
|
|
|
|
* EOAccess/EOAdaptor.m:
o optimization in 'for' loops
* EOAccess/EODatabase.m:
o include <EOCOntrol/EOPriv.h>
o replaced isNilOrEONull() by _isNilOrEONull()
* EOAccess/EODatabaseContext.h:
o added _snapshotForGlobalIDIMP
* EOAccess/EODatabaseContext.m:
o commented NSEmitTODO in
-objectsForSourceGlobalID:relationshipName:editingContext:
o added beter exception format in
qualifierForLockingAttributes:primaryKeyAttributes:entity:snapshot:
o fix compiler warning in -relayPrimaryKey:object:entity:
o logs
o optimizations in -objectsWithFetchSpecification:editingContext:
o replaced isNilOrEONull() by _isNilOrEONull()
o replace [EOFault isFault:] by _isFault()
o use _snapshotForGlobalIDIMP
o IMP usage optimization
* EOAccess/EOAttribute.[hm]:
o added EOAdaptorUnknownType
o added _adaptorValueType and avoid recomputing it each time
o added _valueTypeChar to avoid string comparaisons
o use EOPriv classes declarations
o Temporary reverted David changes in
-adaptorValueByConvertingAttributeValue
* EOAccess/EOAttributePriv.h:
o added _valueTypeChar to avoid string comparaisons
* EOAccess/EOEntityPriv.h:
o moved -attributeForPath: and -relationshipForPath: to
EOEntityGDL2Additions category
* EOAccess/EOEntity.h:
o moved private -attributeForPath: and -relationshipForPath: to
EOEntityGDL2Additions category
* EOAccess/EOEntity.m:
o better exception in classProperties
o fix compiler warning in -setClassProperties:,
-setPrimaryKeyAttributes:,
-setAttributesUsedForLocking:
o moved -attributeForPath: and -relationshipForPath: to
EOEntityGDL2Additions category
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOAccess/EOSQLExpression.m:
o optimization in -tableListWithRootEntity:
o optimization in -formatSQLString:format:
o optimization in +sqlPatternFromShellPattern:
o optimization in +sqlPatternFromShellPattern:withEscapeCharacter:
o fix in -sqlStringForKeyValueQualifier:
o added log in -sqlStringForKeyValueQualifier: for not handled
readFormat
o added log -addInsertListAttribute:value: for not handled
writeFormat
o added log -addUpdateListAttribute:value: for not handled
writeFormat
o changed EOFLOGObjectFnStart to EOFLOGObjectFnStartCond
o changed EOFLOGObjectFnStop to EOFLOGObjectFnStopCond
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOAccess/EOSQLQualifier.m:
o implemented EOKeyComparisonQualifier
-schemaBasedQualifierWithRootEntity
* EOAccess/EOUtilities.m:
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOControl/EOPriv.[hm]:
o added. Contains various classes/selectors/IMPs
* EOControl/EOClassDescription.m:
o handle EONull case in -propagateDeleteForObject:editingContext:,
-addObject:toPropertyWithKey:, -snapshot,
-removeObject:fromPropertyWithKey:,
_setObject:forBothSidesOfRelationshipWithKey:,
addObject:toBothSidesOfRelationshipWithKey:,
-removeObject:fromBothSidesOfRelationshipWithKey:
o fix compiler warning in -dictionaryForInstanceProperties,
-shallowCopy, -updateFromSnapshot:, -snapshot
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
o replaced isNilOrEONull() by _isNilOrEONull()
o fix in -validateForSave
o rewritten -validateValue:forKey: selector build
* EOControl/EOEditingContext.h:
o added -hasUnprocessedChanges
* EOControl/EOEditingContext.m:
o added -hasUnprocessedChanges
o added NS_DURING,... to catch exceptions
o replace [EOFault isFault:] by _isFault()
o IMP usage optimization
* EOControl/EOKeyGlobalID.m:
o replaced isNilOrEONull() by _isNilOrEONull()
o include <EOCOntrol/EOPriv.h>
* EOControl/EOGenericRecord.m:
o partially rewritten -description
o include <EOCOntrol/EOPriv.h>
o replaced isNilOrEONull() by _isNilOrEONull()
o replace [EOFault isFault:] by _isFault()
o changed variable name type of
_infoForInstanceVariableNamed:retType:retSize:retOffset:
o rewritten valueForKey:,... to use cString NSKeyValueCoding
* EOControl/EOKeyValueCoding.m:
o changed NSAssert in NSArray -valueForKey:
o optimization in NSDictionary -takeValue:forKeyPath:isSmart:
o optimization in NSDictionary -takeStoredValue:forKeyPath:
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
o include <EOCOntrol/EOPriv.h>
* EOControl/EOKeyValueQualifier.m:
o fixes for EONull/nil in -evaluateWithObject:
o replaced [EONull null] by GDL2EONull
o include <EOCOntrol/EOPriv.h>
* EOControl/EOSortOrdering.m:
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOAdaptors/Postgres95SQLExpression.m:
o float formatting in +formatValue:forAttribute:
o added -externalNameQuoteCharacter
o added +sqlPatternFromShellPattern:
o added +sqlPatternFromShellPattern:withEscapeCharacter:
o replaced isNilOrEONull() by _isNilOrEONull()
* EOAdaptors/Postgres95Channel.m:
o logs
* EOAdaptors/Postgres95Values.m:
o logs
o fix in +setPostgres95Format:
o fix calendard format to handle timezone (%z)
o optimizations
* EOControl/EOMutableKnownKeyDictionary.m
o removed EOMKKDArrayMapping
+dictionaryFromDictionary:subsetMapping:
o include <EOCOntrol/EOPriv.h>
o replaced isNilOrEONull() by _isNilOrEONull()
* EOControl/EONSAddOns.[hm]:
o added NSString(ShellPattern)
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20687 72102866-910b-0410-8b05-ffd578937521
2005-02-11 17:31:29 +00:00
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
static BOOL initialized=NO;
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
initialized=YES;
|
|
|
|
|
* EOAccess/EOAttribute.m, EOAccess/EODatabaseContext.m,
* EOAccess/EOEntity.m, EOAccess/EOSQLExpression.m
* EOAccess/EOPrivate.h, EOAccess/EOPrivate.m,
* EOAccess/EOSQLQualifier.m, EOAccess/EOUtilities.m
* EOControl/EOClassDescription.m, EOControl/EOEditingContext.m
* EOControl/EOGenericRecord.m, EOControl/EOKeyGlobalID.m
* EOControl/EOKeyValueCoding.m,
* EOControl/EOKeyValueQualifier.m
* EOControl/EOMutableKnownKeyDictionary.m,
* EOControl/EOPrivate.h, EOControl/EOPrivate.m
Unify GDL2 identifiers with GDL2_ prefix. Replace
GDL2NSClass_alloc with GDL2_alloc(NSClass). Replace
GDL2NSClassWith* calls with
AUTORELEASE([GDL2_alloc(NSCLass) initWith* calls]).
Rename GDL2PrivInit to GDL2_PrivateInit.
(GDL2_NSArray, GDL2_NSMutableArray_allocWithZoneIMP)
(GDL2_NSMutableDictionary_allocWithZoneIMP): New globals.
(GDL2_alloc): New macro.
(GDL2NSString_alloc, GDL2NSDecimalNumber_alloc)
(GDL2NSNumber_alloc, GDL2NSCalendarDate_alloc, GDL2NSData_alloc)
(GDL2DataWithBytesAndLength, GDL2MutableArrayWithCapacity)
(GDL2MutableArrayWithArray, GDL2MutableArray, GDL2Array)
(GDL2MutableDictionaryWithCapacity): Remove.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20779 72102866-910b-0410-8b05-ffd578937521
2005-02-22 16:14:03 +00:00
|
|
|
GDL2_PrivateInit();
|
* EOAccess/EOAdaptor.m:
o optimization in 'for' loops
* EOAccess/EODatabase.m:
o include <EOCOntrol/EOPriv.h>
o replaced isNilOrEONull() by _isNilOrEONull()
* EOAccess/EODatabaseContext.h:
o added _snapshotForGlobalIDIMP
* EOAccess/EODatabaseContext.m:
o commented NSEmitTODO in
-objectsForSourceGlobalID:relationshipName:editingContext:
o added beter exception format in
qualifierForLockingAttributes:primaryKeyAttributes:entity:snapshot:
o fix compiler warning in -relayPrimaryKey:object:entity:
o logs
o optimizations in -objectsWithFetchSpecification:editingContext:
o replaced isNilOrEONull() by _isNilOrEONull()
o replace [EOFault isFault:] by _isFault()
o use _snapshotForGlobalIDIMP
o IMP usage optimization
* EOAccess/EOAttribute.[hm]:
o added EOAdaptorUnknownType
o added _adaptorValueType and avoid recomputing it each time
o added _valueTypeChar to avoid string comparaisons
o use EOPriv classes declarations
o Temporary reverted David changes in
-adaptorValueByConvertingAttributeValue
* EOAccess/EOAttributePriv.h:
o added _valueTypeChar to avoid string comparaisons
* EOAccess/EOEntityPriv.h:
o moved -attributeForPath: and -relationshipForPath: to
EOEntityGDL2Additions category
* EOAccess/EOEntity.h:
o moved private -attributeForPath: and -relationshipForPath: to
EOEntityGDL2Additions category
* EOAccess/EOEntity.m:
o better exception in classProperties
o fix compiler warning in -setClassProperties:,
-setPrimaryKeyAttributes:,
-setAttributesUsedForLocking:
o moved -attributeForPath: and -relationshipForPath: to
EOEntityGDL2Additions category
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOAccess/EOSQLExpression.m:
o optimization in -tableListWithRootEntity:
o optimization in -formatSQLString:format:
o optimization in +sqlPatternFromShellPattern:
o optimization in +sqlPatternFromShellPattern:withEscapeCharacter:
o fix in -sqlStringForKeyValueQualifier:
o added log in -sqlStringForKeyValueQualifier: for not handled
readFormat
o added log -addInsertListAttribute:value: for not handled
writeFormat
o added log -addUpdateListAttribute:value: for not handled
writeFormat
o changed EOFLOGObjectFnStart to EOFLOGObjectFnStartCond
o changed EOFLOGObjectFnStop to EOFLOGObjectFnStopCond
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOAccess/EOSQLQualifier.m:
o implemented EOKeyComparisonQualifier
-schemaBasedQualifierWithRootEntity
* EOAccess/EOUtilities.m:
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOControl/EOPriv.[hm]:
o added. Contains various classes/selectors/IMPs
* EOControl/EOClassDescription.m:
o handle EONull case in -propagateDeleteForObject:editingContext:,
-addObject:toPropertyWithKey:, -snapshot,
-removeObject:fromPropertyWithKey:,
_setObject:forBothSidesOfRelationshipWithKey:,
addObject:toBothSidesOfRelationshipWithKey:,
-removeObject:fromBothSidesOfRelationshipWithKey:
o fix compiler warning in -dictionaryForInstanceProperties,
-shallowCopy, -updateFromSnapshot:, -snapshot
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
o replaced isNilOrEONull() by _isNilOrEONull()
o fix in -validateForSave
o rewritten -validateValue:forKey: selector build
* EOControl/EOEditingContext.h:
o added -hasUnprocessedChanges
* EOControl/EOEditingContext.m:
o added -hasUnprocessedChanges
o added NS_DURING,... to catch exceptions
o replace [EOFault isFault:] by _isFault()
o IMP usage optimization
* EOControl/EOKeyGlobalID.m:
o replaced isNilOrEONull() by _isNilOrEONull()
o include <EOCOntrol/EOPriv.h>
* EOControl/EOGenericRecord.m:
o partially rewritten -description
o include <EOCOntrol/EOPriv.h>
o replaced isNilOrEONull() by _isNilOrEONull()
o replace [EOFault isFault:] by _isFault()
o changed variable name type of
_infoForInstanceVariableNamed:retType:retSize:retOffset:
o rewritten valueForKey:,... to use cString NSKeyValueCoding
* EOControl/EOKeyValueCoding.m:
o changed NSAssert in NSArray -valueForKey:
o optimization in NSDictionary -takeValue:forKeyPath:isSmart:
o optimization in NSDictionary -takeStoredValue:forKeyPath:
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
o include <EOCOntrol/EOPriv.h>
* EOControl/EOKeyValueQualifier.m:
o fixes for EONull/nil in -evaluateWithObject:
o replaced [EONull null] by GDL2EONull
o include <EOCOntrol/EOPriv.h>
* EOControl/EOSortOrdering.m:
o include <EOCOntrol/EOPriv.h>
o replaced [EONull null] by GDL2EONull
* EOAdaptors/Postgres95SQLExpression.m:
o float formatting in +formatValue:forAttribute:
o added -externalNameQuoteCharacter
o added +sqlPatternFromShellPattern:
o added +sqlPatternFromShellPattern:withEscapeCharacter:
o replaced isNilOrEONull() by _isNilOrEONull()
* EOAdaptors/Postgres95Channel.m:
o logs
* EOAdaptors/Postgres95Values.m:
o logs
o fix in +setPostgres95Format:
o fix calendard format to handle timezone (%z)
o optimizations
* EOControl/EOMutableKnownKeyDictionary.m
o removed EOMKKDArrayMapping
+dictionaryFromDictionary:subsetMapping:
o include <EOCOntrol/EOPriv.h>
o replaced isNilOrEONull() by _isNilOrEONull()
* EOControl/EONSAddOns.[hm]:
o added NSString(ShellPattern)
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20687 72102866-910b-0410-8b05-ffd578937521
2005-02-11 17:31:29 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Returns an autoreleased EOSortOrdering initilaized with key and selector.
|
|
|
|
* The selector should take an id as an argument and return an
|
|
|
|
* NSComparisonResult value. This method calls
|
|
|
|
* [EOSortOrdering-initWithKey:selector:].
|
|
|
|
*/
|
|
|
|
+ (EOSortOrdering *) sortOrderingWithKey: (NSString *)key
|
|
|
|
selector: (SEL)selector
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-02-20 13:58:43 +00:00
|
|
|
return AUTORELEASE([[self alloc] initWithKey: key
|
|
|
|
selector: selector]);
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
[coder encodeValueOfObjCType: @encode(SEL) at: _selector];
|
|
|
|
[coder encodeObject: _key];
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
|
|
|
|
[coder decodeValueOfObjCType: @encode(SEL) at: &_selector];
|
2003-02-04 15:17:07 +00:00
|
|
|
_key = RETAIN([coder decodeObject]);
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-03-31 00:24:15 +00:00
|
|
|
- (id)copyWithZone:(NSZone *)zone
|
|
|
|
{
|
|
|
|
if (NSShouldRetainWithZone(self, zone))
|
|
|
|
{
|
|
|
|
return RETAIN(self);
|
|
|
|
}
|
|
|
|
return [[[self class] allocWithZone: zone]
|
|
|
|
initWithKey: _key selector: _selector];
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**<init />
|
|
|
|
* Initializes the receiver with a copy of key and the selector. The selector
|
|
|
|
* should take an id as an argument and return an NSComparisonResult value.
|
|
|
|
*/
|
|
|
|
- (id) initWithKey: (NSString *)key selector: (SEL)selector
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
ASSIGNCOPY(_key, key);
|
2002-11-15 22:57:05 +00:00
|
|
|
_selector = selector;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Returns the key of the receiver.
|
|
|
|
*/
|
|
|
|
- (NSString *) key
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
return _key;
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Returns the selector of the receiver. The selector should take an id as
|
|
|
|
* an argument and return an NSComparisonResult value.
|
|
|
|
*/
|
|
|
|
- (SEL) selector
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
return _selector;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithKeyValueUnarchiver: (EOKeyValueUnarchiver*)unarchiver
|
|
|
|
{
|
|
|
|
EOFLOGObjectFnStartOrCond(@"EOSortOrdering");
|
|
|
|
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
NSString *selectorName;
|
|
|
|
|
|
|
|
ASSIGN(_key, [unarchiver decodeObjectForKey: @"key"]);
|
|
|
|
selectorName = [unarchiver decodeObjectForKey: @"selectorName"];
|
|
|
|
|
|
|
|
if (selectorName)
|
|
|
|
_selector = NSSelectorFromString(selectorName);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOFLOGObjectFnStopOrCond(@"EOSortOrdering");
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-03-31 00:24:15 +00:00
|
|
|
- (void) encodeWithKeyValueArchiver: (EOKeyValueArchiver*)archiver
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
[archiver encodeObject: _key forKey: @"key"];
|
|
|
|
if (_selector)
|
|
|
|
{
|
|
|
|
[archiver encodeObject: NSStringFromSelector(_selector)
|
|
|
|
forKey: @"selectorName"];
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Returns a human readable representation of the receiver.
|
|
|
|
*/
|
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"<%@ %p - %@ %@>",
|
|
|
|
NSStringFromClass(isa),
|
|
|
|
(void*)self,
|
|
|
|
_key,
|
|
|
|
NSStringFromSelector(_selector)];
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSArray (EOKeyBasedSorting)
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
static NSComparisonResult
|
|
|
|
compareUsingSortOrderings(id left,
|
|
|
|
id right,
|
|
|
|
void* vpSortOrders)
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-02-20 13:58:43 +00:00
|
|
|
NSArray *sortOrders = (NSArray *)vpSortOrders;
|
|
|
|
NSComparisonResult r = NSOrderedSame;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int sortOrdCnt = [sortOrders count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/* Loop over all sort orderings until we have an ordering difference. */
|
|
|
|
for (i=0; (r == NSOrderedSame) && (i < sortOrdCnt); i++)
|
|
|
|
{
|
|
|
|
EOSortOrdering *sortOrd = [sortOrders objectAtIndex: i];
|
|
|
|
NSString *key = [sortOrd key];
|
|
|
|
SEL compSel = [sortOrd selector];
|
2003-06-26 08:20:30 +00:00
|
|
|
id leftVal = [left valueForKeyPath: key];
|
|
|
|
id rightVal = [right valueForKeyPath: key];
|
2003-02-20 13:58:43 +00:00
|
|
|
BOOL inverted = NO;
|
|
|
|
NSComparisonResult (*imp)(id, SEL, id);
|
|
|
|
|
|
|
|
/* Use EONull instead of nil. */
|
* EOAccess/EOAttribute.m, EOAccess/EODatabaseContext.m,
* EOAccess/EOEntity.m, EOAccess/EOSQLExpression.m
* EOAccess/EOPrivate.h, EOAccess/EOPrivate.m,
* EOAccess/EOSQLQualifier.m, EOAccess/EOUtilities.m
* EOControl/EOClassDescription.m, EOControl/EOEditingContext.m
* EOControl/EOGenericRecord.m, EOControl/EOKeyGlobalID.m
* EOControl/EOKeyValueCoding.m,
* EOControl/EOKeyValueQualifier.m
* EOControl/EOMutableKnownKeyDictionary.m,
* EOControl/EOPrivate.h, EOControl/EOPrivate.m
Unify GDL2 identifiers with GDL2_ prefix. Replace
GDL2NSClass_alloc with GDL2_alloc(NSClass). Replace
GDL2NSClassWith* calls with
AUTORELEASE([GDL2_alloc(NSCLass) initWith* calls]).
Rename GDL2PrivInit to GDL2_PrivateInit.
(GDL2_NSArray, GDL2_NSMutableArray_allocWithZoneIMP)
(GDL2_NSMutableDictionary_allocWithZoneIMP): New globals.
(GDL2_alloc): New macro.
(GDL2NSString_alloc, GDL2NSDecimalNumber_alloc)
(GDL2NSNumber_alloc, GDL2NSCalendarDate_alloc, GDL2NSData_alloc)
(GDL2DataWithBytesAndLength, GDL2MutableArrayWithCapacity)
(GDL2MutableArrayWithArray, GDL2MutableArray, GDL2Array)
(GDL2MutableDictionaryWithCapacity): Remove.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20779 72102866-910b-0410-8b05-ffd578937521
2005-02-22 16:14:03 +00:00
|
|
|
leftVal = (leftVal != nil)?(leftVal) :(GDL2_EONull);
|
|
|
|
rightVal = (rightVal != nil)?(rightVal):(GDL2_EONull);
|
2003-02-20 13:58:43 +00:00
|
|
|
|
|
|
|
/* Insure that EONull is not the parameter for
|
|
|
|
comparisons with other classes. */
|
* EOAccess/EOAttribute.m, EOAccess/EODatabaseContext.m,
* EOAccess/EOEntity.m, EOAccess/EOSQLExpression.m
* EOAccess/EOPrivate.h, EOAccess/EOPrivate.m,
* EOAccess/EOSQLQualifier.m, EOAccess/EOUtilities.m
* EOControl/EOClassDescription.m, EOControl/EOEditingContext.m
* EOControl/EOGenericRecord.m, EOControl/EOKeyGlobalID.m
* EOControl/EOKeyValueCoding.m,
* EOControl/EOKeyValueQualifier.m
* EOControl/EOMutableKnownKeyDictionary.m,
* EOControl/EOPrivate.h, EOControl/EOPrivate.m
Unify GDL2 identifiers with GDL2_ prefix. Replace
GDL2NSClass_alloc with GDL2_alloc(NSClass). Replace
GDL2NSClassWith* calls with
AUTORELEASE([GDL2_alloc(NSCLass) initWith* calls]).
Rename GDL2PrivInit to GDL2_PrivateInit.
(GDL2_NSArray, GDL2_NSMutableArray_allocWithZoneIMP)
(GDL2_NSMutableDictionary_allocWithZoneIMP): New globals.
(GDL2_alloc): New macro.
(GDL2NSString_alloc, GDL2NSDecimalNumber_alloc)
(GDL2NSNumber_alloc, GDL2NSCalendarDate_alloc, GDL2NSData_alloc)
(GDL2DataWithBytesAndLength, GDL2MutableArrayWithCapacity)
(GDL2MutableArrayWithArray, GDL2MutableArray, GDL2Array)
(GDL2MutableDictionaryWithCapacity): Remove.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20779 72102866-910b-0410-8b05-ffd578937521
2005-02-22 16:14:03 +00:00
|
|
|
if (rightVal == GDL2_EONull)
|
2003-02-20 13:58:43 +00:00
|
|
|
{
|
|
|
|
rightVal = leftVal;
|
* EOAccess/EOAttribute.m, EOAccess/EODatabaseContext.m,
* EOAccess/EOEntity.m, EOAccess/EOSQLExpression.m
* EOAccess/EOPrivate.h, EOAccess/EOPrivate.m,
* EOAccess/EOSQLQualifier.m, EOAccess/EOUtilities.m
* EOControl/EOClassDescription.m, EOControl/EOEditingContext.m
* EOControl/EOGenericRecord.m, EOControl/EOKeyGlobalID.m
* EOControl/EOKeyValueCoding.m,
* EOControl/EOKeyValueQualifier.m
* EOControl/EOMutableKnownKeyDictionary.m,
* EOControl/EOPrivate.h, EOControl/EOPrivate.m
Unify GDL2 identifiers with GDL2_ prefix. Replace
GDL2NSClass_alloc with GDL2_alloc(NSClass). Replace
GDL2NSClassWith* calls with
AUTORELEASE([GDL2_alloc(NSCLass) initWith* calls]).
Rename GDL2PrivInit to GDL2_PrivateInit.
(GDL2_NSArray, GDL2_NSMutableArray_allocWithZoneIMP)
(GDL2_NSMutableDictionary_allocWithZoneIMP): New globals.
(GDL2_alloc): New macro.
(GDL2NSString_alloc, GDL2NSDecimalNumber_alloc)
(GDL2NSNumber_alloc, GDL2NSCalendarDate_alloc, GDL2NSData_alloc)
(GDL2DataWithBytesAndLength, GDL2MutableArrayWithCapacity)
(GDL2MutableArrayWithArray, GDL2MutableArray, GDL2Array)
(GDL2MutableDictionaryWithCapacity): Remove.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20779 72102866-910b-0410-8b05-ffd578937521
2005-02-22 16:14:03 +00:00
|
|
|
leftVal = GDL2_EONull;
|
2003-02-20 13:58:43 +00:00
|
|
|
inverted = YES;
|
|
|
|
}
|
2003-02-04 15:17:07 +00:00
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
imp = (NSComparisonResult (*)(id, SEL, id))
|
|
|
|
[leftVal methodForSelector: compSel];
|
|
|
|
NSCAssert3(imp!=NULL,
|
|
|
|
@"Invalid comparison selector:%@ for object:<%@ 0x%x>",
|
|
|
|
NSStringFromSelector(compSel),
|
|
|
|
NSStringFromClass([leftVal class]),
|
|
|
|
leftVal);
|
|
|
|
r = (*imp)(leftVal, compSel, rightVal);
|
|
|
|
|
|
|
|
/* If we inverted the parameters, we must switch the result*/
|
|
|
|
if (inverted == YES)
|
|
|
|
{
|
|
|
|
r = ~r + 1;
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
return r;
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Returns an array contaning the of the objects of the reveiver sorted
|
|
|
|
* according to the provided array of EOSortOrderings.
|
|
|
|
*/
|
|
|
|
- (NSArray *) sortedArrayUsingKeyOrderArray: (NSArray *)orderArray
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
if ([self count] > 1)
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
return [self sortedArrayUsingFunction: compareUsingSortOrderings
|
|
|
|
context: orderArray];
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
2003-02-20 13:58:43 +00:00
|
|
|
else
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
return self;
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSMutableArray (EOKeyBasedSorting)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorts the reveiver according to the provided array of EOSortOrderings.
|
|
|
|
*/
|
|
|
|
- (void) sortUsingKeyOrderArray: (NSArray *)orderArray
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
if ([self count] > 1)
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-02-20 13:58:43 +00:00
|
|
|
[self sortUsingFunction: compareUsingSortOrderings
|
|
|
|
context: orderArray];
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2003-09-10 13:35:32 +00:00
|
|
|
/*
|
|
|
|
This declaration is needed by the compiler to state that
|
|
|
|
eventhough we know not all objects respond to -compare:,
|
|
|
|
we want the compiler to generate code for the given
|
|
|
|
prototype when calling -compare: in the following methods.
|
|
|
|
We do not put this declaration in a header file to avoid
|
|
|
|
the compiler seeing conflicting prototypes in user code.
|
|
|
|
*/
|
|
|
|
@interface NSObject (Comparison)
|
|
|
|
- (NSComparisonResult)compare: (id)other;
|
|
|
|
@end
|
|
|
|
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
@implementation NSObject (EOSortOrderingComparison)
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Default implementation of EOCompareAscending.
|
|
|
|
* This implementation returns the result of compare:.
|
|
|
|
* Concrete classes should either override this method or compare:
|
|
|
|
* to return a meaningful NSComparisonResult.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareAscending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
return [self compare: other];
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Default implementation of EOCompareDescending.
|
|
|
|
* This implementation returns the inverted result of compare:.
|
|
|
|
* Concrete classes should either override this method or compare:
|
|
|
|
* to return a meaningful NSComparisonResult.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareDescending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
NSComparisonResult result = [self compare: other];
|
|
|
|
|
|
|
|
return (~result + 1);
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Default implementation of EOCompareCaseInsensitiveAscending.
|
|
|
|
* This implementation returns the result of compare:.
|
|
|
|
* Concrete classes should either override this method or compare:
|
|
|
|
* to return a meaningful NSComparisonResult.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareCaseInsensitiveAscending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
return [self compare: other];
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Default implementation of EOCompareCaseInsensitiveDescending.
|
|
|
|
* This implementation returns the inverted result of compare:.
|
|
|
|
* Concrete classes should either override this method or compare:
|
|
|
|
* to return a meaningful NSComparisonResult.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareCaseInsensitiveDescending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
NSComparisonResult result = [self compare: other];
|
|
|
|
|
|
|
|
return (~result + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation EONull (EOSortOrderingComparison)
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Implementation of EOCompareAscending for EONull.
|
|
|
|
* When compared to another EONull, return NSOrderedSame.
|
|
|
|
* Otherwise NSOrderdAscening. This leads to EONulls to be at the begining
|
|
|
|
* of arrays sorted with EOCompareAscending.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareAscending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
if (self == other)
|
2002-11-15 22:57:05 +00:00
|
|
|
return NSOrderedSame;
|
|
|
|
|
|
|
|
return NSOrderedAscending;
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Implementation of EOCompareDescending for EONull.
|
|
|
|
* When compared to another EONull, return NSOrderedSame.
|
|
|
|
* Otherwise NSOrderdDescening. This leads to EONulls to be at the end
|
|
|
|
* of arrays sorted with EOCompareDescending.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareDescending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
if (self == other)
|
2002-11-15 22:57:05 +00:00
|
|
|
return NSOrderedSame;
|
|
|
|
|
|
|
|
return NSOrderedDescending;
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Implementation of EOCompareCaseInsensativeAscending for EONull.
|
|
|
|
* When compared to another EONull, return NSOrderedSame.
|
|
|
|
* Otherwise NSOrderdAscening. This leads to EONulls to be at the begining
|
|
|
|
* of arrays sorted with EOCompareCaseInsensitiveAscending.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareCaseInsensitiveAscending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
if (self == other)
|
2002-11-15 22:57:05 +00:00
|
|
|
return NSOrderedSame;
|
|
|
|
|
|
|
|
return NSOrderedAscending;
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Implementation of EOCompareCaseInsensativeDescending for EONull.
|
|
|
|
* When compared to another EONull, return NSOrderedSame.
|
|
|
|
* Otherwise NSOrderdDescening. This leads to EONulls to be at the end
|
|
|
|
* of arrays sorted with EOCompareCaseInsensativeDescending.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareCaseInsensitiveDescending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
if (self == other)
|
2002-11-15 22:57:05 +00:00
|
|
|
return NSOrderedSame;
|
|
|
|
|
|
|
|
return NSOrderedDescending;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
|
2002-11-15 22:57:05 +00:00
|
|
|
@implementation NSString (EOSortOrderingComparison)
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Implementation of EOCompareCaseInsensativeDescending for NSString.
|
|
|
|
* This method simply returns the result
|
|
|
|
* of calling caseInsensitiveCompare:.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareCaseInsensitiveAscending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
return [self caseInsensitiveCompare: other];
|
|
|
|
}
|
|
|
|
|
2003-02-20 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Implementation of EOCompareCaseInsensativeDescending for NSString.
|
|
|
|
* This method simply returns the inverted result
|
|
|
|
* of calling caseInsensitiveCompare:.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compareCaseInsensitiveDescending: (id)other
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
NSComparisonResult result = [self caseInsensitiveCompare: other];
|
|
|
|
|
|
|
|
return (~result + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|