IntegerArray.m
author Jens Alfke <jens@mooseyard.com>
Wed Jul 01 14:04:56 2009 -0700 (2009-07-01)
changeset 33 d52f6b0d94be
permissions -rw-r--r--
Added NSData categories for GZip and Mnemonicode.
Minor tweaks elsewhere.
jens@15
     1
//
jens@15
     2
//  IntegerArray.m
jens@15
     3
//  Cloudy
jens@15
     4
//
jens@15
     5
//  Created by Jens Alfke on 6/23/08.
jens@15
     6
//  Copyright 2008 Jens Alfke. All rights reserved.
jens@15
     7
//
jens@15
     8
jens@15
     9
#import "IntegerArray.h"
jens@15
    10
jens@15
    11
jens@15
    12
@implementation IntegerArray
jens@15
    13
jens@15
    14
- (id) init
jens@15
    15
{
jens@15
    16
    self = [super init];
jens@15
    17
    if (self != nil) {
jens@15
    18
        _storage = [[NSMutableData alloc] initWithCapacity: 10*sizeof(SInt32)];
jens@15
    19
    }
jens@15
    20
    return self;
jens@15
    21
}
jens@15
    22
jens@15
    23
- (void) dealloc
jens@15
    24
{
jens@15
    25
    [_storage release];
jens@15
    26
    [super dealloc];
jens@15
    27
}
jens@15
    28
jens@15
    29
jens@15
    30
jens@15
    31
- (NSUInteger)count             {return _count;}
jens@15
    32
- (const SInt32*) allIntegers   {return _integers;}
jens@15
    33
jens@15
    34
- (SInt32) integerAtIndex: (NSUInteger)index
jens@15
    35
{
jens@15
    36
    Assert(index<_count);
jens@15
    37
    return _integers[index];
jens@15
    38
}
jens@15
    39
jens@15
    40
- (void) setInteger: (SInt32)value atIndex: (NSUInteger)index
jens@15
    41
{
jens@15
    42
    Assert(index<_count);
jens@15
    43
    _integers[index] = value;
jens@15
    44
}
jens@15
    45
jens@15
    46
- (void) addInteger: (SInt32)value
jens@15
    47
{
jens@15
    48
    [_storage appendBytes: &value length: sizeof(value)];
jens@15
    49
    _count++;
jens@15
    50
    _integers = [_storage mutableBytes];
jens@15
    51
}
jens@15
    52
jens@15
    53
@end