Skip to content

Commit

Permalink
Merge pull request #32 from newmanw/enumeration
Browse files Browse the repository at this point in the history
Fix bug feature row enumeration
  • Loading branch information
bosborn authored Jul 10, 2017
2 parents 4fbff65 + ae5beea commit fc90e2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Adheres to [Semantic Versioning](http://semver.org/).
## 1.2.3 (TBD)

* TBD
* Fix bug in feature row enumeration.

## [1.2.2](https://github.com/ngageoint/geopackage-ios/releases/tag/1.2.2) (06-14-2017)

Expand Down
36 changes: 20 additions & 16 deletions geopackage-ios/features/index/GPKGFeatureIndexResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

@interface GPKGFeatureIndexResults ()

@property (nonatomic, strong) GPKGResultSet *results;

/**
* Used to keep the current feature row reference to preven loss of pointers within the unsafe unreatined feature row
* Strong reference of enumerated feature rows to prevent garbage collection of enumerated items.
*/
@property (nonatomic, strong) GPKGFeatureRow *featureRow;
@property (nonatomic, strong) NSMutableArray *rows;
@property (nonatomic, strong) GPKGResultSet *results;

@end

Expand All @@ -42,26 +41,31 @@ -(void) close{
[self.results close];
}

- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len {

- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len{
self.rows = [NSMutableArray arrayWithCapacity:len];

// First call
if(state->state == 0)
{
if(state->state == 0){
state->mutationsPtr = &state->extra[0];
state->state = 1;
}

// Verify there are more results to return
if(![self.results moveToNext]){
return 0;
}
state->itemsPtr = stackbuf;

// Get and set the feature row
self.featureRow = [self getFeatureRow];
__unsafe_unretained GPKGFeatureRow * tempFeatureRow = self.featureRow;
state->itemsPtr = &tempFeatureRow;
NSUInteger count = 0;
while (count < len) {
if(![self.results moveToNext]){
break;
}

GPKGFeatureRow * row = [self getFeatureRow];
[self.rows addObject:row];
stackbuf[count] = row;
count += 1;
}

return 1;
return count;
}

-(GPKGFeatureRow *) getFeatureRow{
Expand Down

0 comments on commit fc90e2b

Please sign in to comment.