Oolite
Loading...
Searching...
No Matches
OORoleSet.h File Reference
import "OOFoundation.h"
Include dependency graph for OORoleSet.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  OORoleSet

Functions

NSDictionary * OOParseRolesFromString (NSString *string)

Function Documentation

◆ OOParseRolesFromString()

NSDictionary * OOParseRolesFromString ( NSString * string)

Definition at line 286 of file OORoleSet.m.

287{
288 NSMutableDictionary* result = nil;
289 NSArray* tokens = nil;
290 NSUInteger i, count;
291 NSString* role = nil;
292 float probability;
293 NSScanner* scanner = nil;
294
295 // Split string at spaces, sanity checks, set-up.
296 if (string == nil)
297 return nil;
298
299 tokens = ScanTokensFromString(string);
300 count = [tokens count];
301 if (count == 0)
302 return nil;
303
304 result = [NSMutableDictionary dictionaryWithCapacity:count];
305
306 // Scan tokens, looking for probabilities.
307 for (i = 0; i != count; ++i) {
308 role = [tokens objectAtIndex:i];
309
310 probability = 1.0f;
311 if ([role rangeOfString:@"("].location != NSNotFound) {
312 scanner = [[NSScanner alloc] initWithString:role];
313 [scanner scanUpToString:@"(" intoString:&role];
314 [scanner scanString:@"(" intoString:NULL];
315 if (![scanner scanFloat:&probability])
316 probability = 1.0f;
317 // Ignore rest of string
318
319 [scanner release];
320 }
321
322 // shipKey roles start with [ so other roles can't
323 if (0 <= probability && ![role hasPrefix:@"["]) {
324 [result setObject:[NSNumber numberWithFloat:probability] forKey:role];
325 }
326 }
327
328 if ([result count] == 0)
329 result = nil;
330 return result;
331}
unsigned count
return nil
NSMutableArray * ScanTokensFromString(NSString *values)

References count, nil, and ScanTokensFromString().

Referenced by OORoleSet::initWithRoleString:, and OOShipRegistry(OODataLoader)::mergeShipRoles:forShipKey:intoProbabilityMap:.

Here is the call graph for this function:
Here is the caller graph for this function: