Skip to content

Instantly share code, notes, and snippets.

@boucher
Forked from anonymous/gist:16350
Created October 12, 2008 01:45
Show Gist options
  • Save boucher/16351 to your computer and use it in GitHub Desktop.
Save boucher/16351 to your computer and use it in GitHub Desktop.
import <Foundation/CPObject.j>
@implementation CalculatorLogic : CPObject
{
CPNumber currentValue;
CPString acumulatedValue;
var decimalPointActive;
//1 * 0.1 * 0.1 in Js = 0.010000000000000002 :) Strings never fails!!!
id changeValueNotifyDelegate;
}
- (id)init
{
self = [super init];
if (self)
{
currentValue = [[CPString alloc] init];
acumulatedValue = [[CPNumber alloc] initWithInt:0];
decimalPointActive = NO;
}
return self;
}
-(void)setNotifyInstance:(id)aInstance
{
changeValueNotifyDelegate = aInstance;
}
-(void)notifyInstance
{
if ([changeValueNotifyDelegate respondsToSelector:@selector(displayValueChanged:)])
{
[changeValueNotifyDelegate displayValueChanged:[self getCurrentValue]];
}
}
-(CPString)getCurrentValue
{
return currentValue;
}
-(void)press: (id)sender
{
var value = [sender objectValue];
if (value == "." && decimalPointActive == NO)
decimalPointActive = YES;
if (([currentValue length] != 0) || ([value isEqualToString:"0"] == NO))
{
currentValue = currentValue + value;
[self notifyInstance];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment