From 911f9c722f3bb81257d5b057bed099a57b7c17d1 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Thu, 4 Jan 2018 11:30:28 +0100 Subject: [PATCH] =?UTF-8?q?extraction=20d'une=20classe=20BaseParam=20?= =?UTF-8?q?=C3=A0=20partir=20de=20ParamDefinition=20(comporte=20uniquement?= =?UTF-8?q?=20un=20symbole=20et=20un=20domaine=20de=20d=C3=A9finition)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/param.ts | 221 +++++++++++++++++++-------------------------------- 1 file changed, 83 insertions(+), 138 deletions(-) diff --git a/src/param.ts b/src/param.ts index dee9c611..57fb26de 100644 --- a/src/param.ts +++ b/src/param.ts @@ -148,152 +148,66 @@ export enum ParamCalculability { } /** - * définition d'un paramètre + * paramètre avec symbole et domaine de définition */ -export class ParamDefinition extends DefinedNumber { +export class BaseParam extends DefinedNumber { /** * symbole */ private _symbol: string; - /** - * alias du symbole - */ - // public symbolAlias: string; - - /** - * calculabilité - */ - private _calc: ParamCalculability; - /** * domaine de définition */ private _domain: ParamDomain; - /** - * noeud de calcul parent - */ - private _computeNodeType: ComputeNodeType - - /** - * ancienne valeur du paramètre - */ - // private _savedValue: number; - - /** - * valeur du paramètre - */ - //private _value: number; - - // private static _idGen: number = 0; // A VIRER - // private _id: number; // A VIRER - - // constructor(s: string, d: ParamDomain, c: ParamCalculability, val: number = undefined) { - constructor(nt: ComputeNodeType, s: string, d: ParamDomain | ParamDomainValue, val: number = undefined) { + constructor(symb: string, d: ParamDomain | ParamDomainValue, val: number = undefined) { super(val); - this._computeNodeType = nt; - this._symbol = s; + this._symbol = symb; if (d instanceof ParamDomain) this._domain = d; else this._domain = new ParamDomain(<ParamDomainValue>d); - this._calc = undefined; this.checkValue(val); - // this._value = val; - - // this._id = ParamDefinition._idGen++; // A VIRER - // console.log("constructor param " + this._symbol + " id=" + this._id); // A VIRER } - // get id(): number { - // return this._id; - // } - - /** - * getter symbole - */ get symbol(): string { return this._symbol; } - /** - * méthodes de domaine - */ getDomain(): ParamDomain { return this._domain; } - - get computeNodeType(): ComputeNodeType { - return this._computeNodeType; - } - - /* - * méthodes de calculabilité - */ - - /** - * variable calculable par l'équation ? - */ - isAnalytical(): boolean { - return this.calculability == ParamCalculability.EQUATION; - } - - get calculability(): ParamCalculability { - if (this._calc == undefined) { - // throw "value of parameter '" + this._symbol + "' calculability is not defined"; - let e = new Message(MessageCode.ERROR_PARAMDEF_CALC_UNDEFINED); - e.extraVar["symbol"] = this.symbol; - throw e; - } - - return this._calc; + public get interval(): Interval { + return this._domain.interval; } - set calculability(c: ParamCalculability) { - this._calc = c; - } /** * gestion de la valeur */ - get v(): number { - // if (this._value == undefined) + + getValue(): number { if (!this.isDefined) { - // throw new UndefinedError("value of '" + this._symbol + "' parameter is not defined"); let e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_UNDEFINED); e.extraVar["symbol"] = this.symbol; throw e; } - // return this._value; - return this.getValue(); - } - set v(val: number) { - // if (val == undefined) - // console.log("warning : setting parameter '" + this._symbol + "' to undefined value (use undefine() instead)"); + return super.getValue(); + } - if (this.calculability == ParamCalculability.NONE) { - // throw "value of '" + this._symbol + "' parameter cannot be changed"; - let e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_FIXED); - e.extraVar["symbol"] = this.symbol; - throw e; - } + setValue(val: number) { this.checkValue(val); - // this._value = val; - this.setValue(val); + super.setValue(val); // console.log("setting param " + this._symbol + " id=" + this._id + " to " + val); // A VIRER } - // get uncheckedValue() { - // return this._value; - // } - - checkValue(v: number) { + public checkValue(v: number) { let sDomain = ParamDomainValue[this._domain.domain]; switch (this._domain.domain) { @@ -302,7 +216,6 @@ export class ParamDefinition extends DefinedNumber { case ParamDomainValue.POS: if (v <= 0) { - // throw "parameter '" + this._symbol + "' : invalid " + v + " value (cannot be <=0)"; let e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_POS); e.extraVar["symbol"] = this.symbol; e.extraVar["value"] = v; @@ -312,7 +225,6 @@ export class ParamDefinition extends DefinedNumber { case ParamDomainValue.POS_NULL: if (v < 0) { - // throw "parameter '" + this._symbol + "' : invalid " + v + " value (cannot be <0)"; let e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_POSNULL); e.extraVar["symbol"] = this.symbol; e.extraVar["value"] = v; @@ -322,7 +234,6 @@ export class ParamDefinition extends DefinedNumber { case ParamDomainValue.NOT_NULL: if (v == 0) { - // throw "parameter '" + this._symbol + "' : value cannot be 0"; let e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_NULL); e.extraVar["symbol"] = this.symbol; throw e; @@ -333,7 +244,6 @@ export class ParamDefinition extends DefinedNumber { let min = this._domain.minValue; let max = this._domain.maxValue; if (v < min || v > max) { - // throw "parameter '" + this._symbol + "' : value " + v + " is out of [" + min + ", " + max + "] interval"; let e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_INTERVAL); e.extraVar["symbol"] = this.symbol; e.extraVar["value"] = v; @@ -344,60 +254,95 @@ export class ParamDefinition extends DefinedNumber { break; default: - //throw "parameter '" + this._symbol + "' : non supported '" + sDomain + "' definition domain"; let e = new Message(MessageCode.ERROR_PARAMDOMAIN_INVALID); e.extraVar["symbol"] = this.symbol; e.extraVar["domain"] = sDomain; throw e; } } +} - // isDefined(): boolean { - // return this._value != undefined; - // } +/** + * définition d'un paramètre d'un neud de calcul + */ +export class ParamDefinition extends BaseParam { + /** + * calculabilité + */ + private _calc: ParamCalculability; + /** + * noeud de calcul parent + */ + private _computeNodeType: ComputeNodeType - // undefine() { - // this._value = undefined; - // // this._savedValue = undefined; + // private static _idGen: number = 0; // A VIRER + // private _id: number; // A VIRER + + constructor(nt: ComputeNodeType, s: string, d: ParamDomain | ParamDomainValue, val: number = undefined) { + super(s, d, val); + this._computeNodeType = nt; + + this._calc = undefined; + this.checkValue(val); + + // this._id = ParamDefinition._idGen++; // A VIRER + // console.log("constructor param " + this._symbol + " id=" + this._id); // A VIRER + } + + // get id(): number { + // return this._id; // } + get computeNodeType(): ComputeNodeType { + return this._computeNodeType; + } + + get v(): number { + return super.getValue(); + } + + set v(val: number) { + if (this.calculability == ParamCalculability.NONE) { + let e = new Message(MessageCode.ERROR_PARAMDEF_VALUE_FIXED); + e.extraVar["symbol"] = this.symbol; + throw e; + } + super.setValue(val); + } + + /* + * méthodes de calculabilité + */ + /** - * gestion du cache + * variable calculable par l'équation ? */ - /* - saveValue() { - if (this._value == undefined) - throw "parameter '" + this._symbol + "' : cannot save 'undefined' value"; - if (this._savedValue != undefined) - throw "parameter '" + this._symbol + "' : previous saved value " + this._savedValue + " has not been restored"; - this._savedValue = this._value; - } - - restoreValue() { - if (this._savedValue == undefined) - throw "parameter '" + this._symbol + "' : value has not been saved"; - this._value = this._savedValue; - this._savedValue = undefined; - } - */ - - // toString(): string { - // if (this.isDefined()) - // return "" + this._value; - // return "undefined"; - // } + isAnalytical(): boolean { + return this.calculability == ParamCalculability.EQUATION; + } + + get calculability(): ParamCalculability { + if (this._calc == undefined) { + // throw "value of parameter '" + this._symbol + "' calculability is not defined"; + let e = new Message(MessageCode.ERROR_PARAMDEF_CALC_UNDEFINED); + e.extraVar["symbol"] = this.symbol; + throw e; + } + + return this._calc; + } + + set calculability(c: ParamCalculability) { + this._calc = c; + } public clone(): ParamDefinition { - let res = new ParamDefinition(this._computeNodeType, this._symbol, this._domain.clone()); + let res = new ParamDefinition(this._computeNodeType, this.symbol, this.getDomain().clone()); res._calc = this._calc; res.value = this.uncheckedValue; return res; } - - public get interval(): Interval { - return this._domain.interval; - } } -- GitLab