Implement fast enumeration.

FossilOrigin-Name: 2da674855b3d179b7524f02132638c404a62952fce04cc7a97907d133939c826
This commit is contained in:
Jonathan Schleifer 2012-10-30 22:33:40 +00:00
parent a5aa71484f
commit 74aa01c7cd
2 changed files with 36 additions and 0 deletions

View file

@ -108,6 +108,38 @@ convert_type(PGresult *res, int col, OFString *str)
initWithResult: result
row: row] autorelease];
}
- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
objects: (id*)objects
count: (int)count
{
int i, j;
if (state->extra[0] == 0) {
state->extra[0] = 1;
state->extra[1] = PQnfields(res);
}
if (count > SIZE_MAX - state->state)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
if (state->state + count > state->extra[1])
count = state->extra[1] - state->state;
for (i = j = 0; i < count; i++) {
if (PQgetisnull(res, row, state->state + i))
continue;
objects[j++] = [OFString stringWithUTF8String:
PQfname(res, state->state + i)];
}
state->state += count;
state->itemsPtr = objects;
state->mutationsPtr = (unsigned long*)self;
return j;
}
@end
@implementation PGResultRowEnumerator