Commit 7a64e0f7 authored by Alexander.Trofimov's avatar Alexander.Trofimov

cBaseOperator, cBaseFunction prototype = new Object -> add method to prototype

parent 03aa784c
...@@ -18,7 +18,7 @@ function (window, undefined) { ...@@ -18,7 +18,7 @@ function (window, undefined) {
var CellAddress = AscCommon.CellAddress; var CellAddress = AscCommon.CellAddress;
var c_oAscError = Asc.c_oAscError; var c_oAscError = Asc.c_oAscError;
/** @enum */ /** @enum */
var cElementType = { var cElementType = {
number : 0, number : 0,
...@@ -1227,7 +1227,7 @@ cRef.prototype.isValid = function () { ...@@ -1227,7 +1227,7 @@ cRef.prototype.isValid = function () {
}; };
cRef.prototype.getMatrix = function () { cRef.prototype.getMatrix = function () {
return [[this.getValue()]]; return [[this.getValue()]];
} };
cRef.prototype.getBBox0 = function () { cRef.prototype.getBBox0 = function () {
return this.getRange().getBBox0(); return this.getRange().getBBox0();
}; };
...@@ -1942,72 +1942,63 @@ function checkTypeCell( val ) { ...@@ -1942,72 +1942,63 @@ function checkTypeCell( val ) {
} }
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/*Base classes for operators & functions */ /*Base classes for operators & functions */
/** @constructor */ /** @constructor */
function cBaseOperator( name, priority, argumentCount ) { function cBaseOperator(name, priority, argumentCount) {
if ( name ) { this.name = name ? name : '';
this.name = name; this.priority = (priority !== undefined) ? priority : 10;
} else {
this.name = "";
}
if ( priority !== undefined ) {
this.priority = priority;
} else {
this.priority = 10;
}
this.type = cElementType.operator; this.type = cElementType.operator;
this.isRightAssociative = false; this.isRightAssociative = false;
if ( argumentCount !== undefined ) { this.argumentsCurrent = (argumentCount !== undefined) ? argumentCount : 2;
this.argumentsCurrent = argumentCount;
} else {
this.argumentsCurrent = 2;
}
this.value = null; this.value = null;
this.formatType = { this.formatType = {
def : -1, //подразумевается формат первой ячейки входящей в формулу. def: -1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat: -2 noneFormat: -2
}; };
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cBaseOperator.prototype = { cBaseOperator.prototype.getArguments = function () {
constructor: cBaseOperator, getArguments: function() { return this.argumentsCurrent;
return this.argumentsCurrent; };
}, toString: function() { cBaseOperator.prototype.toString = function () {
return this.name; return this.name;
}, Calculate: function() { };
return null; cBaseOperator.prototype.Calculate = function () {
}, Assemble: function(arg) { return null;
var str = ""; };
if ( this.argumentsCurrent === 2 ) { cBaseOperator.prototype.Assemble = function (arg) {
str = arg[0] + "" + this.name + "" + arg[1]; var str = "";
if (this.argumentsCurrent === 2) {
str = arg[0] + "" + this.name + "" + arg[1];
} else { } else {
str = this.name + "" + arg[0]; str = this.name + "" + arg[0];
} }
return new cString( str ); return new cString(str);
}, Assemble2: function(arg, start, count) { };
var str = ""; cBaseOperator.prototype.Assemble2 = function (arg, start, count) {
if ( this.argumentsCurrent === 2 ) { var str = "";
str += arg[start + count - 2] + this.name + arg[start + count - 1]; if (this.argumentsCurrent === 2) {
str += arg[start + count - 2] + this.name + arg[start + count - 1];
} else { } else {
str += this.name + arg[start]; str += this.name + arg[start];
} }
return new cString( str ); return new cString(str);
}, Assemble2Locale: function(arg, start, count, locale, digitDelim) { };
var str = ""; cBaseOperator.prototype.Assemble2Locale = function (arg, start, count, locale, digitDelim) {
if ( this.argumentsCurrent === 2 ) { var str = "";
if (this.argumentsCurrent === 2) {
str += arg[start + count - 2].toLocaleString(digitDelim) + this.name + str += arg[start + count - 2].toLocaleString(digitDelim) + this.name +
arg[start + count - 1].toLocaleString(digitDelim); arg[start + count - 1].toLocaleString(digitDelim);
} else { } else {
str += this.name + arg[start]; str += this.name + arg[start];
}
return new cString( str );
} }
}; return new cString(str);
};
/** @constructor */ /** @constructor */
function cBaseFunction( name, argMin, argMax ) { function cBaseFunction(name, argMin, argMax) {
this.name = name; this.name = name;
this.type = cElementType.func; this.type = cElementType.func;
this.value = null; this.value = null;
...@@ -2015,87 +2006,102 @@ function cBaseFunction( name, argMin, argMax ) { ...@@ -2015,87 +2006,102 @@ function cBaseFunction( name, argMin, argMax ) {
this.argumentsCurrent = 0; this.argumentsCurrent = 0;
this.argumentsMax = argMax ? argMax : 255; this.argumentsMax = argMax ? argMax : 255;
this.formatType = { this.formatType = {
def : -1, //подразумевается формат первой ячейки входящей в формулу. def: -1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat: -2 noneFormat: -2
}; };
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
// this.isXLFN = rx_sFuncPref.test(this.name); // this.isXLFN = rx_sFuncPref.test(this.name);
} }
cBaseFunction.prototype.Calculate = function () {
cBaseFunction.prototype = { this.value = new cError(cErrorType.wrong_name);
constructor: cBaseFunction, Calculate: function() { return this.value;
this.value = new cError( cErrorType.wrong_name ); };
return this.value; cBaseFunction.prototype.setArgumentsMin = function (count) {
}, setArgumentsMin: function(count) { this.argumentsMin = count;
this.argumentsMin = count; };
}, setArgumentsMax: function(count) { cBaseFunction.prototype.setArgumentsMax = function (count) {
this.argumentsMax = count; this.argumentsMax = count;
}, DecrementArguments: function() { };
--this.argumentsCurrent; cBaseFunction.prototype.DecrementArguments = function () {
}, IncrementArguments: function() { --this.argumentsCurrent;
++this.argumentsCurrent; };
}, setName: function(name) { cBaseFunction.prototype.IncrementArguments = function () {
this.name = name; ++this.argumentsCurrent;
}, setArgumentsCount: function(count) { };
this.argumentsCurrent = count; cBaseFunction.prototype.setName = function (name) {
}, getArguments: function() { this.name = name;
return this.argumentsCurrent; };
}, getMaxArguments: function() { cBaseFunction.prototype.setArgumentsCount = function (count) {
return this.argumentsMax; this.argumentsCurrent = count;
}, getMinArguments: function() { };
return this.argumentsMin; cBaseFunction.prototype.getArguments = function () {
}, Assemble: function(arg) { return this.argumentsCurrent;
var str = ""; };
for ( var i = 0; i < arg.length; i++ ) { cBaseFunction.prototype.getMaxArguments = function () {
str += arg[i].toString(); return this.argumentsMax;
if ( i !== arg.length - 1 ) { };
str += ","; cBaseFunction.prototype.getMinArguments = function () {
} return this.argumentsMin;
} };
if ( this.isXLFN ) { cBaseFunction.prototype.Assemble = function (arg) {
return new cString( "_xlfn." + this.name + "(" + str + ")" ); var str = "";
} for (var i = 0; i < arg.length; i++) {
return new cString( this.toString() + "(" + str + ")" ); str += arg[i].toString();
}, Assemble2: function(arg, start, count) { if (i !== arg.length - 1) {
str += ",";
}
}
if (this.isXLFN) {
return new cString("_xlfn." + this.name + "(" + str + ")");
}
return new cString(this.toString() + "(" + str + ")");
};
cBaseFunction.prototype.Assemble2 = function (arg, start, count) {
var str = "", c = start + count - 1; var str = "", c = start + count - 1;
for ( var i = start; i <= c; i++ ) { for (var i = start; i <= c; i++) {
str += arg[i].toString(); str += arg[i].toString();
if ( i !== c ) { if (i !== c) {
str += ","; str += ",";
} }
} }
if ( this.isXLFN ) { if (this.isXLFN) {
return new cString( "_xlfn." + this.name + "(" + str + ")" ); return new cString("_xlfn." + this.name + "(" + str + ")");
} }
return new cString( this.toString() + "(" + str + ")" ); return new cString(this.toString() + "(" + str + ")");
}, Assemble2Locale: function(arg, start, count, locale, digitDelim) { };
cBaseFunction.prototype.Assemble2Locale = function (arg, start, count, locale, digitDelim) {
var name = this.toString(), str = "", c = start + count - 1, localeName = locale ? locale[name] : name; var name = this.toString(), str = "", c = start + count - 1, localeName = locale ? locale[name] : name;
localeName = localeName || this.toString(); localeName = localeName || this.toString();
for ( var i = start; i <= c; i++ ) { for (var i = start; i <= c; i++) {
str += arg[i].toLocaleString( digitDelim ); str += arg[i].toLocaleString(digitDelim);
if ( i !== c ) { if (i !== c) {
str += FormulaSeparators.functionArgumentSeparator; str += FormulaSeparators.functionArgumentSeparator;
} }
}
return new cString( localeName + "(" + str + ")" );
}, toString: function() {
return this.name.replace( rx_sFuncPref, "_xlfn." );
}, setCA: function(arg, ca, numFormat) {
this.value = arg;
if ( ca ) {
this.value.ca = true;
}
if ( numFormat !== null && numFormat !== undefined ) {
this.value.numFormat = numFormat;
}
return this.value;
}, setFormat: function(f) {
this.numFormat = f;
} }
}; return new cString(localeName + "(" + str + ")");
};
cBaseFunction.prototype.toString = function () {
return this.name.replace(rx_sFuncPref, "_xlfn.");
};
cBaseFunction.prototype.setCA = function (arg, ca, numFormat) {
this.value = arg;
if (ca) {
this.value.ca = true;
}
if (numFormat !== null && numFormat !== undefined) {
this.value.numFormat = numFormat;
}
return this.value;
};
cBaseFunction.prototype.setFormat = function (f) {
this.numFormat = f;
};
cBaseFunction.prototype.checkArguments = function () {
return this.argumentsMin <= this.argumentsCurrent && this.argumentsCurrent <= this.argumentsMax;
};
/** @constructor */ /** @constructor */
function parentLeft() { function parentLeft() {
...@@ -4226,7 +4232,7 @@ parserFormula.prototype.parse = function(local, digitDelim) { ...@@ -4226,7 +4232,7 @@ parserFormula.prototype.parse = function(local, digitDelim) {
if (this.outStack.length != 0) { if (this.outStack.length != 0) {
return this.isParsed = true; return this.isParsed = true;
} else { } else {
return this.isParsed = false; return this.isParsed = false;
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment