2002-11-15 22:57:05 +00:00
|
|
|
/**
|
|
|
|
EONSAddOns.m <title>EONSAddOns</title>
|
|
|
|
|
2010-04-09 17:44:00 +00:00
|
|
|
Copyright (C) 2000-2002,2003,2004,2005,2006,2007,2010
|
|
|
|
Free Software Foundation, Inc.
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
Author: Manuel Guesdon <mguesdon@orange-concept.com>
|
|
|
|
Date: October 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"
|
|
|
|
|
2004-03-19 16:41:21 +00:00
|
|
|
#ifdef GNUSTEP
|
2003-03-31 00:24:15 +00:00
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
2003-06-24 16:27:01 +00:00
|
|
|
#include <Foundation/NSScanner.h>
|
|
|
|
#include <Foundation/NSCharacterSet.h>
|
2003-03-31 00:24:15 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
#include <Foundation/NSThread.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
#else
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-11 19:04:05 +00:00
|
|
|
#ifndef GNUSTEP
|
2003-08-25 20:01:59 +00:00
|
|
|
#include <GNUstepBase/GNUstep.h>
|
2004-01-29 13:23:22 +00:00
|
|
|
#include <GNUstepBase/GSObjCRuntime.h>
|
2010-04-26 22:05:17 +00:00
|
|
|
#include <GNUstepBase/NSDebug+GNUstepBase.h>
|
2003-07-11 19:04:05 +00:00
|
|
|
#endif
|
2004-05-07 13:14:24 +00:00
|
|
|
#include <GNUstepBase/Unicode.h>
|
2004-02-12 11:07:49 +00:00
|
|
|
#include <GNUstepBase/GSLock.h>
|
2003-07-11 19:04:05 +00:00
|
|
|
|
2003-03-31 00:24:15 +00:00
|
|
|
#include <EOControl/EONSAddOns.h>
|
|
|
|
#include <EOControl/EODebug.h>
|
|
|
|
|
2004-09-28 14:01:01 +00:00
|
|
|
#include <limits.h>
|
2010-04-09 17:44:00 +00:00
|
|
|
#include <assert.h>
|
2004-09-28 14:01:01 +00:00
|
|
|
|
* 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"
|
|
|
|
|
2010-03-15 08:56:06 +00:00
|
|
|
@class GDL2KVCNSObject;
|
|
|
|
@class GDL2KVCNSArray;
|
|
|
|
@class GDL2KVCNSDictionary;
|
|
|
|
@class GDL2KVCNSMutableDictionary;
|
|
|
|
@class GDL2CDNSObject;
|
* 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
|
|
|
|
2004-02-12 11:07:49 +00:00
|
|
|
static NSRecursiveLock *local_lock = nil;
|
2003-03-31 00:24:15 +00:00
|
|
|
static BOOL GSStrictWO451Flag = NO;
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
GSUseStrictWO451Compatibility (NSString *key)
|
|
|
|
{
|
|
|
|
static BOOL read = NO;
|
|
|
|
if (read == NO)
|
|
|
|
{
|
2010-03-30 09:10:01 +00:00
|
|
|
if (local_lock == nil)
|
|
|
|
{
|
|
|
|
NSRecursiveLock *l = [GSLazyRecursiveLock new];
|
|
|
|
GDL2_AssignAtomicallyIfNil(&local_lock, l);
|
|
|
|
}
|
|
|
|
[local_lock lock];
|
2004-02-12 11:07:49 +00:00
|
|
|
|
2003-03-31 00:24:15 +00:00
|
|
|
NS_DURING
|
|
|
|
if (read == NO)
|
|
|
|
{
|
|
|
|
NSUserDefaults *defaults;
|
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
GSStrictWO451Flag
|
|
|
|
= [defaults boolForKey: @"GSUseStrictWO451Compatibility"];
|
|
|
|
read = YES;
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
2004-02-12 11:07:49 +00:00
|
|
|
[local_lock unlock];
|
2003-03-31 00:24:15 +00:00
|
|
|
[localException raise];
|
|
|
|
NS_ENDHANDLER
|
2004-02-12 11:07:49 +00:00
|
|
|
|
|
|
|
[local_lock unlock];
|
2003-03-31 00:24:15 +00:00
|
|
|
}
|
|
|
|
return GSStrictWO451Flag;
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2004-07-21 19:01:48 +00:00
|
|
|
void
|
|
|
|
GDL2_DumpMethodList(Class cls, SEL sel, BOOL isInstance)
|
|
|
|
{
|
2010-03-15 08:56:06 +00:00
|
|
|
/*
|
2004-07-21 19:01:48 +00:00
|
|
|
void *iterator = 0;
|
|
|
|
GSMethodList mList;
|
|
|
|
|
|
|
|
fprintf(stderr,"List for :%s %s (inst:%d)\n",
|
|
|
|
GSNameFromClass(cls), GSNameFromSelector(sel), isInstance);
|
|
|
|
while ((mList = GSMethodListForSelector(cls, sel,
|
|
|
|
&iterator, isInstance)))
|
|
|
|
{
|
|
|
|
GSMethod meth = GSMethodFromList(mList, sel, NO);
|
|
|
|
IMP imp = meth->method_imp;
|
|
|
|
|
|
|
|
fprintf(stderr,"List: %p Meth: %p Imp: %p\n",
|
|
|
|
mList, meth, imp);
|
|
|
|
}
|
|
|
|
fprintf(stderr,"List finished\n"); fflush(stderr);
|
2010-03-15 08:56:06 +00:00
|
|
|
*/
|
2004-07-21 19:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-15 14:00:23 +00:00
|
|
|
GDL2_Activate(Class sup, Class cls)
|
2004-07-21 19:01:48 +00:00
|
|
|
{
|
2010-04-09 17:44:00 +00:00
|
|
|
assert(sup!=Nil);
|
|
|
|
assert(cls!=Nil);
|
2010-03-15 14:00:23 +00:00
|
|
|
GSObjCAddClassOverride(sup, cls);
|
2004-07-21 19:01:48 +00:00
|
|
|
}
|
|
|
|
|
2002-11-15 22:57:05 +00:00
|
|
|
@implementation NSObject (NSObjectPerformingSelector)
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector: (SEL)sel
|
|
|
|
withEachObjectInArray: (NSArray*)array
|
|
|
|
{
|
|
|
|
return [self resultsOfPerformingSelector: sel
|
|
|
|
withEachObjectInArray: array
|
|
|
|
defaultResult: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector: (SEL)sel
|
|
|
|
withEachObjectInArray: (NSArray*)array
|
|
|
|
defaultResult: (id)defaultResult
|
|
|
|
{
|
|
|
|
NSMutableArray *results = nil;
|
|
|
|
|
|
|
|
if (array)
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger count = [array count];
|
2002-11-15 22:57:05 +00:00
|
|
|
results = [NSMutableArray array];
|
2014-05-29 12:06:02 +00:00
|
|
|
if (count>0)
|
|
|
|
{
|
|
|
|
NSUInteger i=0;
|
|
|
|
for(i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
id object = GDL2_ObjectAtIndexWithImpPtr(array,&oaiIMP,i);
|
|
|
|
id result = [self performSelector: sel
|
|
|
|
withObject: object];
|
|
|
|
if (!result)
|
|
|
|
result = defaultResult;
|
|
|
|
|
|
|
|
NSAssert3(result,
|
|
|
|
@"%@: No result for object %@ resultOfPerformingSelector:\"%s\" withEachObjectInArray:",
|
|
|
|
self,
|
|
|
|
object,
|
|
|
|
sel_getName(sel));
|
|
|
|
|
|
|
|
[results addObject: result];
|
|
|
|
}
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSArray (NSArrayPerformingSelector)
|
|
|
|
|
|
|
|
- (id)firstObject
|
|
|
|
{
|
|
|
|
NSAssert1([self count] > 0, @"no object in %@", self);
|
|
|
|
return [self objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector: (SEL)sel
|
|
|
|
{
|
|
|
|
return [self resultsOfPerformingSelector: sel
|
|
|
|
defaultResult: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector: (SEL)sel
|
|
|
|
defaultResult: (id)defaultResult
|
|
|
|
{
|
|
|
|
NSMutableArray *results=[NSMutableArray array];
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger count = [self count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
if (count>0)
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i =0;
|
2002-11-15 22:57:05 +00:00
|
|
|
for(i = 0; i < count; i++)
|
2014-05-29 12:06:02 +00:00
|
|
|
{
|
|
|
|
id object = GDL2_ObjectAtIndexWithImpPtr(self,&oaiIMP,i);
|
|
|
|
id result = [object performSelector: sel];
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
result = defaultResult;
|
|
|
|
|
|
|
|
NSAssert3(result,
|
|
|
|
@"%@: No result for object %@ resultOfPerformingSelector:\"%s\"",
|
|
|
|
self,
|
|
|
|
object,
|
|
|
|
sel_getName(sel));
|
|
|
|
|
|
|
|
[results addObject: result];
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector: (SEL)sel
|
|
|
|
withObject: (id)obj1
|
|
|
|
{
|
|
|
|
return [self resultsOfPerformingSelector: sel
|
|
|
|
withObject: obj1
|
|
|
|
defaultResult: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector:(SEL)sel
|
|
|
|
withObject:(id)obj1
|
|
|
|
defaultResult:(id)defaultResult
|
|
|
|
{
|
|
|
|
NSMutableArray *results = [NSMutableArray array];
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger count = [self count];
|
|
|
|
if (count>0)
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i=0;
|
2002-11-15 22:57:05 +00:00
|
|
|
for(i = 0; i < count; i++)
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
id object = GDL2_ObjectAtIndexWithImpPtr(self,&oaiIMP,i);
|
|
|
|
id result = [object performSelector: sel
|
|
|
|
withObject: obj1];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
if (!result)
|
|
|
|
result = defaultResult;
|
|
|
|
|
|
|
|
NSAssert3(result,
|
|
|
|
@"%@: No result for object %@ resultOfPerformingSelector:\"%s\"",
|
|
|
|
self,
|
|
|
|
object,
|
2010-07-04 10:00:57 +00:00
|
|
|
sel_getName(sel));
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
[results addObject: result];
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector: (SEL)sel
|
|
|
|
withObject: (id)obj1
|
|
|
|
withObject: (id)obj2
|
|
|
|
{
|
|
|
|
return [self resultsOfPerformingSelector: sel
|
|
|
|
withObject: obj1
|
|
|
|
withObject: obj2
|
|
|
|
defaultResult: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)resultsOfPerformingSelector: (SEL)sel
|
|
|
|
withObject: (id)obj1
|
|
|
|
withObject: (id)obj2
|
|
|
|
defaultResult: (id)defaultResult
|
|
|
|
{
|
|
|
|
NSMutableArray *results = [NSMutableArray array];
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger count = [self count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
if (count>0)
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i=0;
|
2002-11-15 22:57:05 +00:00
|
|
|
for(i = 0; i < count; i++)
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
id object = GDL2_ObjectAtIndexWithImpPtr(self,&oaiIMP,i);
|
|
|
|
id result = [object performSelector: sel
|
|
|
|
withObject: obj1
|
|
|
|
withObject: obj2];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
if (!result)
|
|
|
|
result = defaultResult;
|
|
|
|
|
|
|
|
NSAssert3(result,
|
|
|
|
@"%@: No result for object %@ resultOfPerformingSelector:\"%s\"",
|
|
|
|
self,
|
|
|
|
object,
|
2010-07-04 10:00:57 +00:00
|
|
|
sel_getName(sel));
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
[results addObject: result];
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)arrayExcludingObjectsInArray: (NSArray*)array
|
|
|
|
{
|
|
|
|
//Verify: mutable/non mutable,..
|
|
|
|
NSArray *result = nil;
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger selfCount = [self count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
if (selfCount > 0) //else return nil
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger arrayCount = [array count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
if (arrayCount == 0) //Nothing to exclude ?
|
|
|
|
result = self;
|
|
|
|
else
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger i = 0;
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < selfCount; i++)
|
|
|
|
{
|
|
|
|
id object = [self objectAtIndex: i];
|
2010-07-04 10:00:57 +00:00
|
|
|
NSUInteger index = [array indexOfObjectIdenticalTo: object];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
if (index == NSNotFound)
|
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
[(NSMutableArray*)result addObject: object];
|
|
|
|
else
|
|
|
|
result = [NSMutableArray arrayWithObject: object];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-02 18:48:29 +00:00
|
|
|
- (NSArray *)arrayExcludingObject: (id)_object
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
//Verify: mutable/non mutable,..
|
|
|
|
NSArray *result = nil;
|
2013-03-02 18:48:29 +00:00
|
|
|
NSUInteger selfCount = [self count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2013-03-02 18:48:29 +00:00
|
|
|
if (selfCount > 0 && _object) //else return nil
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger i=0;
|
|
|
|
IMP oaiIMP=NULL;
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < selfCount; i++)
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
id object = GDL2_ObjectAtIndexWithImpPtr(self,&oaiIMP,i);
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2013-03-02 18:48:29 +00:00
|
|
|
if (object != _object)
|
2002-11-15 22:57:05 +00:00
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
[(NSMutableArray *)result addObject: object];
|
|
|
|
else
|
|
|
|
result = [NSMutableArray arrayWithObject: object];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)arrayByReplacingObject: (id)object1
|
|
|
|
withObject: (id)object2
|
|
|
|
{
|
|
|
|
NSArray *array = nil;
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger count = [self count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i = 0;
|
|
|
|
NSMutableArray* tmpArray = [NSMutableArray arrayWithCapacity: count];
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
id o = GDL2_ObjectAtIndexWithImpPtr(self,&oaiIMP,i);
|
2002-11-15 22:57:05 +00:00
|
|
|
|
|
|
|
if ([o isEqual: object1])
|
|
|
|
[tmpArray addObject: object2];
|
|
|
|
else
|
|
|
|
[tmpArray addObject: o];
|
|
|
|
}
|
|
|
|
array = [NSArray arrayWithArray: tmpArray];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
array = self;
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** return YES if the 2 arrays contains exactly identical objects (compared by address) (i.e. only the order may change), NO otherwise
|
|
|
|
**/
|
|
|
|
- (BOOL)containsIdenticalObjectsWithArray: (NSArray *)array
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
return ![NSArray diffOldArray:self
|
|
|
|
newArray:array
|
|
|
|
returnsRemovedValues:NULL
|
|
|
|
addedValues:NULL];
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
#define EO_MAX_OBJECTS_FROM_STACK 64
|
|
|
|
/**
|
|
|
|
* Macro to manage memory for chunks of code that need to work with
|
|
|
|
* arrays of items. Use this to start the block of code using
|
|
|
|
* the array and EO_ENDITEMBUF() to end it. The idea is to ensure that small
|
|
|
|
* arrays are allocated on the stack (for speed), but large arrays are
|
|
|
|
* allocated from the heap (to avoid stack overflow).
|
|
|
|
*/
|
|
|
|
#define EO_BEGINITEMBUF(P, S, T) { \
|
|
|
|
T P ## _ibuf[(S) <= EO_MAX_OBJECTS_FROM_STACK ? (S) : 0]; \
|
|
|
|
T *P ## _base = ((S) <= EO_MAX_OBJECTS_FROM_STACK) ? P ## _ibuf \
|
|
|
|
: (T*)NSZoneMalloc(NSDefaultMallocZone(), (S) * sizeof(T)); \
|
|
|
|
T *(P) = P ## _base;
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
/**
|
|
|
|
* Macro to manage memory for chunks of code that need to work with
|
|
|
|
* arrays of items. Use EO_BEGINITEMBUF() to start the block of code using
|
|
|
|
* the array and this macro to end it.
|
|
|
|
*/
|
|
|
|
#define EO_ENDITEMBUF(P) \
|
|
|
|
if (P ## _base != P ## _ibuf) \
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), P ## _base); \
|
|
|
|
}
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
/**
|
|
|
|
* Macro to manage memory for chunks of code that need to work with
|
|
|
|
* arrays of objects. Use this to start the block of code using
|
|
|
|
* the array and EO_ENDIDBUF() to end it. The idea is to ensure that small
|
|
|
|
* arrays are allocated on the stack (for speed), but large arrays are
|
|
|
|
* allocated from the heap (to avoid stack overflow).
|
|
|
|
*/
|
|
|
|
#define EO_BEGINIDBUF(P, S) EO_BEGINITEMBUF(P, S, id)
|
2002-11-15 22:57:05 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
/**
|
|
|
|
* Macro to manage memory for chunks of code that need to work with
|
|
|
|
* arrays of objects. Use EO_BEGINIDBUF() to start the block of code using
|
|
|
|
* the array and this macro to end it.
|
|
|
|
*/
|
|
|
|
#define EO_ENDIDBUF(P) EO_ENDITEMBUF(P)
|
|
|
|
|
|
|
|
//Returns YES if the 2 arrays don't contains exactly identical objects (compared by address) (i.e. only the order may change)
|
|
|
|
//Optimized for end addition/removing
|
|
|
|
+(BOOL)diffOldArray:(NSArray*)oldArray
|
|
|
|
newArray:(NSArray*)newArray
|
|
|
|
returnsRemovedValues:(NSArray**)removedValues
|
|
|
|
addedValues:(NSArray**)addedValues
|
|
|
|
{
|
|
|
|
BOOL isDiff=NO;
|
|
|
|
if (removedValues!=NULL)
|
|
|
|
*removedValues=nil;
|
|
|
|
if (addedValues!=NULL)
|
|
|
|
*addedValues=nil;
|
|
|
|
if (oldArray==newArray)
|
|
|
|
{
|
|
|
|
//Same array: do nothing
|
|
|
|
isDiff=NO;
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
2014-05-29 12:06:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NSUInteger oldArrayCount = [oldArray count];
|
|
|
|
NSUInteger newArrayCount = [newArray count];
|
|
|
|
if (oldArrayCount==0)
|
|
|
|
{
|
|
|
|
if (newArrayCount==0) // oldArrayCount==0 && newArrayCount==0
|
|
|
|
{
|
|
|
|
//same are empty
|
|
|
|
isDiff=NO;
|
|
|
|
}
|
|
|
|
else // oldArrayCount==0 && newArrayCount>0
|
|
|
|
{
|
|
|
|
//No old array values
|
|
|
|
isDiff=YES;
|
|
|
|
if (addedValues!=NULL)
|
|
|
|
{
|
|
|
|
if ([newArray isKindOfClass:GDL2_NSMutableArrayClass])
|
|
|
|
*addedValues=AUTORELEASE([newArray shallowCopy]);
|
|
|
|
else
|
|
|
|
*addedValues=AUTORELEASE(RETAIN(newArray));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (newArrayCount==0) // oldArrayCount>0 && newArrayCount==0
|
|
|
|
{
|
|
|
|
//no new array values
|
|
|
|
isDiff=YES;
|
|
|
|
if (removedValues!=NULL)
|
|
|
|
{
|
|
|
|
if ([oldArray isKindOfClass:GDL2_NSMutableArrayClass])
|
|
|
|
*removedValues=AUTORELEASE([oldArray shallowCopy]);
|
|
|
|
else
|
|
|
|
*removedValues=AUTORELEASE(RETAIN(oldArray));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // oldArrayCount>0 && newArrayCount>0
|
|
|
|
{
|
|
|
|
//Start deep work
|
|
|
|
NSUInteger minCount=(oldArrayCount<newArrayCount ? oldArrayCount : newArrayCount);
|
|
|
|
EO_BEGINIDBUF(oldObjects,oldArrayCount);
|
|
|
|
EO_BEGINIDBUF(newObjects,newArrayCount);
|
|
|
|
[oldArray getObjects: oldObjects];
|
|
|
|
[newArray getObjects: newObjects];
|
|
|
|
|
|
|
|
//Find for 1st diff
|
|
|
|
NSUInteger i=0;
|
|
|
|
NSUInteger start=minCount;
|
|
|
|
for(i=0;i<minCount;i++)
|
|
|
|
{
|
|
|
|
if (oldObjects[i]!=newObjects[i])
|
|
|
|
{
|
|
|
|
start=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (start==minCount
|
|
|
|
&& oldArrayCount==newArrayCount)
|
|
|
|
{
|
|
|
|
//No diff found at the begining and same array size
|
|
|
|
isDiff=NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//NSLog(@"X DIFF ARRAY start at %d",start);
|
|
|
|
NSUInteger maxCount=(oldArrayCount>newArrayCount ? oldArrayCount : newArrayCount);
|
|
|
|
maxCount-=start;
|
|
|
|
EO_BEGINIDBUF(tmpObjects,maxCount);
|
|
|
|
|
|
|
|
// Find removed values
|
|
|
|
NSUInteger oi=0;
|
|
|
|
NSUInteger ni=0;
|
|
|
|
i=0;
|
|
|
|
for(oi=start;oi<oldArrayCount;oi++)
|
|
|
|
{
|
|
|
|
id o=oldObjects[oi];
|
|
|
|
for(ni=start;ni<newArrayCount && newObjects[ni]!=o;ni++);
|
|
|
|
NSCAssert(i<maxCount,@"Pb");
|
|
|
|
if (ni>=newArrayCount)//Not found ?
|
|
|
|
tmpObjects[i++]=o;
|
|
|
|
}
|
|
|
|
if (i>0)
|
|
|
|
{
|
|
|
|
isDiff=YES;
|
|
|
|
if (removedValues!=NULL)
|
|
|
|
{
|
|
|
|
*removedValues=[NSArray arrayWithObjects:tmpObjects
|
|
|
|
count:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find added values
|
|
|
|
i=0;
|
|
|
|
for(ni=start;ni<newArrayCount;ni++)
|
|
|
|
{
|
|
|
|
id n=newObjects[ni];
|
|
|
|
for(oi=start;oi<oldArrayCount && oldObjects[oi]!=n;oi++);
|
|
|
|
NSCAssert(i<maxCount,@"Pb");
|
|
|
|
if (oi>=oldArrayCount)//Not found ?
|
|
|
|
tmpObjects[i++]=n;
|
|
|
|
}
|
|
|
|
if (i>0)
|
|
|
|
{
|
|
|
|
isDiff=YES;
|
|
|
|
if (addedValues!=NULL)
|
|
|
|
{
|
|
|
|
*addedValues=[NSArray arrayWithObjects:tmpObjects
|
|
|
|
count:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EO_ENDIDBUF(tmpObjects);
|
|
|
|
}
|
|
|
|
EO_ENDIDBUF(newObjects);
|
|
|
|
EO_ENDIDBUF(oldObjects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isDiff;
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2003-03-31 00:24:15 +00:00
|
|
|
@interface NSObject (EOCOmpareOnNameSupport)
|
|
|
|
- (NSString *)name;
|
|
|
|
@end
|
2002-11-15 22:57:05 +00:00
|
|
|
@implementation NSObject (EOCompareOnName)
|
|
|
|
|
|
|
|
- (NSComparisonResult)eoCompareOnName: (id)object
|
|
|
|
{
|
2003-03-31 00:24:15 +00:00
|
|
|
return [[self name] compare: [(NSObject *)object name]];
|
2002-11-15 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSString (YorYes)
|
|
|
|
|
|
|
|
- (BOOL)isYorYES
|
|
|
|
{
|
|
|
|
return ([self isEqual: @"Y"] || [self isEqual: @"YES"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2003-03-31 00:24:15 +00:00
|
|
|
|
2003-06-24 16:27:01 +00:00
|
|
|
@implementation NSString (VersionParsing)
|
|
|
|
- (int)parsedFirstVersionSubstring
|
|
|
|
{
|
|
|
|
NSString *shortVersion;
|
|
|
|
NSScanner *scanner;
|
|
|
|
NSCharacterSet *characterSet;
|
|
|
|
NSArray *versionComponents;
|
|
|
|
NSString *component;
|
|
|
|
int count, i;
|
|
|
|
int version = 0;
|
|
|
|
int factor[] = { 10000, 100, 1 };
|
|
|
|
|
|
|
|
scanner = [NSScanner scannerWithString: self];
|
|
|
|
characterSet
|
|
|
|
= [NSCharacterSet characterSetWithCharactersInString: @"0123456789."];
|
|
|
|
|
|
|
|
[scanner setCharactersToBeSkipped: [characterSet invertedSet]];
|
|
|
|
[scanner scanCharactersFromSet: characterSet intoString: &shortVersion];
|
|
|
|
|
|
|
|
versionComponents = [shortVersion componentsSeparatedByString:@"."];
|
|
|
|
count = [versionComponents count];
|
|
|
|
|
|
|
|
for (i = 0; (i < count) && (i < 3); i++)
|
|
|
|
{
|
|
|
|
component = [versionComponents objectAtIndex: i];
|
|
|
|
version += [component intValue] * factor[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2004-05-07 13:14:24 +00:00
|
|
|
@implementation NSString (Extensions)
|
|
|
|
- (NSString *)initialCapitalizedString
|
|
|
|
{
|
|
|
|
unichar *chars;
|
2014-05-29 12:06:02 +00:00
|
|
|
NSUInteger length = [self length];
|
2004-05-07 13:14:24 +00:00
|
|
|
|
2010-04-26 22:05:17 +00:00
|
|
|
chars = NSZoneMalloc(NSDefaultMallocZone(),length * sizeof(unichar));
|
2004-05-07 13:14:24 +00:00
|
|
|
[self getCharacters: chars];
|
|
|
|
chars[0]=uni_toupper(chars[0]);
|
|
|
|
|
2010-04-26 22:05:17 +00:00
|
|
|
|
|
|
|
// CHECKME: does this really free how we want it? -- dw
|
|
|
|
|
2004-05-07 13:14:24 +00:00
|
|
|
return AUTORELEASE([[NSString alloc] initWithCharactersNoCopy: chars
|
|
|
|
length: length
|
|
|
|
freeWhenDone: YES]);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2003-11-28 22:30:57 +00:00
|
|
|
@implementation NSString (StringToNumber)
|
|
|
|
-(unsigned int)unsignedIntValue
|
|
|
|
{
|
|
|
|
long v=atol([self lossyCString]);
|
|
|
|
if (v<0 || v >UINT_MAX)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%ld is not an unsigned int",v];
|
|
|
|
};
|
|
|
|
return (unsigned int)v;
|
|
|
|
};
|
|
|
|
-(short)shortValue
|
|
|
|
{
|
|
|
|
int v=atoi([self lossyCString]);
|
|
|
|
if (v<SHRT_MIN || v>SHRT_MAX)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%d is not a short",v];
|
|
|
|
};
|
|
|
|
return (short)v;
|
|
|
|
};
|
2006-12-30 17:41:02 +00:00
|
|
|
-(unsigned short)unsignedShortValue
|
2003-11-28 22:30:57 +00:00
|
|
|
{
|
|
|
|
int v=atoi([self lossyCString]);
|
|
|
|
if (v<0 || v>USHRT_MAX)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%d is not an unsigned short",v];
|
|
|
|
};
|
|
|
|
return (unsigned short)v;
|
|
|
|
};
|
|
|
|
|
|
|
|
-(long)longValue
|
|
|
|
{
|
|
|
|
return atol([self lossyCString]);
|
|
|
|
};
|
|
|
|
|
2006-12-30 17:41:02 +00:00
|
|
|
-(unsigned long)unsignedLongValue
|
2003-11-28 22:30:57 +00:00
|
|
|
{
|
|
|
|
long long v=atoll([self lossyCString]);
|
|
|
|
if (v<0 || v>ULONG_MAX)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%lld is not an unsigned long",v];
|
|
|
|
};
|
|
|
|
return (unsigned long)v;
|
|
|
|
};
|
|
|
|
|
|
|
|
-(unsigned long long)unsignedLongLongValue
|
|
|
|
{
|
|
|
|
return strtoull([self lossyCString],NULL,10);
|
|
|
|
};
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSObject (PerformSelect3)
|
2014-07-24 21:09:40 +00:00
|
|
|
|
|
|
|
- (id) performSelector: (SEL)selector
|
|
|
|
withPointer: (void*) ptr
|
|
|
|
{
|
|
|
|
IMP msg;
|
|
|
|
|
|
|
|
if (selector == 0)
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%@ null selector given", NSStringFromSelector(_cmd)];
|
|
|
|
|
|
|
|
msg = class_getMethodImplementation([self class], selector);
|
|
|
|
if (!msg)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"invalid selector passed to %s", sel_getName(_cmd)];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*msg)(self, selector, ptr);
|
|
|
|
}
|
|
|
|
|
2003-11-28 22:30:57 +00:00
|
|
|
//Ayers: Review (Do we really need this?)
|
|
|
|
/**
|
|
|
|
* Causes the receiver to execute the method implementation corresponding
|
|
|
|
* to aSelector and returns the result.<br />
|
|
|
|
* The method must be one which takes three arguments and returns an object.
|
|
|
|
* <br />Raises NSInvalidArgumentException if given a null selector.
|
|
|
|
*/
|
2006-12-30 17:41:02 +00:00
|
|
|
- (id) performSelector: (SEL)selector
|
2003-11-28 22:30:57 +00:00
|
|
|
withObject: (id) object1
|
|
|
|
withObject: (id) object2
|
|
|
|
withObject: (id) object3
|
|
|
|
{
|
|
|
|
IMP msg;
|
|
|
|
|
2006-12-30 17:41:02 +00:00
|
|
|
if (selector == 0)
|
2003-11-28 22:30:57 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%@ null selector given", NSStringFromSelector(_cmd)];
|
|
|
|
|
2010-04-26 22:05:17 +00:00
|
|
|
msg = class_getMethodImplementation([self class], selector);
|
2003-11-28 22:30:57 +00:00
|
|
|
if (!msg)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
2010-07-04 10:00:57 +00:00
|
|
|
format: @"invalid selector passed to %s", sel_getName(_cmd)];
|
2003-11-28 22:30:57 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-12-30 17:41:02 +00:00
|
|
|
return (*msg)(self, selector, object1, object2, object3);
|
2003-11-28 22:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2010-07-04 10:00:57 +00:00
|
|
|
|
|
|
|
@implementation NSMutableDictionary (EOAdditions)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an autoreleased mutable dictionary based on otherDictionary
|
|
|
|
* but only with keys from the keys array.
|
|
|
|
*/
|
|
|
|
|
|
|
|
+ (NSMutableDictionary *) dictionaryWithDictionary:(NSDictionary *)otherDictionary
|
|
|
|
keys:(NSArray*)keys
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
NSMutableDictionary* mDict=nil;
|
|
|
|
if (keys==nil)
|
|
|
|
{
|
|
|
|
mDict=[NSMutableDictionary dictionary];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSUInteger keyCount = [keys count];
|
|
|
|
if (keyCount==0)
|
|
|
|
{
|
|
|
|
mDict=[NSMutableDictionary dictionary];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i = 0;
|
|
|
|
mDict = [NSMutableDictionary dictionaryWithCapacity:keyCount];
|
2010-07-04 10:00:57 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
for (; i < keyCount; i++)
|
|
|
|
{
|
|
|
|
NSString * key = GDL2_ObjectAtIndexWithImpPtr(keys,&oaiIMP,i);
|
|
|
|
id value = [otherDictionary valueForKey:key];
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
value = GDL2_EONull;
|
|
|
|
|
|
|
|
[mDict setObject:value
|
|
|
|
forKey:key];
|
|
|
|
}
|
|
|
|
}
|
2010-07-04 10:00:57 +00:00
|
|
|
}
|
2014-05-29 12:06:02 +00:00
|
|
|
return mDict;
|
2010-07-04 10:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// "translateFromKeys:toKeys:",
|
|
|
|
|
|
|
|
- (void) translateFromKeys:(NSArray *) currentKeys
|
|
|
|
toKeys:(NSArray *) newKeys
|
|
|
|
{
|
|
|
|
NSUInteger count = [currentKeys count];
|
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
if (count != [newKeys count])
|
2010-07-04 10:00:57 +00:00
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%s key arrays must contain equal number of keys", __PRETTY_FUNCTION__];
|
2010-07-04 10:00:57 +00:00
|
|
|
}
|
2014-05-29 12:06:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSMutableArray* buffer = [NSMutableArray arrayWithCapacity:count];
|
|
|
|
NSUInteger i = 0;
|
|
|
|
NSString * nullPlaceholder = @"__EOAdditionsDummy__";
|
2010-07-04 10:00:57 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
id key = GDL2_ObjectAtIndexWithImpPtr(currentKeys,&oaiIMP,i);
|
|
|
|
id value = [self objectForKey:key];
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
value = nullPlaceholder;
|
|
|
|
[buffer addObject:value];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[buffer addObject:value];
|
|
|
|
[self removeObjectForKey:key];
|
|
|
|
}
|
|
|
|
}
|
2010-07-04 10:00:57 +00:00
|
|
|
|
2014-05-29 12:06:02 +00:00
|
|
|
[self removeAllObjects];
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
id value = [buffer objectAtIndex:i];
|
|
|
|
if(value != nullPlaceholder)
|
|
|
|
{
|
|
|
|
[self setObject:value
|
|
|
|
forKey:[newKeys objectAtIndex:i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override self values with values from dict for keys
|
|
|
|
*/
|
|
|
|
-(void)overrideEntriesWithObjectsFromDictionary:(NSDictionary*)dict
|
|
|
|
forKeys:(NSArray*)keys
|
|
|
|
{
|
|
|
|
NSUInteger keysCount=[keys count];
|
|
|
|
if (keysCount>0)
|
2010-07-04 10:00:57 +00:00
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i=0;
|
|
|
|
for(i=0;i<keysCount;i++)
|
|
|
|
{
|
|
|
|
id key = GDL2_ObjectAtIndexWithImpPtr(keys,&oaiIMP,i);
|
|
|
|
id value = [dict objectForKey:key];
|
|
|
|
if (value != nil)
|
|
|
|
{
|
|
|
|
[self setObject:value
|
|
|
|
forKey:key];
|
|
|
|
}
|
|
|
|
}
|
2010-07-04 10:00:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSDictionary (EOAdditions)
|
|
|
|
|
|
|
|
- (BOOL) containsAnyNullObject
|
|
|
|
{
|
|
|
|
NSArray * values = [self allValues];
|
|
|
|
NSUInteger count = [values count];
|
2014-05-29 12:06:02 +00:00
|
|
|
if (count>0)
|
2010-07-04 10:00:57 +00:00
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i = 0;
|
|
|
|
for (; i < count; i++)
|
|
|
|
{
|
|
|
|
if (GDL2_ObjectAtIndexWithImpPtr(values,&oaiIMP,i) == GDL2_EONull)
|
|
|
|
return YES;
|
|
|
|
}
|
2010-07-04 10:00:57 +00:00
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSDictionary*) dictionaryWithNullValuesForKeys:(NSArray*) keys
|
|
|
|
{
|
|
|
|
NSMutableDictionary * dict = nil;
|
|
|
|
NSUInteger count = [keys count];
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
2014-05-29 12:06:02 +00:00
|
|
|
IMP oaiIMP=NULL;
|
|
|
|
NSUInteger i = 0;
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity:count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
NSString * key = GDL2_ObjectAtIndexWithImpPtr(keys,&oaiIMP,i);
|
|
|
|
[dict setObject:GDL2_EONull
|
|
|
|
forKey: key];
|
|
|
|
}
|
2010-07-04 10:00:57 +00:00
|
|
|
}
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-05-22 14:05:51 +00:00
|
|
|
@implementation NSString (EORelationshipPath)
|
|
|
|
|
|
|
|
- (NSString*) relationshipPathByDeletingFirstComponent
|
|
|
|
{
|
|
|
|
NSRange r=[self rangeOfString:@"."];
|
|
|
|
if (r.length==0)
|
|
|
|
return nil;
|
|
|
|
else
|
|
|
|
return [self substringFromIndex:r.location+r.length];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) firstComponentFromRelationshipPath
|
|
|
|
{
|
|
|
|
NSRange r=[self rangeOfString:@"."];
|
|
|
|
if (r.length==0)
|
|
|
|
return nil;
|
|
|
|
else
|
|
|
|
return [self substringToIndex:r.location];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) relationshipPathByDeletingLastComponent;
|
|
|
|
{
|
|
|
|
NSRange r=[self rangeOfString:@"."
|
|
|
|
options:NSBackwardsSearch];
|
|
|
|
if (r.length==0)
|
|
|
|
return nil;
|
|
|
|
else
|
|
|
|
return [self substringToIndex:r.location];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) lastComponentFromRelationshipPath
|
|
|
|
{
|
|
|
|
NSRange r=[self rangeOfString:@"."
|
|
|
|
options:NSBackwardsSearch];
|
|
|
|
if (r.length==0)
|
|
|
|
return nil;
|
|
|
|
else
|
|
|
|
return [self substringFromIndex:r.location+r.length];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) relationshipPathIsMultiHop
|
|
|
|
{
|
|
|
|
NSRange r=[self rangeOfString:@"."];
|
|
|
|
return (r.length>0 ? YES : NO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|