Added Lots of Documentation
Added some nice to haves Improved and Unified General Code Layout
This commit is contained in:
@@ -8,13 +8,21 @@
|
||||
|
||||
#import "MPEvaluationContext.h"
|
||||
|
||||
|
||||
|
||||
@interface MPEvaluationContext ()
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *stack;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation MPEvaluationContext
|
||||
|
||||
static MPEvaluationContext *sharedContext;
|
||||
|
||||
|
||||
+ (MPEvaluationContext *)sharedContext
|
||||
{
|
||||
if (!sharedContext) {
|
||||
@@ -23,6 +31,7 @@ static MPEvaluationContext *sharedContext;
|
||||
return sharedContext;
|
||||
}
|
||||
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (sharedContext) {
|
||||
@@ -40,16 +49,19 @@ static MPEvaluationContext *sharedContext;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)push
|
||||
{
|
||||
[self.stack addObject:[[NSMutableDictionary alloc] init]];
|
||||
}
|
||||
|
||||
|
||||
- (void)pop
|
||||
{
|
||||
[self.stack removeLastObject];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)defineVariable:(NSString *)variable
|
||||
value:(NSDecimalNumber *)value
|
||||
{
|
||||
@@ -62,17 +74,20 @@ static MPEvaluationContext *sharedContext;
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)undefineVariable:(NSString *)variable
|
||||
{
|
||||
NSMutableDictionary *currentBindings = self.stack.lastObject;
|
||||
[currentBindings removeObjectForKey:variable];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)isVariableDefined:(NSString *)variable
|
||||
{
|
||||
return [self valueForVariable:variable] != nil;
|
||||
}
|
||||
|
||||
|
||||
- (NSDecimalNumber *)valueForVariable:(NSString *)variable
|
||||
{
|
||||
NSUInteger currentIndex = self.stack.count;
|
||||
|
||||
Reference in New Issue
Block a user