src/js/globals.js
/*! @file globals.js */
/*
* part of the 'Transfinite Ordinal Calculator'
* author: Claudio Kressibucher
* license: GNU LGPL
*/
// This File declares ALL (except the X... Methods of the x-library) global
// variables used by this program...
// An object to hold temporarily used (pseudo-)global variables
var go = {}; // "global objects"
// The Gui object
var oGui;
// util tools
var util;
// The Model object
var model;
// class for a calculation of two ordinal numbers
var Calculation;
// Data structure for Ordinal numbers
var Ord; // an ordinal number
var OrdSummand; // a term of an ordinal number
// error classes
var ClassedError;
/**
* Parameters of the program.
* @class config
* @static
*/
var config = {
/**
* Debug mode:
* <ul>
* <li>0 productive, no logs are displayed</li>
* <li>1 only fatal errors are displayed</li>
* <li>2 warnings and non-fatal errors are also displayed</li>
* <li>3 debug notes are also displayed</li>
* </ul>
* It is essential that the value is set to 0 in productive
* state to not obtain debug logs in the GUI!
* @property debug
* @type number
*/
debug: 0,
/**
* Specifies, if an own console object (which prints to a
* HTML-DOM-Element) should be preferred against the browser's
* console object. (If the browser console is available; otherwise, an own
* console object is created, as long as config.prohibitOwnConsole
* doesn't prohibit this.)
* @property useConsole
* @type boolean
*/
useOwnConsole: false,
/**
* This property set to true prohibits the use of an own
* console object in any case. If there is no browser console available and
* config.debug > 0, then the logs will be lost. This property
* is stronger than useOwnConsole, so if
* useOwnConsole == true, and
* prohibitOwnConsole == true,
* then the browser console is used (if available).
* @property prohibitOwnConsole
* @type boolean
*/
prohibitOwnConsole: false,
/**
* If true, some functionality tests are executed when the application is started
* @property testFncOnInit
* @type boolean
*/
testFncOnInit: true,
/**
* The URL where the user finds further information about the project
* @property projectUrl
* @type string
*/
projectUrl: 'http://transfinite.ch/project.html',
/**
* Version of the application
* @property projectVersion
* @type string
*/
projectVersion: "1.0"
};
/**
* Used to describe and classify an error.
* @class ClassedError
* @constructor
* @param {string} msg The error message. If this is an empty string or null, then the
* type's default error message will be used
* @param {number} type A number value representing one of the types of
* enum list of ClassedError.types
* @extends Error
*/
ClassedError = function (msg, type){
if (msg === null || msg === ""){
this.message = "error"; // TODO depending on type different default error message
} else {
this.message = msg;
}
this.type = type;
};
// set Error instance as prototype and reset constructor
ClassedError.prototype = new Error();
ClassedError.prototype.constructor = ClassedError;
/**
* Enumerable values representing the different types / or classes
* of errors that can be thrown by this application
* @property types
* @type object literal containing number values
*/
ClassedError.types = {
finExpTooLarge : 0, /* if a finite exponent is so large that there result too many terms */
calcError : 1, /* general (not further specified) calculation error */
inaccurate : 2, /* too large number, could cause inaccurate results */
progError : 3 /* general program error */
};
/**
* Handle the error according to its type
* @method handleErr
*/
ClassedError.prototype.handleErr = function (){
var t = ClassedError.types;
switch (this.type){
case t.finExpTooLarge:
break;
case t.calcError:
break;
case t.inaccurate:
break;
case t.progError:
break;
default:
}
oGui.showHint(this.message);
oGui.dbgLog("ClassedError: " + this.message);
};