Oolite
Loading...
Searching...
No Matches
OOSystemDescriptionEntry Class Reference

#include <OOSystemDescriptionManager.h>

Inheritance diagram for OOSystemDescriptionEntry:
Collaboration diagram for OOSystemDescriptionEntry:

Instance Methods

(void) - setProperty:forLayer:toValue:
(id) - getProperty:forLayer:
(id) - init [implementation]
(void) - dealloc [implementation]
(id) - validateProperty:withValue: [implementation]

Private Attributes

NSMutableDictionary * layers [OO_SYSTEM_LAYERS]

Detailed Description

Definition at line 52 of file OOSystemDescriptionManager.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 547 of file OOSystemDescriptionManager.m.

548{
549 for (NSUInteger i = 0; i < OO_SYSTEM_LAYERS; i++) {
550 DESTROY(layers[i]);
551 }
552 [super dealloc];
553}
#define DESTROY(x)
#define OO_SYSTEM_LAYERS
NSMutableDictionary * layers[OO_SYSTEM_LAYERS]

References dealloc, DESTROY, layers, and OO_SYSTEM_LAYERS.

Referenced by dealloc.

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

◆ getProperty:forLayer:

- (id) getProperty: (NSString*) property
forLayer: (OOSystemLayer) layer 

Definition at line 570 of file OOSystemDescriptionManager.m.

570 :(NSString*)property forLayer:(OOSystemLayer)layer
571{
572 return [layers[layer] objectForKey:property];
573}

Referenced by OOSystemDescriptionManager(OOPrivate)::getProperty:forSystemKey:withUniversal:, and OOSystemDescriptionManager(OOPrivate)::getProperty:orProperty:forSystemKey:withUniversal:.

Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 536 of file OOSystemDescriptionManager.m.

537{
538 self = [super init];
539 if (self != nil) {
540 for (NSUInteger i = 0; i < OO_SYSTEM_LAYERS; i++) {
541 layers[i] = [[NSMutableDictionary alloc] initWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
542 }
543 }
544 return self;
545}
return nil

References init, layers, nil, and OO_SYSTEM_LAYERS.

Referenced by init.

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

◆ setProperty:forLayer:toValue:

- (void) setProperty: (NSString*) property
forLayer: (OOSystemLayer) layer
toValue: (id) value 

Definition at line 555 of file OOSystemDescriptionManager.m.

555 :(NSString*)property forLayer:(OOSystemLayer)layer toValue:(id)value
556{
557 if (value == nil) {
558 [layers[layer] removeObjectForKey:property];
559 } else {
560 // validate type of object for certain properties
561 value = [self validateProperty:property withValue:value];
562 // if it's nil now, validation failed and could not be recovered
563 // so don't actually set anything
564 if (value != nil) {
565 [layers[layer] setObject:value forKey:property];
566 }
567 }
568}

References nil, and validateProperty:withValue:.

Referenced by OOSystemDescriptionManager(OOPrivate)::setProperties:inDescription:, and OOSystemDescriptionManager::setProperty:forSystemKey:andLayer:toValue:fromManifest:.

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

◆ validateProperty:withValue:

- (id) validateProperty: (NSString*) property
withValue: (id) value 
implementation

Provided by category OOSystemDescriptionEntry(OOPrivate).

Definition at line 580 of file OOSystemDescriptionManager.m.

580 :(NSString*)property withValue:(id)value
581{
582 if ([property isEqualToString:@"coordinates"]) {
583 // must be a string with two numbers in it
584 // TODO: convert two element arrays
585 if (![value isKindOfClass:[NSString class]]) {
586 OOLog(@"system.description.error", @"'%@' is not a valid format for coordinates", value);
587 return nil;
588 }
589 NSArray* tokens = ScanTokensFromString((NSString*)value);
590 if ([tokens count] != 2) {
591 OOLog(@"system.description.error", @"'%@' is not a valid format for coordinates (must have exactly two numbers)", value);
592 return nil;
593 }
594 } else if ([property isEqualToString:@"radius"] || [property isEqualToString:@"government"]) {
595 // read in a context which expects a string, but it's a string representation of a number
596 if (![value isKindOfClass:[NSString class]]) {
597 if ([value isKindOfClass:[NSNumber class]]) {
598 return [value stringValue];
599 } else {
600 OOLog(@"system.description.error", @"'%@' is not a valid value for '%@' (string required)", value, property);
601 return nil;
602 }
603 }
604 } else if ([property isEqualToString:@"inhabitant"] || [property isEqualToString:@"inhabitants"] || [property isEqualToString:@"name"]) {
605 // read in a context which expects a string
606 if (![value isKindOfClass:[NSString class]]) {
607 OOLog(@"system.description.error", @"'%@' is not a valid value for '%@' (string required)", value, property);
608 return nil;
609 }
610 }
611
612 return value;
613}
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
NSMutableArray * ScanTokensFromString(NSString *values)

References count, nil, OOLog, and ScanTokensFromString().

Referenced by setProperty:forLayer:toValue:.

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

Member Data Documentation

◆ layers

- (NSMutableDictionary* layers[OO_SYSTEM_LAYERS])
private

Definition at line 54 of file OOSystemDescriptionManager.h.

Referenced by dealloc, and init.


The documentation for this class was generated from the following files: