Class model
Class defined in:src/js/model.js:21
The model contains the data of the application.
addChar( ch )
src/js/model.js:922
Add a character to the stack. This method is normally called from the event handler of the input keys.
Parameters:-
ch<String>The character to be added.
addConst( ch ) /* private method */
src/js/model.js:512
Primitive function to add a constant (omega) to the stack. Helper method for addChar. If an error occurs, it will be stored to the mErr property, so it can be handled later.
Parameters:-
ch<String>The constant to add (normally it is 'w').
addLeftBracket( ch ) /* private method */
src/js/model.js:606
Primitive function to add a left bracket to the stack. Helper method for addChar.
Parameters:-
ch<String>The bracket character, normally '('.
addNum( ch ) /* private method */
src/js/model.js:429
Primitive function to add a Digit to the stack. Helper method for addChar.
Parameters:-
ch<String>The character representing the number to add
addOptor( ch ) /* private method */
src/js/model.js:561
Primitive function to add an Operator to the stack. Helper method for addChar. Does not return anything. If an error occurred, then a ClassedError object is appended to the private property mErr. This error should be handled by the calling function.
Parameters:-
ch<String>The operator to add to the stack.
backSpace( )
src/js/model.js:996
This method performs an operation on the stack that is expected when pressing the backspace button. Which operation is actually performed depends on the state of the model. No return value
calculate( lookForBracket ) /* private method */
src/js/model.js:264
Calculates the expression from top of the stack until
an open bracket or the end (bottom) of the stack is reached.
Uses mErr to store a ClassedError object if an error occurs. Check this
property in the calling function.
-
lookForBracket<Boolean>If true, an open bracket is expected. If no such is found, a debug error is generated.
clearRegister( )
src/js/model.js:880
This method clears the registers. It expects that the model is in the init state, otherwise it will call resetModel itself to ensure that.
compareRegs( )
src/js/model.js:1140
Compare the register values and return a DocumentFragment containing the html to represent the comparison.
determineState( ) /* private method */
src/js/model.js:645
Tries to determine and set the correct state of the stack after an error in calculation.
getCmpOpnds( )
src/js/model.js:1160
Returns an array with the two operands (as Ord instances). The left operand is placed at (array-)index 0, the right operand at index 1. If registers have changed, the comparisonData object of the model is updated.
getCmpResult( )
src/js/model.js:1181
Returns the result of the comparison between the two actual register values. If an error occurred, the value null is returned. If registers have changed, the comparisonData object of the model is updated.
- Return value is greater 0: The left operand is greater than the right one.
- Return value is equal to 0: The two operands are equal
- Return value is less than 0: The left operand is less than the right one.
getData( simple )
src/js/model.js:771
Get the data in the representation needed by the gui to display the content of the model.
Parameters:-
simple<Boolean>If set, the data is in a simple form, that means, no html, just w instead of omega and so on. If not specified, the html form is returned.
getNumOfOpenBr( )
src/js/model.js:912
Get the number of open (and not yet closed) brackets on the stack expression.
getRegister( regAddr ) /* private method */
src/js/model.js:693
Get the operand stored in the register
Parameters:-
regAddr<Number>The address of the register
getState( bAsString )
src/js/model.js:737
Get the current state of the model.
Parameters:-
bAsString<Boolean>If set, the state is returned as a string instead of the representing number (association defined in model.enumState)
isNatural( ch ) /* private method */
src/js/model.js:138
Check if the character is a natural number consisting of digits.
Parameters:-
ch<String>The character or little String to be tested
isOperator( ch ) /* private method */
src/js/model.js:120
Check if a character is an operator.
Parameters:-
ch<String>The character (or short string) to be checked.
recall( regAddr )
src/js/model.js:837
Recall a value from the register and put it on the stack.
Parameters:-
regAddr<Number>The address of the register. Possible Values: 0 and 1
regsDirty( )
src/js/model.js:1208
Checks the state of the registers.
regsEmpty( )
src/js/model.js:900
Checks if the registers are empty. Empty means that they are in the original state; if an ordinal with the value 0 is stored in a register, then it is NOT considered empty!
stackToString( htmlStyle ) /* private method */
src/js/model.js:327
Get the content of the stack as String representation
Parameters:-
htmlStyle<Boolean>If true, the return-String contains the special html-char ω instead of w and the last operand will be wrapped into a span tag.
store( regAddr )
src/js/model.js:787
Calculate the whole stack (if necessary) and store the resulting Ord object into a register
Parameters:-
regAddr<Number>The address of the register. Possible Values: 0 and 1
subcalc( optorIx ) /* private method */
src/js/model.js:152
Performs a (sub-)calculation around an operator whose stack-index is given as parameter. The method looks for the two surrounding operands, extracts this operands, and then performs the calculation. If a calculation error occurrs, then subcalc will store it to the mErr propererty. Check for that in the calling function.
Parameters:-
optorIx<Number>The index of the operator on the stack
trySimplify( op ) /* private method */
src/js/model.js:206
Tries simplification of previous operands. This is possible, if the last operator (which is delivered as parameter):
- has a lower priority than the preceeding one
- has the same priority than the preceeding one and the operation is associativ or left-associativ
This method tries to calculate as many operands as possible by iteratively
testing if the condition described above is true...
The method updates the stack itself. If an error occurs, mErr is used to
store the Error object.
-
op<String>The last operator. Is not stored on the stack yet.
enumState <Object literal containing number values>src/js/model.js:61
Enumerable values for the state of the model.
enumType <Object literal with number values>src/js/model.js:1226
Enumerable values to define the type of a stack element.
mErr <ClassedError>src/js/model.js:93
To store a ClassedError object, and share it between methods.
regDirty <Boolean>src/js/model.js:52
Flag to indicate if register's have changed since last call of method compareRegs()
stack <Array (of StackEl objects)>src/js/model.js:28
The stack holds the data of the current expression.
state <Number (enumState)>src/js/model.js:85
The state of the model, depending on the last added character.
Transfinite Ordinal Calculator: model