Source/Stack.m
changeset 27 b0affce7beb1
parent 1 3eb7be1dd7b6
     1.1 --- a/Source/Stack.m	Mon Mar 10 17:30:57 2008 -0700
     1.2 +++ b/Source/Stack.m	Tue Mar 10 22:36:23 2009 -0700
     1.3 @@ -63,6 +63,18 @@
     1.4  @synthesize bits=_bits;
     1.5  
     1.6  
     1.7 +- (NSUInteger) numberOfBits
     1.8 +{
     1.9 +    return _bits.count;
    1.10 +}
    1.11 +
    1.12 +- (void) setNumberOfBits: (NSUInteger)n
    1.13 +{
    1.14 +    NSAssert2(n<=_bits.count,@"Cannot increase numberOfBits (from %u to %u)", _bits.count,n);
    1.15 +    while( _bits.count > n )
    1.16 +        [self removeBit: self.topBit];
    1.17 +}
    1.18 +
    1.19  - (Bit*) topBit
    1.20  {
    1.21      return [_bits lastObject];
    1.22 @@ -98,6 +110,16 @@
    1.23  }
    1.24  
    1.25  
    1.26 +- (void) removeBit: (Bit*)bit
    1.27 +{
    1.28 +    NSUInteger index = [_bits indexOfObjectIdenticalTo: bit];
    1.29 +    if( index != NSNotFound ) {
    1.30 +        [bit removeFromSuperlayer];
    1.31 +        [_bits removeObjectAtIndex: index];
    1.32 +    }
    1.33 +}
    1.34 +
    1.35 +
    1.36  - (void) setHighlighted: (BOOL)highlighted
    1.37  {
    1.38      [super setHighlighted: highlighted];