calc/calcHsm.c File Reference

#include "calcHsm.h"
#include <stdlib.h>
#include <stdio.h>

Functions

stnext on (int signal, void *param)
stnext ready (int signal, void *param)
stnext result (int signal, void *param)
stnext begin (int signal, void *param)
stnext negated1 (int signal, void *param)
stnext operand1 (int signal, void *param)
stnext zero1 (int signal, void *param)
stnext int1 (int signal, void *param)
stnext frac1 (int signal, void *param)
stnext error (int signal, void *param)
stnext opEntered (int signal, void *param)
stnext negated2 (int signal, void *param)
stnext operand2 (int signal, void *param)
stnext zero2 (int signal, void *param)
stnext int2 (int signal, void *param)
stnext frac2 (int signal, void *param)
void calchsm_init (Ihandle *tb)
void calchsm_signal (int signal, void *param)
void zero (void)
void negate (void)
void append (char c)
double calc (double operand1, double operand2, char operator_)

Variables

simplehsm_t hsm = {NULL}
Ihandle * textbox = NULL
BOOL clear_on_next
BOOL negative
double _operand1
char _operator

Detailed Description

Author:
Daniel Newton <djpnewton@gmail.com>
Version:
1.0

LICENSE

Copyright (c) 2009 Daniel Newton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DESCRIPTION

The calc state machine

Function Documentation

void append ( char  c  ) 

Append a character to the textbox input, if the clear_on_next variable is set then clear the textbox first

Parameters:
c The character to insert

stnext begin ( int  signal,
void *  param 
)

The 'begin' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise ready() (the parent state)

double calc ( double  operand1,
double  operand2,
char  operator_ 
)

Calculate the result of a function

Parameters:
operand1 The first operand
operand2 The second operand
operator_ The operator (+, -, *, /) to use
Returns:
The result of the function

void calchsm_init ( Ihandle *  tb  ) 

Initialize the calc state machine

Parameters:
tb The IUP textbox widget that the calc state machine will use

void calchsm_signal ( int  signal,
void *  param 
)

Send a signal to the calc state machine

Parameters:
signal The signal to send
param An optional parameter

stnext error ( int  signal,
void *  param 
)

The 'error' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
on() (the parent state)

stnext frac1 ( int  signal,
void *  param 
)

The 'frac1' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise operand1() (the parent state)

stnext frac2 ( int  signal,
void *  param 
)

The 'frac2' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise operand2() (the parent state)

stnext int1 ( int  signal,
void *  param 
)

The 'int1' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise operand1() (the parent state)

stnext int2 ( int  signal,
void *  param 
)

The 'int2' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise operand2() (the parent state)

void negate ( void   ) 

Clear the textbox input and replace with a '-0' string also set the negative variable

stnext negated1 ( int  signal,
void *  param 
)

The 'negated1' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise on() (the parent state)

stnext negated2 ( int  signal,
void *  param 
)

The 'negated2' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise on() (the parent state)

stnext on ( int  signal,
void *  param 
)

The 'on' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
Always NULL as this is the top level state function

stnext opEntered ( int  signal,
void *  param 
)

The 'opEntered' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise on() (the parent state)

stnext operand1 ( int  signal,
void *  param 
)

The 'operand1' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise on() (the parent state)

stnext operand2 ( int  signal,
void *  param 
)

The 'operand2' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise on() (the parent state)

Todo:
handle error like so:
 IupSetAttribute(textbox, "VALUE", "ERROR");
 simplehsm_transition_state(&hsm, error);

Todo:
handle error like so:
 IupSetAttribute(textbox, "VALUE", "ERROR");
 simplehsm_transition_state(&hsm, error);

stnext ready ( int  signal,
void *  param 
)

The 'ready' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise on() (the parent state)

stnext result ( int  signal,
void *  param 
)

The 'result' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
ready() (the parent state)

void zero ( void   ) 

Clear the textbox input and replace with a '0' string also reset the negative variable

stnext zero1 ( int  signal,
void *  param 
)

The 'zero1' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise operand1() (the parent state)

stnext zero2 ( int  signal,
void *  param 
)

The 'zero2' state functon

Parameters:
signal The signal to handle
param The accompaning parameter
Returns:
NULL if the signal is handled otherwise operand2() (the parent state)


Variable Documentation

double _operand1

The first operand

char _operator

The current operator

If this flag is set we clear the textbox and replace text with new character on the next signal

simplehsm_t hsm = {NULL}

The Calc state machine object

BOOL negative

If this flag is set the current operand will be negative

Ihandle* textbox = NULL

The IUP textbox widget


Generated on Thu Feb 4 09:32:56 2010 for simplehsm(C) by  doxygen 1.5.9