Skip to content

Commit

Permalink
[ADDITIVE] Add field access policies to field.
Browse files Browse the repository at this point in the history
  • Loading branch information
hagantsa committed Aug 3, 2023
1 parent 47fd20e commit 7479a78
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 36 deletions.
16 changes: 16 additions & 0 deletions IPXACTmodels/Component/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,22 @@ void Field::setParameters(QSharedPointer<QList<QSharedPointer<Parameter> > > new
parameters_ = newParameters;
}

//-----------------------------------------------------------------------------
// Function: Field::getFieldAccessPolicies()
//-----------------------------------------------------------------------------
QSharedPointer<QList<QSharedPointer<FieldAccessPolicy> > > Field::getFieldAccessPolicies() const
{
return fieldAccessPolicies_;
}

//-----------------------------------------------------------------------------
// Function: Field::setFieldAccessPolicies()
//-----------------------------------------------------------------------------
void Field::setFieldAccessPolicies(QSharedPointer<QList<QSharedPointer<FieldAccessPolicy> > > newFieldAccessPolicies)
{
fieldAccessPolicies_ = newFieldAccessPolicies;
}

//-----------------------------------------------------------------------------
// Function: Field::copyEnumeratedValues()
//-----------------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions IPXACTmodels/Component/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <IPXACTmodels/Component/FieldReset.h>
#include <IPXACTmodels/Component/FieldReference.h>
#include <IPXACTmodels/Component/FieldAccessPolicy.h>

#include <QString>
#include <QMap>
Expand Down Expand Up @@ -384,6 +385,20 @@ class IPXACTMODELS_EXPORT Field : public NameGroup, public Extendable
*/
void setParameters(QSharedPointer<QList<QSharedPointer<Parameter> > > newParameters);

/*!
* Get the field access policies of the field.
*
* @return Pointer to a list containing the field access policies.
*/
QSharedPointer<QList<QSharedPointer<FieldAccessPolicy> > > getFieldAccessPolicies() const;

/*!
* Set the field access policies for the field.
*
* @param [in] newFieldAccessPolicies The new field access policies.
*/
void setFieldAccessPolicies(QSharedPointer<QList<QSharedPointer<FieldAccessPolicy> > > newFieldAccessPolicies);

private:

