# HG changeset patch # User Jens Alfke # Date 1214334324 25200 # Node ID 06e7d03fd23e9e896550ce516a7bcb1f5100789b # Parent 1af6415650bfd1e0af0affa7d811c8d46258620c Added IntegerArray. diff -r 1af6415650bf -r 06e7d03fd23e IntegerArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IntegerArray.h Tue Jun 24 12:05:24 2008 -0700 @@ -0,0 +1,25 @@ +// +// IntegerArray.h +// Cloudy +// +// Created by Jens Alfke on 6/23/08. +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import + + +@interface IntegerArray : NSObject { + NSMutableData *_storage; + SInt32 *_integers; + NSUInteger _count; +} + +- (NSUInteger)count; +- (const SInt32*) allIntegers; + +- (SInt32) integerAtIndex: (NSUInteger)index; +- (void) setInteger: (SInt32)value atIndex: (NSUInteger)index; +- (void) addInteger: (SInt32)value; + +@end diff -r 1af6415650bf -r 06e7d03fd23e IntegerArray.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IntegerArray.m Tue Jun 24 12:05:24 2008 -0700 @@ -0,0 +1,53 @@ +// +// IntegerArray.m +// Cloudy +// +// Created by Jens Alfke on 6/23/08. +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import "IntegerArray.h" + + +@implementation IntegerArray + +- (id) init +{ + self = [super init]; + if (self != nil) { + _storage = [[NSMutableData alloc] initWithCapacity: 10*sizeof(SInt32)]; + } + return self; +} + +- (void) dealloc +{ + [_storage release]; + [super dealloc]; +} + + + +- (NSUInteger)count {return _count;} +- (const SInt32*) allIntegers {return _integers;} + +- (SInt32) integerAtIndex: (NSUInteger)index +{ + Assert(index<_count); + return _integers[index]; +} + +- (void) setInteger: (SInt32)value atIndex: (NSUInteger)index +{ + Assert(index<_count); + _integers[index] = value; +} + +- (void) addInteger: (SInt32)value +{ + [_storage appendBytes: &value length: sizeof(value)]; + _count++; + _integers = [_storage mutableBytes]; +} + +@end