Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented core notification routines on AQAppStateMachine.

  • Loading branch information...
commit 82e973f30381ec24ae1422d30849afae06094fe1 1 parent 70c15ef
Jim Dovey authored
View
40 AQAppStateMachine/AQAppStateMachine.m
@@ -44,36 +44,58 @@ - (void) dealloc
dispatch_release(_syncQ);
}
-- (void) notifyForChangesToStateBitAtIndex: (NSUInteger) index usingBlock: (void (^)(void)) block
+- (void) _runNotificationBlocksForChangeInRange: (NSRange) range
{
- [self notifyForChangesToStateBitsInRange: NSMakeRange(index, 1) usingBlock: block];
+ for ( AQStateMatchingDescriptor * match in _matchDescriptors )
+ {
+ if ( [match matchesRange: range] == NO )
+ continue;
+
+ dispatch_block_t block = (dispatch_block_t)[_notifierLookup objectForKey: [match uniqueID]];
+ if ( block != nil )
+ block();
+ }
}
-- (void) notifyForChangesToStateBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block
+- (void) _notifyForChangesToStatesMatchingDescriptor: (AQStateMatchingDescriptor *) desc
+ usingBlock: (void (^)(void)) block
{
- // create match descriptor and store it
- id desc = [[AQStateMatchingDescriptor alloc] initWithRange: range matchingMask: nil];
-
[_matchDescriptors addObject: desc];
[_notifierLookup setObject: block forKey: [desc uniqueID]];
- [_stateBits notifyModificationOfBitsInRange: range usingBlock: ^(NSRange range) {
+ NSRange notifyRange = desc.fullRange;
+ [_stateBits notifyModificationOfBitsInRange: notifyRange usingBlock: ^(NSRange range) {
// find and run any stored blocks
+ [self _runNotificationBlocksForChangeInRange: range];
}];
}
+- (void) notifyForChangesToStateBitAtIndex: (NSUInteger) index usingBlock: (void (^)(void)) block
+{
+ [self notifyForChangesToStateBitsInRange: NSMakeRange(index, 1) usingBlock: block];
+}
+
+- (void) notifyForChangesToStateBitsInRange: (NSRange) range usingBlock: (void (^)(void)) block
+{
+ // create match descriptor and store it
+ AQStateMatchingDescriptor * desc = [[AQStateMatchingDescriptor alloc] initWithRange: range matchingMask: nil];
+ [self _notifyForChangesToStatesMatchingDescriptor: desc usingBlock: block];
+}
+
- (void) notifyForChangesToStateBitsInRange: (NSRange) range
maskedWithInteger: (NSUInteger) mask
usingBlock: (void (^)(void)) block
{
-
+ AQStateMatchingDescriptor * desc = [[AQStateMatchingDescriptor alloc] initWith32BitMask: mask forRange: range];
+ [self _notifyForChangesToStatesMatchingDescriptor: desc usingBlock: block];
}
- (void) notifyForChangesToStateBitsInRange: (NSRange) range
maskedWithBits: (AQBitfield *) mask
usingBlock: (void (^)(void)) block
{
-
+ AQStateMatchingDescriptor * desc = [[AQStateMatchingDescriptor alloc] initWithRange: range matchingMask: mask];
+ [self _notifyForChangesToStatesMatchingDescriptor: desc usingBlock: block];
}
@end
View
2  AQAppStateMachine/AQStateMatchingDescriptor.h
@@ -17,9 +17,11 @@
}
// designated initializer
+// to specify 'no mask' in an array, use NSNull
- (id) initWithRanges: (NSIndexSet *) ranges matchingMasks: (NSArray *) masks;
@property (nonatomic, readonly) NSString * uniqueID;
+@property (nonatomic, readonly) NSRange fullRange;
- (BOOL) matchesRange: (NSRange) range;
View
5 AQAppStateMachine/AQStateMatchingDescriptor.m
@@ -58,6 +58,11 @@ - (id) initWithRanges: (NSIndexSet *) ranges matchingMasks: (NSArray *) masks
return ( self );
}
+- (NSRange) fullRange
+{
+ return ( NSMakeRange([_matchingIndices firstIndex], [_matchingIndices lastIndex] - [_matchingIndices firstIndex]) );
+}
+
- (BOOL) matchesRange: (NSRange) range
{
return ( [_matchingIndices intersectsIndexesInRange: range] );
Please sign in to comment.
Something went wrong with that request. Please try again.