IntegerArray.m
changeset 30 2befbe36c746
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/IntegerArray.m	Tue May 12 14:38:30 2009 +0200
     1.3 @@ -0,0 +1,53 @@
     1.4 +//
     1.5 +//  IntegerArray.m
     1.6 +//  Cloudy
     1.7 +//
     1.8 +//  Created by Jens Alfke on 6/23/08.
     1.9 +//  Copyright 2008 Jens Alfke. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import "IntegerArray.h"
    1.13 +
    1.14 +
    1.15 +@implementation IntegerArray
    1.16 +
    1.17 +- (id) init
    1.18 +{
    1.19 +    self = [super init];
    1.20 +    if (self != nil) {
    1.21 +        _storage = [[NSMutableData alloc] initWithCapacity: 10*sizeof(SInt32)];
    1.22 +    }
    1.23 +    return self;
    1.24 +}
    1.25 +
    1.26 +- (void) dealloc
    1.27 +{
    1.28 +    [_storage release];
    1.29 +    [super dealloc];
    1.30 +}
    1.31 +
    1.32 +
    1.33 +
    1.34 +- (NSUInteger)count             {return _count;}
    1.35 +- (const SInt32*) allIntegers   {return _integers;}
    1.36 +
    1.37 +- (SInt32) integerAtIndex: (NSUInteger)index
    1.38 +{
    1.39 +    Assert(index<_count);
    1.40 +    return _integers[index];
    1.41 +}
    1.42 +
    1.43 +- (void) setInteger: (SInt32)value atIndex: (NSUInteger)index
    1.44 +{
    1.45 +    Assert(index<_count);
    1.46 +    _integers[index] = value;
    1.47 +}
    1.48 +
    1.49 +- (void) addInteger: (SInt32)value
    1.50 +{
    1.51 +    [_storage appendBytes: &value length: sizeof(value)];
    1.52 +    _count++;
    1.53 +    _integers = [_storage mutableBytes];
    1.54 +}
    1.55 +
    1.56 +@end