API Docs for: 1.0

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.

Parameters:
  • 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.

DocumentFragment compareRegs( )
src/js/model.js:1140

Compare the register values and return a DocumentFragment containing the html to represent the comparison.


Returns: <DocumentFragment> HTML elements representing the comparison. Null if Comparison failed. (Note: error is already processed)
model.enumState determineState( ) /* private method */
src/js/model.js:645

Tries to determine and set the correct state of the stack after an error in calculation.


Returns: <model.enumState> The state.
Array of Ord 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.


Returns: <Array of Ord> the Array
Number / null 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.


Returns: <Number / null> the compare value. If the comparison succeeded, there are three possibilities:
  • 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.
String 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.


Returns: <String> The data of the model
Number getNumOfOpenBr( )
src/js/model.js:912

Get the number of open (and not yet closed) brackets on the stack expression.


Returns: <Number> The number of open brackets
model.Operand getRegister( regAddr ) /* private method */
src/js/model.js:693

Get the operand stored in the register

Parameters:
  • regAddr <Number>

    The address of the register


Returns: <model.Operand> The value stored in the register or null if an error occurs.
Number / string 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)


Returns: <Number / string> The state of the model. A value of model.enumState.
Boolean 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


Returns: <Boolean> True if the parameter ch is a natural number
Boolean 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.


Returns: <Boolean> True if the parameter ch is an operator
logStack( ) /* private method */
src/js/model.js:420

Logs the content of the stack.

Boolean 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


Returns: <Boolean> If the operation was successful
Boolean regsDirty( )
src/js/model.js:1208

Checks the state of the registers.


Returns: <Boolean> If register values have changed since last call to the compareRegs method, then this method will return true.
Boolean 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!


Returns: <Boolean> True if registers are empty
resetModel( )
src/js/model.js:869

Sets the model back to state init and delete the stack's content.

String 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.


Returns: <String> The string representation of the stack
Boolean 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


Returns: <Boolean> If the operation was successful
Ord 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


Returns: <Ord> The result object, or null if an error occurs.
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.

Parameters:
  • op <String>

    The last operator. Is not stored on the stack yet.

cmpData <model.ComparisonData>
src/js/model.js:44

Caches the last comparison.

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.

numOfOpenBrackets <Number>
src/js/model.js:77

Counts how many brackets are currently opened.

regDirty <Boolean>
src/js/model.js:52

Flag to indicate if register's have changed since last call of method compareRegs()

regs <Array of Ord instances>
src/js/model.js:36

The registers contain the stored data.

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.