/*!
Expand Down Expand Up @@ -483,6 +498,10 @@ class IPXACTMODELS_EXPORT Field : public NameGroup, public Extendable

//! Reference to another field (ipxact:aliasOf).
QSharedPointer<FieldReference> fieldReference_;

//! The field access policies of the field, for standard revision 2022.
QSharedPointer<QList<QSharedPointer<FieldAccessPolicy> > > fieldAccessPolicies_ =
QSharedPointer<QList<QSharedPointer<FieldAccessPolicy> > >(new QList<QSharedPointer<FieldAccessPolicy> > ());
};

Q_DECLARE_METATYPE(QSharedPointer<Field>);
Expand Down
49 changes: 37 additions & 12 deletions IPXACTmodels/Component/FieldReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "WriteValueConstraint.h"
#include "MemoryArrayReader.h"
#include "FieldReferenceReader.h"
#include "FieldAccessPolicyReader.h"

#include <IPXACTmodels/common/NameGroupReader.h>

Expand All @@ -34,12 +35,21 @@ QSharedPointer<Field> FieldReader::createFieldFrom(QDomNode const& fieldNode, Do
{
Details::parseID(fieldElement, newField);
Details::parsePresence(fieldElement, newField);

Details::parseAccess(fieldElement, newField);
Details::parseModifiedWriteValue(fieldElement, newField);
Details::parseWriteValueConstraint(fieldElement, newField);
Details::parseReadAction(fieldElement, newField);
Details::parseTestable(fieldElement, newField);
Details::parseReserved(fieldElement, newField);

}
else if (docRevision == Document::Revision::Std22)
{
Details::parseMemoryArray(fieldElement, newField);
Details::parseFieldDefinitionRef(fieldElement, newField);
Details::parseFieldReference(fieldElement, newField);
Details::parseFieldAccessPolicies(fieldElement, newField);
}

Details::parseBitOffset(fieldElement, newField);
Expand All @@ -52,20 +62,8 @@ QSharedPointer<Field> FieldReader::createFieldFrom(QDomNode const& fieldNode, Do

Details::parseVolatile(fieldElement, newField);

Details::parseAccess(fieldElement, newField);

Details::parseEnumeratedValues(fieldElement, newField);

Details::parseModifiedWriteValue(fieldElement, newField);

Details::parseWriteValueConstraint(fieldElement, newField);

Details::parseReadAction(fieldElement, newField);

Details::parseTestable(fieldElement, newField);

Details::parseReserved(fieldElement, newField);

Details::parseParameters(fieldElement, newField);

CommonItemsReader::parseVendorExtensions(fieldNode, newField);
Expand Down Expand Up @@ -408,3 +406,30 @@ void FieldReader::Details::parseParameters(QDomElement const& fieldElement, QSha
}
}
}

//-----------------------------------------------------------------------------
// Function: FieldReader::Details::parseFieldAccessPolicies()
//-----------------------------------------------------------------------------
void FieldReader::Details::parseFieldAccessPolicies(QDomElement const& fieldElement, QSharedPointer<Field> newField)
{
auto fieldAccessPoliciesElement = fieldElement.firstChildElement(QStringLiteral("ipxact:fieldAccessPolicies"));

if (fieldAccessPoliciesElement.isNull() || fieldAccessPoliciesElement.hasChildNodes() == false)
{
return;
}

auto fieldAccessPolicies = fieldAccessPoliciesElement.childNodes();

for (int i = 0; i < fieldAccessPolicies.size(); ++i)
{
auto fieldAccessPolicyNode = fieldAccessPolicies.at(i);

if (fieldAccessPolicyNode.nodeName() == QStringLiteral("ipxact:fieldAccessPolicy"))
{
auto newFieldAccessPolicy = FieldAccessPolicyReader::createFieldAccessPolicyFrom(fieldAccessPolicyNode);

newField->getFieldAccessPolicies()->append(newFieldAccessPolicy);
}
}
}
8 changes: 8 additions & 0 deletions IPXACTmodels/Component/FieldReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ namespace FieldReader
* @param [in] newField The new field item.
*/
void parseParameters(QDomElement const& fieldElement, QSharedPointer<Field> newField);

/*!
* Parse 2022 std field access policies.
*
* @param [in] fieldElement XML description of the field.
* @param [in] newField The new field item.
*/
void parseFieldAccessPolicies(QDomElement const& fieldElement, QSharedPointer<Field> newField);
}
};

Expand Down
36 changes: 14 additions & 22 deletions IPXACTmodels/Component/FieldWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

#include "FieldWriter.h"
#include "FieldReferenceWriter.h"
#include "FieldAccessPolicyWriter.h"
#include "Field.h"
#include "WriteValueConstraint.h"
#include "MemoryArrayWriter.h"
#include "EnumeratedValueWriter.h"
#include "FieldReset.h"

#include <IPXACTmodels/common/NameGroupWriter.h>
#include <IPXACTmodels/Component/EnumeratedValueWriter.h>
#include <IPXACTmodels/Component/FieldReset.h>

//-----------------------------------------------------------------------------
// Function: FieldWriter::writeField()
Expand Down Expand Up @@ -330,33 +331,24 @@ void FieldWriter::Details::writeFieldData2022(QXmlStreamWriter& writer, QSharedP
writer.writeTextElement(QStringLiteral("ipxact:bitWidth"), bitWidth);
}

// TODO: write field access policy

Details::writeVolatile(writer, field);

Details::writeResets(writer, field);

Details::writeFieldReference(writer, field); // ipxact:aliasOf

Details::writeAccess(writer, field);

Details::writeModifiedWriteValue(writer, field);

Details::writeWriteValueConstraint(writer, field->getWriteConstraint());

Details::writeReadAction(writer, field);

// TODO: writeReadResponse

// TODO: writeBroadcasts

// TODO: writeAccessRestrictions

Details::writeTestable(writer, field);

