From cc1e71878a83aa8565d9a40dac9edaa261500ed8 Mon Sep 17 00:00:00 2001 From: "benjamin.lesage" Date: Fri, 12 Apr 2024 09:00:20 +0200 Subject: [PATCH] Create hardware components with no load/store services --- .../hardware/BaseHardwareNodeBuilder.scala | 56 ++++++++++++------- .../pml/model/hardware/HardwareTest.scala | 12 ++++ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala index 2220d04..8362ed1 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala @@ -82,45 +82,63 @@ trait BaseHardwareNodeBuilder[T <: Hardware] extends PMLNodeBuilder[T] { * (the name of the value enclosing the object) * @example {{{ * val mySimpleTransporter = SimpleTransporter() - * }}} - * @param basics the set of basic services provided, if empty a default store and load services are added - * @param implicitName implicitly retrieved name from the declaration context - * @param p implicitly retrieved relation linking components to their provided services - * @param owner implicitly retrieved name of the platform + * }}} + * @param basics the set of basic services provided, if empty a default store and load services are added + * @param withDefaultServices add default Load/Store services on creation + * @param implicitName implicitly retrieved name from the declaration context + * @param p implicitly retrieved relation linking components to their provided services + * @param owner implicitly retrieved name of the platform * @return the physical component * @group publicConstructor */ - def apply(basics: Set[Service] = Set.empty)(implicit implicitName: Name, - p: ProvideRelation[Hardware, Service], - owner: Owner): T = - apply(Symbol(implicitName.value), basics) + def apply(basics: Set[Service] = Set.empty, withDefaultServices: Boolean = true)(implicit implicitName: Name, + p: ProvideRelation[Hardware, Service], + owner: Owner): T = + apply(Symbol(implicitName.value), basics, withDefaultServices) /** * A physical component can be defined by its name and the basic services it provides * A transporter is only defined by its name, so if the transporter already exists it will * simply add the services provided by basics * - * @param name the physical component name - * @param basics the set of basic services provided, if empty a default store and load services are added - * @param p implicitly retrieved relation linking components to their provided services - * @param owner implicitly retrieved name of the platform + * @param name the physical component name + * @param basics the set of basic services provided, if empty a default store and load services are added + * @param withDefaultServices add default Load/Store services on creation + * @param p implicitly retrieved relation linking components to their provided services + * @param owner implicitly retrieved name of the platform * @return the physical component * @group publicConstructor */ - def apply(name: Symbol, basics: Set[Service])(implicit - p: ProvideRelation[Hardware, Service], - owner: Owner): T = { + def apply(name: Symbol, basics: Set[Service], withDefaultServices: Boolean)(implicit + p: ProvideRelation[Hardware, Service], + owner: Owner): T = { val formattedName = formatName(name, owner) val result = _memo.getOrElseUpdate((owner.s, formattedName), builder(formattedName)) val mutableBasic = collection.mutable.Set(basics.toSeq: _*) - if (!basics.exists(_.isInstanceOf[Load])) + if (withDefaultServices && !basics.exists(_.isInstanceOf[Load])) mutableBasic += Load(Symbol(s"${formattedName.name}_load")) - if (!basics.exists(_.isInstanceOf[Store])) + if (withDefaultServices && !basics.exists(_.isInstanceOf[Store])) mutableBasic += Store(Symbol(s"${formattedName.name}_store")) p.add(result, mutableBasic) result } + /** + * A physical component can be defined by its name and the basic services it provides + * + * @param name the physical component name + * @param basics the set of basic services provided, if empty a default store and load services are added + * @param p implicitly retrieved relation linking components to their provided services + * @param owner implicitly retrieved name of the platform + * @return the physical component + * @group publicConstructor + */ + def apply(name: Symbol, basics: Set[Service])(implicit + p: ProvideRelation[Hardware, Service], + owner: Owner): T = { + apply(name, basics, true) + } + /** * A physical component can be defined only its name, the services will be defined by default * @group publicConstructor @@ -131,5 +149,5 @@ trait BaseHardwareNodeBuilder[T <: Hardware] extends PMLNodeBuilder[T] { */ def apply(name: Symbol)(implicit p: ProvideRelation[Hardware, Service], owner: Owner): T = - apply(name, Set.empty) + apply(name, Set.empty, true) } diff --git a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala index e9019c1..e1ac118 100644 --- a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala +++ b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala @@ -26,4 +26,16 @@ class HardwareTest extends AnyFlatSpec with should.Matchers { h.services.size shouldBe 2 } } + + it should "have no services when specified" in { + val t: Target = Target(withDefaultServices=false) + val s: SimpleTransporter = SimpleTransporter(withDefaultServices=false) + val i: Initiator = Initiator(withDefaultServices=false) + val v: Virtualizer = Virtualizer(withDefaultServices=false) + + for (h <- List(t, s, i, v)) { + h.services shouldBe empty + } + } + }