diff --git a/src/index.ts b/src/index.ts index 191a2b4cd293c51e29533840a5313a3af79f7ad7..b48447f2d8fa568c7213bd1c1e2395eb70ac9f3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,6 @@ export * from "./section/section_trapez"; export * from "./section/section_rectang"; export * from "./section/section_circulaire"; export * from "./section/section_puissance"; -export * from "./util/definedvalue"; export * from "./util/numericalstring"; export * from "./util/message"; export * from "./util/log"; diff --git a/src/param/param-values.ts b/src/param/param-values.ts index 0b285d74a16a9cedccd1c5c424060b5d059435ff..733d86553f085e48f9c22fefe9e28787e07431c0 100644 --- a/src/param/param-values.ts +++ b/src/param/param-values.ts @@ -1,5 +1,4 @@ import { Interval, Result } from ".."; -import { DefinedNumber } from "../util/definedvalue"; import { INubReference, IReferencedNub, NubReference } from "../value_ref/object_ref"; import { INamedIterableValues, INumberIterator, IterableValues, ParamValueIterator } from "./param-value-iterator"; import { ParamValueMode } from "./param-value-mode"; @@ -19,7 +18,7 @@ export class ParamValues implements INubReference, IterableValues { /** * valeur numérique (éventuellement non définie) dans le mode "valeur unique" (ParamValueMode.SINGLE) */ - private _singleValue: DefinedNumber; + private _singleValue: number; /** * valeur min dans le cas ParamValueMode.MINMAX @@ -44,7 +43,7 @@ export class ParamValues implements INubReference, IterableValues { /** * valeur courante (éventuellement non définie) indépendemment du mode */ - private _currentValue: DefinedNumber; + private _currentValue: number; /** * itérateur courant @@ -52,8 +51,6 @@ export class ParamValues implements INubReference, IterableValues { private _iterator: INumberIterator; constructor() { - this._singleValue = new DefinedNumber(); - this._currentValue = new DefinedNumber(); this._nubRef = new NubReference(); } @@ -61,19 +58,19 @@ export class ParamValues implements INubReference, IterableValues { if (typeof (o) === "number") { if (max === undefined) { this._valueMode = ParamValueMode.SINGLE; - this._singleValue.value = o as number; - this._currentValue.value = o as number; + this._singleValue = o; + this._currentValue = o; } else { this._valueMode = ParamValueMode.MINMAX; - this._minValue = o as number; + this._minValue = o; this._maxValue = max; this._stepValue = step; - this._currentValue.undefine(); + this._currentValue = undefined; } } else if (Array.isArray(o)) { this._valueMode = ParamValueMode.LISTE; this._valueList = o; - this._currentValue.undefine(); + this._currentValue = undefined; } else { throw new Error(`ParamValues.setValues() : appel invalide`); } @@ -90,7 +87,7 @@ export class ParamValues implements INubReference, IterableValues { public check() { switch (this._valueMode) { case ParamValueMode.SINGLE: - if (!this._singleValue.isDefined) { + if (this._singleValue === undefined) { throw new Error(`ParamValues : valeur fixe non définie`); } break; @@ -132,11 +129,11 @@ export class ParamValues implements INubReference, IterableValues { if (this.isReferenceDefined) { return this._nubRef.referencedObject.currentValue; } - return this._currentValue.value; + return this._currentValue; } public set currentValue(v: number) { - this._currentValue.value = v; + this._currentValue = v; } /** @@ -146,21 +143,21 @@ export class ParamValues implements INubReference, IterableValues { if (this.isReferenceDefined) { return this._nubRef.referencedParamValues.singleValue; } - return this._singleValue.value; + return this._singleValue; } public get uncheckedValue() { - return this._currentValue.uncheckedValue; + return this._currentValue; } public setSingleValue(v: number) { this._valueMode = ParamValueMode.SINGLE; - this._singleValue.value = v; - this._currentValue.value = v; + this._singleValue = v; + this._currentValue = v; } public get isDefined() { - return this._currentValue.isDefined; + return this._currentValue !== undefined; } public get min() { @@ -356,7 +353,7 @@ export class ParamValues implements INubReference, IterableValues { } else { res = this._iterator.next(); if (!res.done) { - this._currentValue.value = res.value; + this._currentValue = res.value; } } return res; diff --git a/src/util/definedvalue.ts b/src/util/definedvalue.ts deleted file mode 100644 index 9c180f88931228dd617105ea55d95f38551c5200..0000000000000000000000000000000000000000 --- a/src/util/definedvalue.ts +++ /dev/null @@ -1,72 +0,0 @@ -export class DefinedValue<T> { - - get isDefined() { - return this._value !== undefined; - } - - get uncheckedValue() { - return this._value; - } - - get value() { - return this.getValue(); - } - - set value(v: T) { - this.setValue(v); - } - private _value: T; - - constructor(v?: T) { - this._value = v; - } - - public undefine() { - this._value = undefined; - } - - public toString(): string { - if (this.isDefined) { - return String(this._value); - } - - return "undefined"; - } - - /** - * fonction nécessitée par le fait qu'on ne peut pas appeller les accesseurs d'un parent - * ou que si l'un des 2 accesseurs est surchargé, il faut surcharger l'autre - * (et donc pour pouvoir éventuellement appeler l'accesseur parent) - */ - protected getValue(): T { - if (this._value === undefined) { - throw new Error("undefined value"); - } - - return this._value; - } - - /** - * fonction nécessitée par le fait qu'on ne peut pas appeller les accesseurs d'un parent - * ou que si l'un des 2 accesseurs est surchargé, il faut surcharger l'autre - * (et donc pour pouvoir éventuellement appeler l'accesseur parent) - */ - protected setValue(v: T) { - this._value = v; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class DefinedBoolean extends DefinedValue<boolean> { -} - -// tslint:disable-next-line:max-classes-per-file -export class DefinedNumber extends DefinedValue<number> { -} - -// tslint:disable-next-line:max-classes-per-file -export class DefinedString extends DefinedValue<string> { - constructor(v?: any) { - super(v === undefined ? v : String(v)); - } -} diff --git a/src/util/numericalstring.ts b/src/util/numericalstring.ts index 9c35a4e91cb42c4122cea60603c1803af873a38a..f3d8696e7b2a2f0bc65b3b5ef7a4fd438e04afc9 100644 --- a/src/util/numericalstring.ts +++ b/src/util/numericalstring.ts @@ -1,61 +1,59 @@ -import { DefinedBoolean, DefinedString } from "./definedvalue"; +export class NumericalString { -export class NumericalString extends DefinedString { + private _value: string; + private _isNumericalFlag: boolean; - private get isNumericalFlag(): DefinedBoolean { - if (this._isNumericalFlag === undefined) { - this._isNumericalFlag = new DefinedBoolean(); - } + private get isNumericalFlag(): boolean { return this._isNumericalFlag; } get isNumerical(): boolean { this.updateNumericalFlag(); - return this.isNumericalFlag.value; + return this.isNumericalFlag; } /** * nécessaire car si on surcharge un des accesseurs, il faut surcharger les 2 (merci Microsoft) */ get value() { - return this.getValue(); + return this._value; } set value(v: string) { - this.isNumericalFlag.undefine(); - this.setValue(v); - // this.updateNumericalFlag(); + this._isNumericalFlag = undefined; + this._value = v; + this.updateNumericalFlag(); } get numericalValue(): number { if (!this.isNumerical) { - throw new Error("invalid NumericalString '" + this.uncheckedValue + "' value"); + throw new Error("invalid NumericalString '" + this._value + "' value"); } return +this.value; } get uncheckedValueString(): string { - if (this.isDefined) { - return this.uncheckedValue; + if (this._value !== undefined) { + return this._value; } return ""; } - private _isNumericalFlag: DefinedBoolean; constructor(s?: any) { - super(s); + this._value = s; + this.updateNumericalFlag(); } public toString(): string { - return super.toString() + (this.isNumerical ? " [numerical]" : " [NOT numerical]"); + return this._value + (this.isNumerical ? " [numerical]" : " [NOT numerical]"); } private updateNumericalFlag() { - if (!this.isNumericalFlag.isDefined) { - this.isNumericalFlag.value = false; - if (this.isDefined) { + if (this.isNumericalFlag === undefined) { + this._isNumericalFlag = false; + if (this._value !== undefined) { if (typeof this.value === "string") { - this.isNumericalFlag.value = String(this.value).trim() !== "" && !isNaN(+this.value); + this._isNumericalFlag = String(this.value).trim() !== "" && !isNaN(+this.value); } } }