Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 416f784

Browse files
committed
Allow ArrayLength attribute in Component tags
Numerical parameters as well as ParameterBlocks can have an "ArrayLength" attribute that instantiate as many identical parameters or parameter blocks. This is now also possible for Component instances (not types). When used, a ParameterBlock is created with the name of the arrayed Component and as many Components will be created with their names being "0", "1", "2", ... *** Use with caution! *** You shouldn't define any context or instantiation mapping at or below the level of the "arrayed" component. This also concerns the Component's type (since the Component will inherit its type's mapping). In other words, only use "ArrayLength" on components that do not have any mapping and which content does not have any mapping either. DO: <ComponentType Name="MyType"> <IntegerParameter Name="some_int" Size="8"/> <FixedPointParameter Name="some_fp" Size="8" Integral="1" Fractional="6"/> </ComponentType> <InstanceDefinition> <Component Type="MyType" ArrayLength="2"/> </InstanceDefinition> DON'T: <ComponentType Name="MyType" Mapping="Ctx1:foo" Extends="SomeTypeWithMapping"> <IntegerParameter Name="some_int" Size="8" Mapping="Instance:1"/> <FixedPointParameter Name="some_fp" Size="8" Integral="1" Fractional="6" Mapping="Instance:2"/> </ComponentType> <InstanceDefinition> <Component Type="MyType" ArrayLength="2" Mapping="Ctx2:bar"/> </InstanceDefinition> Signed-off-by: David Wagner <[email protected]>
1 parent dfa10b7 commit 416f784

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

parameter/ComponentInstance.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "ComponentLibrary.h"
3232
#include "ComponentType.h"
3333
#include "Component.h"
34+
#include "ParameterBlock.h" // for "array" instantiation
3435
#include "XmlParameterSerializingContext.h"
3536

3637
#define base CTypeElement
@@ -110,12 +111,33 @@ bool CComponentInstance::fromXml(const CXmlElement& xmlElement, CXmlSerializingC
110111

111112
CInstanceConfigurableElement* CComponentInstance::doInstantiate() const
112113
{
113-
return new CComponent(getName(), this);
114+
if (isScalar()) {
115+
return new CComponent(getName(), this);
116+
} else {
117+
return new CParameterBlock(getName(), this);
118+
}
114119
}
115120

116121
void CComponentInstance::populate(CElement* pElement) const
117122
{
118-
base::populate(pElement);
123+
size_t arrayLength = getArrayLength();
124+
125+
if (arrayLength != 0) {
126+
127+
// Create child elements
128+
for (size_t child = 0; child < arrayLength; child++) {
129+
130+
CComponent* pChildComponent = new CComponent(std::to_string(child), this);
119131

120-
_pComponentType->populate(static_cast<CComponent*>(pElement));
132+
pElement->addChild(pChildComponent);
133+
134+
base::populate(pChildComponent);
135+
136+
_pComponentType->populate(pChildComponent);
137+
}
138+
} else {
139+
base::populate(pElement);
140+
141+
_pComponentType->populate(static_cast<CComponent*>(pElement));
142+
}
121143
}

schemas/Parameter.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</xs:attributeGroup>
1111
<xs:complexType name="ComponentInstance">
1212
<xs:attributeGroup ref="TypedNameable"/>
13+
<xs:attributeGroup ref="ArrayLengthAttribute"/>
1314
<xs:attribute name="Mapping" use="optional"/>
1415
</xs:complexType>
1516
<xs:simpleType name="SizeType">

test/functional-tests/Handle.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ struct AllParamsPF : public ParameterFramework
102102
nodeDesc("ParameterBlock", "parameter_block_array",
103103
getBasicParams(), "ArrayLength='2'") +
104104
nodeDesc("Component", "component_scalar", "", "Type='component_type'") +
105-
// Test that ArrayLength have no effect on components
106105
nodeDesc("Component", "component_array", "",
107106
"Type='component_type' ArrayLength='2'");
108107
return config;
@@ -220,10 +219,12 @@ SCENARIO_METHOD(AllParamsPF, "Export component", "[handler][structure][xml]")
220219

221220
SCENARIO_METHOD(AllParamsPF, "Export component array", "[handler][structure][xml]")
222221
{
223-
string expected = rootNode("ParameterBlock", "Name='component_array' "
224-
"Description='description_component_array'",
225-
// component array are the same as non array for now
226-
getBasicParams());
222+
string expected = rootNode("ParameterBlock",
223+
"Name='component_array' Description='description_component_array'",
224+
nodeDesc("ParameterBlock", "0", getBasicParams(), "",
225+
"description_component_array") +
226+
nodeDesc("ParameterBlock", "1", getBasicParams(), "",
227+
"description_component_array"));
227228
checkStructure("/test/test/component_array", expected);
228229
}
229230

@@ -239,7 +240,12 @@ SCENARIO_METHOD(AllParamsPF, "Export all parameters", "[handler][structure][xml]
239240
"description_parameter_block_array")) +
240241
// Components should be exported as parameterBlock
241242
nodeDesc("ParameterBlock", "component_scalar", getBasicParams()) +
242-
nodeDesc("ParameterBlock", "component_array", getBasicParams());
243+
nodeDesc("ParameterBlock", "component_array",
244+
nodeDesc("ParameterBlock", "0", getBasicParams(), "",
245+
// description is inherited from array
246+
"description_component_array") +
247+
nodeDesc("ParameterBlock", "1", getBasicParams(), "",
248+
"description_component_array"));
243249

244250
WHEN("Exporting subsystem") {
245251
string expected = rootNode("Subsystem", "Name='test'", paramExpected);
@@ -274,7 +280,9 @@ struct SettingsTestPF : public AllParamsPF
274280
parameterBlockNode("0", settings) +
275281
parameterBlockNode("1", settings)) +
276282
parameterBlockNode("component_scalar", settings) +
277-
parameterBlockNode("component_array", settings);
283+
parameterBlockNode("component_array",
284+
parameterBlockNode("0", settings) +
285+
parameterBlockNode("1", settings));
278286

279287
return rootNode("SystemClass", "Name='test'" ,
280288
node("Subsystem", "test", settings, ""));
@@ -283,7 +291,9 @@ struct SettingsTestPF : public AllParamsPF
283291
static string fullBytesSettings(const string &basicSettings)
284292
{
285293
string fullSettings;
286-
for (size_t i = 0; i < 6; ++i) {
294+
// We have the "basic params" repeated 7 times across the test
295+
// structure
296+
for (size_t i = 0; i < 7; ++i) {
287297
fullSettings += basicSettings;
288298
}
289299
return fullSettings;

0 commit comments

Comments
 (0)