Added IntegerArray.
authorJens Alfke <jens@mooseyard.com>
Tue Jun 24 12:05:24 2008 -0700 (2008-06-24)
changeset 1506e7d03fd23e
parent 14 1af6415650bf
child 16 ce9c83f7ec14
Added IntegerArray.
IntegerArray.h
IntegerArray.m
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/IntegerArray.h	Tue Jun 24 12:05:24 2008 -0700
     1.3 @@ -0,0 +1,25 @@
     1.4 +//
     1.5 +//  IntegerArray.h
     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 <Cocoa/Cocoa.h>
    1.13 +
    1.14 +
    1.15 +@interface IntegerArray : NSObject {
    1.16 +    NSMutableData *_storage;
    1.17 +    SInt32 *_integers;
    1.18 +    NSUInteger _count;
    1.19 +}
    1.20 +
    1.21 +- (NSUInteger)count;
    1.22 +- (const SInt32*) allIntegers;
    1.23 +
    1.24 +- (SInt32) integerAtIndex: (NSUInteger)index;
    1.25 +- (void) setInteger: (SInt32)value atIndex: (NSUInteger)index;
    1.26 +- (void) addInteger: (SInt32)value;
    1.27 +
    1.28 +@end
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/IntegerArray.m	Tue Jun 24 12:05:24 2008 -0700
     2.3 @@ -0,0 +1,53 @@
     2.4 +//
     2.5 +//  IntegerArray.m
     2.6 +//  Cloudy
     2.7 +//
     2.8 +//  Created by Jens Alfke on 6/23/08.
     2.9 +//  Copyright 2008 Jens Alfke. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +#import "IntegerArray.h"
    2.13 +
    2.14 +
    2.15 +@implementation IntegerArray
    2.16 +
    2.17 +- (id) init
    2.18 +{
    2.19 +    self = [super init];
    2.20 +    if (self != nil) {
    2.21 +        _storage = [[NSMutableData alloc] initWithCapacity: 10*sizeof(SInt32)];
    2.22 +    }
    2.23 +    return self;
    2.24 +}
    2.25 +
    2.26 +- (void) dealloc
    2.27 +{
    2.28 +    [_storage release];
    2.29 +    [super dealloc];
    2.30 +}
    2.31 +
    2.32 +
    2.33 +
    2.34 +- (NSUInteger)count             {return _count;}
    2.35 +- (const SInt32*) allIntegers   {return _integers;}
    2.36 +
    2.37 +- (SInt32) integerAtIndex: (NSUInteger)index
    2.38 +{
    2.39 +    Assert(index<_count);
    2.40 +    return _integers[index];
    2.41 +}
    2.42 +
    2.43 +- (void) setInteger: (SInt32)value atIndex: (NSUInteger)index
    2.44 +{
    2.45 +    Assert(index<_count);
    2.46 +    _integers[index] = value;
    2.47 +}
    2.48 +
    2.49 +- (void) addInteger: (SInt32)value
    2.50 +{
    2.51 +    [_storage appendBytes: &value length: sizeof(value)];
    2.52 +    _count++;
    2.53 +    _integers = [_storage mutableBytes];
    2.54 +}
    2.55 +
    2.56 +@end