forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFSArray.m
716 lines (602 loc) · 20.6 KB
/
FSArray.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
/* FSArray.m Copyright (c) 1998-2009 Philippe Mougin. */
/* This software is open source. See the license. */
#import "build_config.h"
#import "FSArray.h"
#import "ArrayPrivate.h"
#import "ArrayRepId.h"
#import "FScriptFunctions.h"
#import <Foundation/Foundation.h>
#import "FSCompiler.h"
#import "FSVoid.h"
#import <objc/objc-runtime.h>
#import "FSBlock.h"
#import "FSExecEngine.h"
#import "FSPattern.h"
#import "FSNumber.h"
#import "NumberPrivate.h"
#import "ArrayRepDouble.h"
#import "ArrayRepEmpty.h"
#import "ArrayRepBoolean.h"
#import "FSBooleanPrivate.h"
#import "FSMiscTools.h"
#import "FSNSArrayPrivate.h"
#import "FSArrayEnumerator.h"
#import "FSNSMutableArray.h"
#import "FSCollectionInspector.h"
#import "FSReplacementForCoderForNilInArray.h"
@interface FSArray(ArrayPrivateInternal)
- (void) addObjectsFromFSArray:(FSArray *)otherArray;
- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range identical:(BOOL)identical;
- (enum ArrayRepType)type;
@end
void __attribute__ ((constructor)) initializeFSArray(void)
{
[NSKeyedUnarchiver setClass:[FSArray class] forClassName:@"Array"];
[NSUnarchiver decodeClassName:@"Array" asClassName:@"FSArray"];
}
/*static int comp_unsigned_int(const void *a,const void *b)
{
if (*(unsigned int *)a == *(unsigned int *)b)
return 0;
else if (*(unsigned int *)a) < *(unsigned int *)b)
return -1;
else
return 1;
} */
/*static int compEq(const void *a,const void *b)
{
if ( [*(id *)a operator_less: *(id *)b] == fsTrue) return -1;
else if ( [*(id *)b operator_less: *(id *)a] == fsTrue) return 1;
else return 0;
}
*/
@implementation FSArray
///////////////////////////////////// USER METHODS
- (id)at:(id)index put:(id)elem
{
if (type == FS_ID) return [(ArrayRepId *)rep at:index put:elem];
else return [super at:index put:elem];
}
- (FSArray *) distinctId
{
if ([rep respondsToSelector:@selector(distinctId)]) return [rep distinctId];
else {return [super distinctId];}
}
- (BOOL) isEqual:(id)anObject
{
if ([anObject isKindOfClass:[NSArray class]]) return [self isEqualToArray:anObject];
else return NO;
}
- (FSArray *)replicate:(NSArray *)operand
{
VERIF_OP_NSARRAY(@"replicate:");
if ([self count] != [operand count]) FSExecError(@"receiver and argument of method \"replicate:\" must be arrays of same size");
if ([operand isProxy])
{ // build a local array because replicate: of an arrayRep does not support FSArray proxy
NSUInteger i;
NSUInteger nb = [operand count];
NSArray *remoteReplicationArray = operand;
operand = [FSArray arrayWithCapacity:nb];
for (i = 0; i < nb; i++) [(FSArray *)operand addObject:[remoteReplicationArray objectAtIndex:i]];
}
if ([rep respondsToSelector:@selector(replicateWithArray:)] && [operand isKindOfClass:[FSArray class]])
return [rep replicateWithArray:(FSArray *)operand];
else
return [super replicate:operand];
}
- (FSArray *)reverse
{
if ([rep respondsToSelector:@selector(reverse)]) return [rep reverse];
else return [super reverse];
}
- (FSArray *)rotatedBy:(NSNumber *)operand
{
if ([rep respondsToSelector:@selector(rotatedBy:)]) return [rep rotatedBy:operand];
else return [super rotatedBy:operand];
}
- (FSArray *)sort
{
if ([rep respondsToSelector:@selector(sort)]) return [rep sort];
else return [super sort];
}
///////////////////////////////////////////////////////////////////////////
//////////////////////////////////// OTHER METHODS ////////////////////////
///////////////////////////////////////////////////////////////////////////
+ (id)arrayWithObject:(id)anObject
{
return [[[FSArray alloc] initWithObject:anObject] autorelease];
}
+ (id)arrayWithObjects:(id *)objects count:(NSUInteger)count
{
return [[[FSArray alloc] initWithObjects:objects count:count] autorelease];
}
+ (FSArray *)arrayWithRep:(id)theRep
{
return [[[FSArray alloc] initWithRep:theRep] autorelease];
}
+ (double) maxCount { return NSUIntegerMax;}
typedef struct fs_objc_object {
Class isa;
} *fso;
- (void)addObject:(id)anObject
{
switch (type)
{
case DOUBLE:
{
if (anObject && object_getClass(anObject) == FSNumberClass) // anObject is casted to avoid the warning "static access to object of type id"
[(ArrayRepDouble *)rep addDouble:((FSNumber *)anObject)->value ];
else if (anObject && isNSNumberWithLosslessConversionToDouble(anObject))
[(ArrayRepDouble *)rep addDouble:[(NSNumber *)anObject doubleValue]];
else
{
[self becomeArrayOfId];
[(ArrayRepId *)rep addObject:anObject];
}
break;
}
case BOOLEAN:
if (anObject == fsFalse) [(ArrayRepBoolean *)rep addBoolean:0];
else if (anObject == fsTrue) [(ArrayRepBoolean *)rep addBoolean:1];
else {[self becomeArrayOfId]; [(ArrayRepId *)rep addObject:anObject];}
break;
case FS_ID:
[(ArrayRepId *)rep addObject:anObject];
break;
case EMPTY:
if (isNSNumberWithLosslessConversionToDouble(anObject))
{
id oldRep = rep;
rep = [[(ArrayRepEmpty *)rep asArrayRepDouble] retain];
type = DOUBLE;
[oldRep release];
[(ArrayRepDouble *)rep addDouble:[(NSNumber *)anObject doubleValue]];
}
else if (anObject == fsTrue || anObject == fsFalse)
{
id oldRep = rep;
rep = [[(ArrayRepEmpty *)rep asArrayRepBoolean] retain];
type = BOOLEAN;
[oldRep release];
[(ArrayRepBoolean *)rep addBoolean:(anObject == fsTrue ? 1 : 0)];
}
else
{
[self becomeArrayOfId];
[(ArrayRepId *)rep addObject:anObject];
}
break;
case FETCH_REQUEST:
[self becomeArrayOfId];
[(ArrayRepId *)rep addObject:anObject];
break;
} // end switch
}
- (void)addObjectsFromFSArray:(FSArray *)otherArray
{
BOOL proxy = [otherArray isProxy];
enum ArrayRepType repType = [otherArray type];
if (type==FS_ID && repType==FS_ID && !proxy) [(ArrayRepId *)rep addObjectsFromFSArray:otherArray];
else if (type==DOUBLE && repType==DOUBLE && !proxy) [(ArrayRepDouble *)rep addDoublesFromFSArray:otherArray];
else if (type==EMPTY) [self setValue:otherArray];
else
{
NSUInteger otherArrayCount = [otherArray count];
NSUInteger i;
if (repType == FS_ID && !proxy)
{
id *data = [otherArray dataPtr];
for (i = 0; i < otherArrayCount; i++) [self addObject:data[i]];
}
else for (i = 0; i < otherArrayCount; i++) [self addObject:[otherArray objectAtIndex:i]];
}
}
- (NSArray *)arrayByAddingObject:(id)anObject
{
FSArray *r = [[self copy] autorelease];
[r addObject:anObject];
return r;
}
- (NSArray *)arrayByAddingObjectsFromArray:(NSArray *)otherArray
{
FSArray *r = [[self copy] autorelease];
NSUInteger i, count;
if ([otherArray isKindOfClass:[FSArray class]])
[r addObjectsFromFSArray:(FSArray*)otherArray];
else
for (i = 0, count = [otherArray count]; i < count; i++)
[r addObject:[otherArray objectAtIndex:i]];
return r;
}
- (id)arrayRep {return rep;}
- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder
{
Class ReplacementForCoderForNilInArrayClass = [FSReplacementForCoderForNilInArray class];
NSUInteger i, count;
for (i = 0, count = [self count]; i < count; i++)
{
if ([[self objectAtIndex:i] isKindOfClass:ReplacementForCoderForNilInArrayClass])
[self replaceObjectAtIndex:i withObject:nil];
}
return self;
}
- (void)becomeArrayOfId
{
id oldRep = rep;
rep = [[rep asArrayRepId] retain];
[oldRep release];
type = FS_ID;
}
- (Class)classForCoder { return [self class]; }
- (NSString *)componentsJoinedByString:(NSString *)separator
{
NSMutableArray *a = [NSMutableArray arrayWithCapacity:[self count]];
for (id elem in self)
{
if (elem == nil) [a addObject:@"nil"];
else [a addObject:elem];
}
return [a componentsJoinedByString:separator];
}
- (BOOL)containsObject:(id)anObject
{
return [self indexOfObject:anObject] != NSNotFound;
}
- (id)copy { return [self copyWithZone:NULL];}
- (id)copyWithZone:(NSZone *)zone { return [[FSArray alloc] initWithRepNoRetain:[rep copyWithZone:zone]];}
- (NSUInteger)count
{
if ([rep respondsToSelector:@selector(count)])
return [rep count];
else
{
[self becomeArrayOfId];
return [rep count];
}
}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)statep objects:(id *)stackbuf count:(NSUInteger)len
{
if (type == FS_ID) return [rep countByEnumeratingWithState:statep objects:stackbuf count:len];
else return [super countByEnumeratingWithState:statep objects:stackbuf count:len];
}
- (NSString *)descriptionLimited:(NSUInteger)nbElem
{
if ([rep respondsToSelector:@selector(descriptionLimited:)]) return [rep descriptionLimited:nbElem];
else return [super descriptionLimited:nbElem];
}
- (NSString *)description
{
return [self descriptionLimited:[self count]];
}
- (NSString *)descriptionWithLocale:(NSDictionary *)locale
{
return [self descriptionWithLocale:locale indent:0];
}
- (NSString *)descriptionWithLocale:(NSDictionary *)locale indent:(NSUInteger)level
{
// fallback to printString (we may do something better in the future).
// Note: super's implementation is not used because it won't work if the array contains nil.
return [self printString];
}
- (void *)dataPtr
{
if (type != FS_ID) [self becomeArrayOfId];
return ((ArrayRepId *)rep)->t;
}
- (void)dealloc
{
//NSLog([NSString stringWithFormat:@">>>>>>>>>>>> %@", self]);
[rep release];
[super dealloc];
}
/*- (void)getObjects:(id *)aBuffer
{
return [self getObjects:aBuffer range:NSMakeRange(0,[self count])];
}
- (void)getObjects:(id *)aBuffer range:(NSRange)range
{
unsigned i, end;
if (range.location + range.length > [self count] || range.location == [self count])
[NSException raise:NSRangeException format:@"*** -[%@ getObjects:range:]: index (%d) beyond bounds (%d)",[self class],range.location + range.length - 1, [self count]];
if (range.length == 0) return;
for (i = range.location, end = (range.location + range.length - 1); i <= end; i++)
aBuffer[i] = [self objectAtIndex:i];
}*/
- (id)firstObjectCommonWithArray:(NSArray *)otherArray
{
for (id elem in self)
{
if ([otherArray containsObject:elem]) return elem;
}
return nil;
}
- (NSUInteger)indexOfObject:(id)anObject
{
return [self indexOfObject:anObject inRange:NSMakeRange(0,[self count])];
}
- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range
{
return [self indexOfObject:anObject inRange:range identical:NO];
}
- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range identical:(BOOL)identical
{
if (range.location + range.length > [self count])
[NSException raise:NSRangeException format:@"*** -[%@ indexOfObject:inRange:identical:]: index (%lu) beyond bounds (%lu)",[self class],(long unsigned)(range.location + MAX(0, range.length-1)), (long unsigned)[self count]];
if ([rep respondsToSelector:@selector(indexOfObject:inRange:identical:)])
return [rep indexOfObject:anObject inRange:range identical:identical];
if (range.length == 0) return NSNotFound;
else
{
NSUInteger i = range.location;
NSUInteger end = (range.location + range.length -1);
id elem = [self objectAtIndex:i];
while ( i <= end && !( identical ? elem == anObject : ([elem isEqual:anObject] || (elem == nil && anObject == nil)) ) )
{
i++;
elem = [self objectAtIndex:i];
}
return (i > end) ? NSNotFound : i;
}
}
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject
{
return [self indexOfObjectIdenticalTo:anObject inRange:NSMakeRange(0,[self count])];
}
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(NSRange)range
{
return [self indexOfObject:anObject inRange:range identical:YES];
}
- (id)init
{
return [self initWithCapacity:0];
}
- (id)initFrom:(NSUInteger)from to:(NSUInteger)to step:(NSUInteger)step
{
ArrayRepDouble *representation = [[ArrayRepDouble alloc] initFrom:from to:to step:step];
if (representation) return [self initWithRepNoRetain:representation];
else
{
[super dealloc];
return nil;
}
}
- (id)initFilledWith:(id)elem count:(NSUInteger)nb
{
id representation;
if (elem == fsTrue || elem == fsFalse)
representation = [[ArrayRepBoolean alloc] initFilledWithBoolean:(elem == fsTrue ? 1 :0) count:nb];
else if (isNSNumberWithLosslessConversionToDouble(elem))
representation = [[ArrayRepDouble alloc] initFilledWithDouble:[(NSNumber *)elem doubleValue] count:nb];
else
representation = [[ArrayRepId alloc] initFilledWith:elem count:nb];
if (representation) return [self initWithRepNoRetain:representation];
else
{
[super dealloc];
return nil;
}
}
- (id)initWithCapacity:(NSUInteger)aNumItems
{
return [self initWithRepNoRetain:[[ArrayRepEmpty alloc] initWithCapacity:aNumItems]];
}
- (id)initWithObject:(id)object
{
if (self = [self initWithCapacity:1])
{
[self addObject:object];
return self;
}
return nil;
}
- (id)initWithObjects:(id *)objects count:(NSUInteger)nb
{
NSUInteger i;
if (self = [self initWithCapacity:nb])
{
for (i = 0; i < nb; i++) [self addObject:objects[i]];
return self;
}
return nil;
}
- (FSArray *)initWithRep:(id)theRep
{
return [self initWithRepNoRetain:[theRep retain]];
}
- (FSArray *)initWithRepNoRetain:(id)theRep //designated initializer
{
if ((self = [super init]))
{
retainCount = 1;
type = [theRep repType];
rep = theRep;
return self;
}
return nil;
}
- (void)insertObject:anObject atIndex:(NSUInteger)index
{
if (index > [self count])
[NSException raise:NSRangeException format:@"index beyond the end of the array in method -insertObject:atIndex"];
if (type == DOUBLE && isNSNumberWithLosslessConversionToDouble(anObject))
[(ArrayRepDouble *)rep insertDouble:[anObject doubleValue] atIndex:index];
else
{
if (type != FS_ID) [self becomeArrayOfId];
[(ArrayRepId *)rep insertObject:anObject atIndex:index];
}
}
- (BOOL) isEqualToArray:(NSArray *)anArray
{
NSUInteger count = [self count];
NSUInteger i;
if (count != [anArray count]) return NO;
for (i = 0; i < count; i++)
{
id e1 = [self objectAtIndex:i];
id e2 = [anArray objectAtIndex:i];
if (![e1 isEqual:e2] && !(e1 == nil && e2 == nil))
break;
}
return i == count;
}
- (id)mutableCopyWithZone:(NSZone *)zone
{
return [[FSArray alloc] initWithRepNoRetain:[rep copyWithZone:zone]];
}
- (id)objectAtIndex:(NSUInteger)index
{
switch (type)
{
case FS_ID:
if (index >= ((ArrayRepId *)rep)->count)
[NSException raise:NSRangeException format:@"index beyond the end of the array in method -ObjectAtIndex:"];
return ((ArrayRepId *)rep)->t[index];
case DOUBLE:
if (index >= ((ArrayRepDouble *)rep)->count)
[NSException raise:NSRangeException format:@"index beyond the end of the array in method -ObjectAtIndex:"];
return [FSNumber numberWithDouble:((ArrayRepDouble *)rep)->t[index]];
case BOOLEAN:
if (index >= ((ArrayRepBoolean *)rep)->count)
[NSException raise:NSRangeException format:@"index beyond the end of the array in method -ObjectAtIndex:"];
return (((ArrayRepBoolean *)rep)->t[index] ? (id)fsTrue : (id)fsFalse);
case EMPTY:
[NSException raise:NSRangeException format:@"index beyond the end of the array in method -ObjectAtIndex:"];
case FETCH_REQUEST:
[self becomeArrayOfId];
return [self objectAtIndex:index];
} // end switch
return nil; // W
}
- (NSEnumerator *)objectEnumerator
{
return [[[FSArrayEnumerator alloc] initWithArray:self reverse:NO] autorelease];
}
- (void)removeLastObject
{
if ([rep count] == 0) [NSException raise:NSRangeException format:@"-removeLastObject called on an empty array"];
if ([rep respondsToSelector:@selector(removeLastElem)]) [rep removeLastElem];
else
{
[self becomeArrayOfId];
[rep removeLastElem];
}
}
- (void)removeObjectAtIndex:(NSUInteger)index
{
if (index >= [self count])
[NSException raise:NSRangeException format:@"index beyond the end of the array in method -removeObjectAtIndex:"];
if ([rep respondsToSelector:@selector(removeElemAtIndex:)]) [rep removeElemAtIndex:index];
else
{
[self becomeArrayOfId];
[rep removeElemAtIndex:index];
}
}
- (id)replacementObjectForCoder:(NSCoder *)aCoder
{
//id superReplacement = [super replacementObjectForCoder:aCoder];
if ([self containsObject:nil])
{
FSArray *r = [[[FSArray alloc ] initWithCapacity:[self count]] autorelease];
FSReplacementForCoderForNilInArray *replacementForNil = [[[FSReplacementForCoderForNilInArray alloc] init] autorelease];
NSUInteger i, count;
for (i = 0, count = [self count]; i < count; i++)
{
id elem = [self objectAtIndex:i];
if (elem == nil)
[r addObject:replacementForNil];
else
[r addObject:elem];
}
return r;
}
return self;
}
- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
// Overhide the NSArray behavior (which is to pass arrays by copy by default), with a by reference behavior by default.
// This is because passing an object by copy only works if the receiving process is linked with the class of the object.
// In our case, we want to support passing Arrays to applications that are not linked with the F-Script framework.
{
if ([encoder isBycopy]) return self;
else return [NSDistantObject proxyWithLocal:self connection:[encoder connection]];
}
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject
{
if (index >= [rep count])
[NSException raise:NSRangeException format:@"index beyond the end of the array in method -replaceObjectAtIndex:withObject:"];
if (type == DOUBLE)
{
if (anObject && object_getClass(anObject) == FSNumberClass) // anObject is casted to avoid the warning "static access to object of type id"
[(ArrayRepDouble *)rep replaceDoubleAtIndex:index withDouble:((FSNumber *)anObject)->value];
else if (anObject && isNSNumberWithLosslessConversionToDouble(anObject))
[(ArrayRepDouble *)rep replaceDoubleAtIndex:index withDouble:[anObject doubleValue]];
else
{
[self becomeArrayOfId];
[(ArrayRepId *)rep replaceObjectAtIndex:index withObject:anObject];
}
}
else if (type == BOOLEAN && (anObject == fsTrue || anObject == fsFalse))
[(ArrayRepBoolean *)rep replaceBooleanAtIndex:index withBoolean:(anObject == fsTrue ? 1 : 0)];
else
{
if (type != FS_ID) [self becomeArrayOfId];
[(ArrayRepId *)rep replaceObjectAtIndex:index withObject:anObject];
}
}
- (id)retain { retainCount++; return self;}
- (NSUInteger)retainCount { return retainCount;}
- (void)release { if (--retainCount == 0) [self dealloc];}
- (NSEnumerator *)reverseObjectEnumerator
{
return [[[FSArrayEnumerator alloc] initWithArray:self reverse:YES] autorelease];
}
- (void)setArray:(NSArray *)operand
{
id oldRep = rep;
if ([operand isKindOfClass:[FSArray class]])
{
if ([operand isProxy]) // we test for proxy because we don't want to have a Proxy as array rep.
{
NSUInteger i;
NSUInteger nb = [operand count];
type = EMPTY;
rep = [[ArrayRepEmpty alloc] initWithCapacity:nb];
for(i = 0; i < nb; i++) [self addObject:[operand objectAtIndex:i]];
}
else
{
type = [(FSArray *)operand type];
rep = [[(FSArray *)operand arrayRep] copy];
}
[oldRep release];
}
else [super setArray:operand];
}
- (NSArray *)subarrayWithRange:(NSRange)range
{
if (range.location + range.length > [self count]) return [super subarrayWithRange:range]; // will raise an exception
if ([rep respondsToSelector:@selector(subarrayWithRange:)]) return [rep subarrayWithRange:range];
else
{
[self becomeArrayOfId];
return [rep subarrayWithRange:range];
}
}
- (enum ArrayRepType)type { return type;} // declared in ArrayPrivate
///////////////////////////////// PRIVATE FOR USE BY FSExecEngine ///////////////
-(NSUInteger) _ul_count { return [self count]; }
- (id)_ul_objectAtIndex:(NSUInteger)index
{
switch (type)
{
case FS_ID : return ((ArrayRepId *)rep)->t[index];
case DOUBLE : return [FSNumber numberWithDouble:((ArrayRepDouble *)rep)->t[index]];
case BOOLEAN: return ((ArrayRepBoolean *)rep)->t[index] ? (id)fsTrue : (id)fsFalse;
case EMPTY : assert(0);
case FETCH_REQUEST: return [self objectAtIndex:index];
}
return nil; // W
}
@end