Details::writeReserved(writer, field);
if (auto const& fieldAccessPolicies = field->getFieldAccessPolicies();
fieldAccessPolicies->isEmpty() == false)
{
writer.writeStartElement(QStringLiteral("ipxact:fieldAccessPolicies"));

for (auto const& fieldAccessPolicy : *fieldAccessPolicies)
{
FieldAccessPolicyWriter::writeFieldAccessPolicy(writer, fieldAccessPolicy);
}

// TODO: writeVendorExtensions
writer.writeEndElement(); // ipxact:fieldAccessPolicies
}

Details::writeEnumerations(writer, field);
}
Expand Down
12 changes: 10 additions & 2 deletions tests/IPXACTmodels/Component/tst_FieldReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,27 @@ void tst_FieldReader::readFieldReference()
//-----------------------------------------------------------------------------
void tst_FieldReader::readFieldAccessPolicies()
{
QString document(
QString documentContent(
"<ipxact:field>"
"<ipxact:name>testField</ipxact:name>"
"<ipxact:bitOffset>8</ipxact:bitOffset>"
"<ipxact:bitWidth>16</ipxact:bitWidth>"
"<ipxact:fieldAccessPolicies>"
"<ipxact:fieldAccessPolicy>"
"<ipxact:modeRef priority=\"0\">testMode</ipxact:modeRef>"
"<ipcact:fieldAccessPolicyDefinitionRef typeDefinitions=\"testDefinition\"/>"
"<ipxact:fieldAccessPolicyDefinitionRef typeDefinitions=\"testDefinition\"/>"
"</ipxact:fieldAccessPolicy>"
"</ipxact:fieldAccessPolicies>"
"</ipxact:field>"
);

QDomDocument document;
document.setContent(documentContent);

QDomNode fieldNode = document.firstChildElement("ipxact:field");
QSharedPointer<Field> testField = FieldReader::createFieldFrom(fieldNode, Document::Revision::Std22);

QCOMPARE(testField->getFieldAccessPolicies()->size(), 1);
}

//-----------------------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions tests/IPXACTmodels/Component/tst_FieldWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ private slots:
void writeTestable();
void writeReserved();

void writeFieldAccessPolicies();

void writeParameters();

void writeVendorExtensions();
Expand Down Expand Up @@ -673,6 +675,41 @@ void tst_FieldWriter::writeReserved()
QCOMPARE(output, expectedOutput);
}

//-----------------------------------------------------------------------------
// Function: tst_FieldWriter::writeFieldAccessPolicies()
//-----------------------------------------------------------------------------
void tst_FieldWriter::writeFieldAccessPolicies()
{
QString output;
QXmlStreamWriter xmlStreamWriter(&output);

QSharedPointer<FieldAccessPolicy> testFieldAccessPolicy(new FieldAccessPolicy());
testFieldAccessPolicy->setTestable(true);
testFieldAccessPolicy->setTestConstraint(General::TEST_RESTORE);
testFieldAccessPolicy->setAccess(AccessTypes::READ_ONLY);
testFieldAccessPolicy->setReadAction(General::READ_CLEAR);

testField_->getFieldAccessPolicies()->append(testFieldAccessPolicy);

QString expectedOutput(
"<ipxact:field>"
"<ipxact:name>testField</ipxact:name>"
"<ipxact:bitOffset>Baldur's</ipxact:bitOffset>"
"<ipxact:bitWidth>Gate</ipxact:bitWidth>"
"<ipxact:fieldAccessPolicies>"
"<ipxact:fieldAccessPolicy>"
"<ipxact:access>read-only</ipxact:access>"
"<ipxact:readAction>clear</ipxact:readAction>"
"<ipxact:testable testConstraint=\"restore\">true</ipxact:testable>"
"</ipxact:fieldAccessPolicy>"
"</ipxact:fieldAccessPolicies>"
"</ipxact:field>"
);

FieldWriter::writeField(xmlStreamWriter, testField_, Document::Revision::Std22);
QCOMPARE(output, expectedOutput);
}

//-----------------------------------------------------------------------------
// Function: tst_FieldWriter::writeParameters()
//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 7479a78

Please sign in to comment.