From 2890084ad58f576d553f7682ef9f357409bd428b Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Fri, 1 Jun 2018 15:48:24 +0200
Subject: [PATCH] =?UTF-8?q?=20#45=20d=C3=A9placement=20de=20l'impl=C3=A9me?=
 =?UTF-8?q?ntation=20de=20IObjectReference=20de=20ParamDefinition=20vers?=
 =?UTF-8?q?=20BaseParam?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/param/param-base.ts       | 34 +++++++++++++++++++++++++++++++--
 src/param/param-definition.ts | 36 +++--------------------------------
 2 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/param/param-base.ts b/src/param/param-base.ts
index 6731c456..6ed2099f 100644
--- a/src/param/param-base.ts
+++ b/src/param/param-base.ts
@@ -5,12 +5,13 @@ import { Message, MessageCode } from "../util/message";
 import { JalhydObject } from "../jalhyd_object"
 import { ParamDomain, ParamDomainValue } from "./param-domain";
 import { ParamValues, ParamValueMode } from "./param-values";
+import { IReferencedObject, IObjectReference, ObjectReference } from "../value_ref/object_ref";
 
 /**
  * paramètre avec symbole et domaine de définition
  */
 // tslint:disable-next-line:max-classes-per-file
-export class BaseParam extends JalhydObject {
+export class BaseParam extends JalhydObject implements IObjectReference {
     /**
      * symbole
      */
@@ -26,9 +27,15 @@ export class BaseParam extends JalhydObject {
      */
     private _paramValues: ParamValues;
 
+    /**
+     * implémentation par délégation de IObjectReference
+     */
+    private _valueRef: ObjectReference;
+
     constructor(symb: string, d: ParamDomain | ParamDomainValue, val?: number) {
         super();
         this._symbol = symb;
+        this._valueRef = new ObjectReference();
 
         this._paramValues = new ParamValues();
         this._paramValues.setSingleValue(val);
@@ -75,7 +82,16 @@ export class BaseParam extends JalhydObject {
             throw e;
         }
 
-        return this._paramValues.singleValue;
+        switch (this.valueMode) {
+            case ParamValueMode.SINGLE:
+                return this._paramValues.singleValue;
+
+            case ParamValueMode.LINK:
+                return this._valueRef.referencedValues[0];
+
+            default:
+                throw new Error(`mode de valeur ${ParamValueMode[this.valueMode]} invalide`);
+        }
     }
 
     public setValue(val: number) {
@@ -144,4 +160,18 @@ export class BaseParam extends JalhydObject {
     public get valueMode() {
         return this._paramValues.valueMode;
     }
+
+    // interface IObjectReference
+
+    public defineReference(target: IReferencedObject, desc: string) {
+        this.paramValues.valueMode = ParamValueMode.LINK;
+        this._valueRef.defineReference(target, desc);
+    }
+
+    /**
+     * valeurs de l'objet IReferencedObject référencé
+     */
+    public get referencedValues(): number[] {
+        return this._valueRef.referencedValues;
+    }
 }
diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts
index c8c009cc..afd80ace 100644
--- a/src/param/param-definition.ts
+++ b/src/param/param-definition.ts
@@ -2,8 +2,7 @@ import { Message, MessageCode } from "../util/message";
 
 import { BaseParam } from "./param-base";
 import { ParamDomain, ParamDomainValue } from "./param-domain";
-import { ParamValueMode } from "./param-values";
-import { IReferencedObject, IObjectReference, ObjectReference } from "../value_ref/object_ref";
+import { ParamValueMode, ParamValueIterator } from "./param-values";
 
 /**
  * calculabilité du paramètre
@@ -34,34 +33,19 @@ export enum ParamCalculability {
  * définition d'un paramètre d'un noeud de calcul
  */
 // tslint:disable-next-line:max-classes-per-file
-export class ParamDefinition extends BaseParam implements IObjectReference {
+export class ParamDefinition extends BaseParam {
     /**
      * calculabilité
      */
     private _calc: ParamCalculability;
 
-    /**
-     * implémentation par délégation de IObjectReference
-     */
-    private _valueRef: ObjectReference;
-
     constructor(s: string, d: ParamDomain | ParamDomainValue, val?: number) {
         super(s, d, val);
-        this._valueRef = new ObjectReference();
         this._calc = ParamCalculability.FREE;
     }
 
     get v(): number {
-        switch (this.valueMode) {
-            case ParamValueMode.SINGLE:
-                return super.getValue();
-
-            case ParamValueMode.LINK:
-                return this._valueRef.referencedValues[0];
-
-            default:
-                throw new Error(`mode de valeur ${ParamValueMode[this.valueMode]} invalide`);
-        }
+        return super.getValue();
     }
 
     set v(val: number) {
@@ -104,18 +88,4 @@ export class ParamDefinition extends BaseParam implements IObjectReference {
         res._calc = this._calc;
         return res;
     }
-
-    // interface IObjectReference
-
-    public defineReference(target: IReferencedObject, desc: string) {
-        this.paramValues.valueMode = ParamValueMode.LINK;
-        this._valueRef.defineReference(target, desc);
-    }
-
-    /**
-     * valeurs de l'objet IReferencedObject référencé
-     */
-    public get referencedValues(): number[] {
-        return this._valueRef.referencedValues;
-    }
 }
-- 
GitLab