Oolite 1.91.0.7644-241112-7f5034b
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 56 of file OOSystemDescriptionManager.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 58 of file OOSystemDescriptionManager.m.

656{
657 for (NSUInteger i=0;i<OO_SYSTEM_LAYERS;i++)
658 {
659 DESTROY(layers[i]);
660 }
661 [super dealloc];
662}
#define DESTROY(x)
Definition OOCocoa.h:77
#define OO_SYSTEM_LAYERS
NSMutableDictionary * layers[OO_SYSTEM_LAYERS]

◆ getProperty:forLayer:

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

Definition at line 58 of file OOSystemDescriptionManager.m.

685 :(NSString *)property forLayer:(OOSystemLayer)layer
686{
687 return [layers[layer] objectForKey:property];
688}

◆ init

- (id) init
implementation

Definition at line 58 of file OOSystemDescriptionManager.m.

642{
643 self = [super init];
644 if (self != nil)
645 {
646 for (NSUInteger i=0;i<OO_SYSTEM_LAYERS;i++)
647 {
648 layers[i] = [[NSMutableDictionary alloc] initWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
649 }
650 }
651 return self;
652}
return nil

◆ setProperty:forLayer:toValue:

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

Definition at line 58 of file OOSystemDescriptionManager.m.

665 :(NSString *)property forLayer:(OOSystemLayer)layer toValue:(id)value
666{
667 if (value == nil)
668 {
669 [layers[layer] removeObjectForKey:property];
670 }
671 else
672 {
673 // validate type of object for certain properties
674 value = [self validateProperty:property withValue:value];
675 // if it's nil now, validation failed and could not be recovered
676 // so don't actually set anything
677 if (value != nil)
678 {
679 [layers[layer] setObject:value forKey:property];
680 }
681 }
682}

◆ validateProperty:withValue:

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

Provided by category OOSystemDescriptionEntry(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

696 :(NSString *)property withValue:(id)value
697{
698 if ([property isEqualToString:@"coordinates"])
699 {
700 // must be a string with two numbers in it
701 // TODO: convert two element arrays
702 if (![value isKindOfClass:[NSString class]])
703 {
704 OOLog(@"system.description.error",@"'%@' is not a valid format for coordinates",value);
705 return nil;
706 }
707 NSArray *tokens = ScanTokensFromString((NSString *)value);
708 if ([tokens count] != 2)
709 {
710 OOLog(@"system.description.error",@"'%@' is not a valid format for coordinates (must have exactly two numbers)",value);
711 return nil;
712 }
713 }
714 else if ([property isEqualToString:@"radius"] || [property isEqualToString:@"government"])
715 {
716 // read in a context which expects a string, but it's a string representation of a number
717 if (![value isKindOfClass:[NSString class]])
718 {
719 if ([value isKindOfClass:[NSNumber class]])
720 {
721 return [value stringValue];
722 }
723 else
724 {
725 OOLog(@"system.description.error",@"'%@' is not a valid value for '%@' (string required)",value,property);
726 return nil;
727 }
728 }
729 }
730 else if ([property isEqualToString:@"inhabitant"] || [property isEqualToString:@"inhabitants"] || [property isEqualToString:@"name"] )
731 {
732 // read in a context which expects a string
733 if (![value isKindOfClass:[NSString class]])
734 {
735 OOLog(@"system.description.error",@"'%@' is not a valid value for '%@' (string required)",value,property);
736 return nil;
737 }
738 }
739
740 return value;
741}
#define OOLog(class, format,...)
Definition OOLogging.h:88
unsigned count
NSMutableArray * ScanTokensFromString(NSString *values)

Member Data Documentation

◆ layers

- (NSMutableDictionary* layers[OO_SYSTEM_LAYERS])
private

Definition at line 59 of file OOSystemDescriptionManager.h.


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