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

Commit 0ba8ce6

Browse files
committed
Merge pull request #305 from dawagner/component-arrays
Add "array" capability to Components 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). The Semantic of this feature is very unclear, even now... use with caution and see 416f784.
2 parents 67fd096 + 416f784 commit 0ba8ce6

File tree

9 files changed

+64
-31
lines changed

9 files changed

+64
-31
lines changed

parameter/Component.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,5 @@ class CComponent : public CInstanceConfigurableElement
4545
{
4646
return EComponent;
4747
}
48-
49-
std::string getXmlElementName() const override
50-
{
51-
// Once instantiated components are reflected as parameter blocks
52-
// in XML documents
53-
return "ParameterBlock";
54-
}
5548
};
5649

parameter/ComponentInstance.cpp

Lines changed: 33 additions & 4 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
@@ -41,7 +42,14 @@ CComponentInstance::CComponentInstance(const std::string& strName) : base(strNam
4142

4243
std::string CComponentInstance::getKind() const
4344
{
44-
return "Component";
45+
return "ComponentInstance";
46+
}
47+
48+
std::string CComponentInstance::getXmlElementName() const
49+
{
50+
// Once instantiated components are reflected as parameter blocks
51+
// in XML documents
52+
return "ParameterBlock";
4553
}
4654

4755
bool CComponentInstance::childrenAreDynamic() const
@@ -103,12 +111,33 @@ bool CComponentInstance::fromXml(const CXmlElement& xmlElement, CXmlSerializingC
103111

104112
CInstanceConfigurableElement* CComponentInstance::doInstantiate() const
105113
{
106-
return new CComponent(getName(), this);
114+
if (isScalar()) {
115+
return new CComponent(getName(), this);
116+
} else {
117+
return new CParameterBlock(getName(), this);
118+
}
107119
}
108120

109121
void CComponentInstance::populate(CElement* pElement) const
110122
{
111-
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++) {
112129

113-
_pComponentType->populate(static_cast<CComponent*>(pElement));
130+
CComponent* pChildComponent = new CComponent(std::to_string(child), this);
131+
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+
}
114143
}

parameter/ComponentInstance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CComponentInstance : public CTypeElement
5555

5656
// CElement
5757
virtual std::string getKind() const;
58+
std::string getXmlElementName() const override;
5859
private:
5960
virtual bool childrenAreDynamic() const;
6061
virtual CInstanceConfigurableElement* doInstantiate() const;

parameter/InstanceConfigurableElement.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ std::string CInstanceConfigurableElement::getKind() const
4747
return _pTypeElement->getKind();
4848
}
4949

50+
std::string CInstanceConfigurableElement::getXmlElementName() const
51+
{
52+
// Delegate
53+
return _pTypeElement->getXmlElementName();
54+
}
55+
5056
// Type element
5157
const CTypeElement* CInstanceConfigurableElement::getTypeElement() const
5258
{

parameter/InstanceConfigurableElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class PARAMETER_EXPORT CInstanceConfigurableElement : public CConfigurableElemen
7070

7171
// From CElement
7272
virtual std::string getKind() const;
73+
std::string getXmlElementName() const override;
7374

7475
// Syncer to/from HW
7576
void setSyncer(ISyncer* pSyncer);

parameter/MappingContext.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ using std::string;
3737
// Item access
3838
bool CMappingContext::setItem(size_t itemType, const string* pStrKey, const string* pStrItem)
3939
{
40-
// Assert that the key hasn't been set before
41-
assert(find_if(begin(mItems), end(mItems), [pStrKey](SItem &item)
42-
{ return item.strKey == pStrKey; }
43-
) == end(mItems));
44-
45-
if (mItems[itemType].bSet) {
40+
if (iSet(itemType)) {
4641
// Already set!
4742
return false;
4843
}
@@ -53,8 +48,6 @@ bool CMappingContext::setItem(size_t itemType, const string* pStrKey, const stri
5348
// Set item value
5449
mItems[itemType].strItem = pStrItem;
5550

56-
// Now is set
57-
mItems[itemType].bSet = true;
5851
return true;
5952
}
6053

@@ -83,5 +76,5 @@ const string* CMappingContext::getItem(const string& strKey) const
8376

8477
bool CMappingContext::iSet(size_t itemType) const
8578
{
86-
return mItems[itemType].bSet;
79+
return mItems[itemType].strItem != nullptr;
8780
}

parameter/MappingContext.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ class PARAMETER_EXPORT CMappingContext
4141
private:
4242
// Item structure
4343
struct SItem {
44-
const std::string* strKey;
45-
const std::string* strItem;
46-
bool bSet;
44+
const std::string* strKey{nullptr};
45+
const std::string* strItem{nullptr};
4746
};
4847

4948
public:

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)