diff --git a/IPXACTmodels/Component/Port.cpp b/IPXACTmodels/Component/Port.cpp index 66eb7a1e6..058ea6212 100644 --- a/IPXACTmodels/Component/Port.cpp +++ b/IPXACTmodels/Component/Port.cpp @@ -490,7 +490,7 @@ QString Port::getArrayLeft() const return QString(); } - return configurableArrays_->first()->getLeft(); + return configurableArrays_->first().getLeft(); } //----------------------------------------------------------------------------- @@ -500,19 +500,18 @@ void Port::setArrayLeft(QString const& newArrayLeft) { if (configurableArrays_->isEmpty()) { - QSharedPointer<Array> newArray (new Array(newArrayLeft, QStringLiteral("0"))); - configurableArrays_->append(newArray); + configurableArrays_->append(Array(newArrayLeft, QStringLiteral("0"))); } else { - QSharedPointer<Array> portArray = configurableArrays_->first(); - if (newArrayLeft.isEmpty() && portArray->getRight().isEmpty()) + auto& portArray = configurableArrays_->first(); + if (newArrayLeft.isEmpty() && portArray.getRight().isEmpty()) { - configurableArrays_->removeOne(portArray); + configurableArrays_->removeFirst(); } else { - portArray->setLeft(newArrayLeft); + portArray.setLeft(newArrayLeft); } } } @@ -527,7 +526,7 @@ QString Port::getArrayRight() const return QString(); } - return configurableArrays_->first()->getRight(); + return configurableArrays_->first().getRight(); } //----------------------------------------------------------------------------- @@ -537,19 +536,18 @@ void Port::setArrayRight(QString const& newArrayRight) { if (configurableArrays_->isEmpty()) { - QSharedPointer<Array> newArray (new Array(QStringLiteral("0"), newArrayRight)); - configurableArrays_->append(newArray); + configurableArrays_->append(Array(QStringLiteral("0"), newArrayRight)); } else { - QSharedPointer<Array> portArray = configurableArrays_->first(); - if (portArray->getLeft().isEmpty() && newArrayRight.isEmpty()) + auto& portArray = configurableArrays_->first(); + if (portArray.getLeft().isEmpty() && newArrayRight.isEmpty()) { - configurableArrays_->removeOne(portArray); + configurableArrays_->removeFirst(); } else { - portArray->setRight(newArrayRight); + portArray.setRight(newArrayRight); } } } @@ -609,7 +607,7 @@ void Port::setIsPresent(QString const& newIsPresent) //----------------------------------------------------------------------------- // Function: Port::getArrays() //----------------------------------------------------------------------------- -QSharedPointer<QList<QSharedPointer<Array> > > Port::getArrays() const +QSharedPointer<QList<Array> > Port::getArrays() const { return configurableArrays_; } diff --git a/IPXACTmodels/Component/Port.h b/IPXACTmodels/Component/Port.h index deb1fdefa..98cf3ae9b 100644 --- a/IPXACTmodels/Component/Port.h +++ b/IPXACTmodels/Component/Port.h @@ -321,7 +321,7 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable * * @return Pointer to a list containing the arrays. */ - QSharedPointer<QList<QSharedPointer<Array> > > getArrays() const; + QSharedPointer<QList<Array> > getArrays() const; /*! * Get the wire type definitions. @@ -356,7 +356,7 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable QSharedPointer<Structured> structured_{ nullptr }; //! The list of arrays. - QSharedPointer<QList<QSharedPointer<Array> > > configurableArrays_{ new QList<QSharedPointer<Array> >() }; + QSharedPointer<QList<Array > > configurableArrays_{ new QList<Array>() }; }; Q_DECLARE_METATYPE(QSharedPointer<Port>) diff --git a/IPXACTmodels/Component/PortReader.cpp b/IPXACTmodels/Component/PortReader.cpp index 77155d2e2..b3ad2c591 100644 --- a/IPXACTmodels/Component/PortReader.cpp +++ b/IPXACTmodels/Component/PortReader.cpp @@ -47,7 +47,7 @@ QSharedPointer<Port> PortReader::createPortFrom(QDomNode const& portNode, Docume } } - Details::parseArrays(portNode, newPort); + newPort->getArrays()->append(Details::createArrays(portNode)); Details::parsePortExtensions(portNode, newPort); @@ -412,28 +412,33 @@ void PortReader::Details::parseSubPorts(QDomElement const& structuredElement, QS parsedSubPort->setStructured(Details::createStructuredFrom(nestedStructured)); } + parsedSubPort->getArrays()->append(createArrays(subPortElement)); + newStructured->getSubPorts()->append(parsedSubPort); } } //----------------------------------------------------------------------------- -// Function: PortReader::Details::parseArrays() +// Function: PortReader::Details::createArrays() //----------------------------------------------------------------------------- -void PortReader::Details::parseArrays(QDomNode const& portNode, QSharedPointer<Port> newPort) +QList<Array> PortReader::Details::createArrays(QDomNode const& parentNode) { - QDomElement arraysElement = portNode.firstChildElement(QStringLiteral("ipxact:arrays")); + const auto arraysElement = parentNode.firstChildElement(QStringLiteral("ipxact:arrays")); - QDomNodeList arrayNodeList = arraysElement.elementsByTagName(QStringLiteral("ipxact:array")); + const auto arrayNodeList = arraysElement.elementsByTagName(QStringLiteral("ipxact:array")); + QList<Array> parsedArrays; for (int arrayIndex = 0; arrayIndex < arrayNodeList.count(); ++arrayIndex) { - QDomNode arrayNode = arrayNodeList.at(arrayIndex); + auto const& arrayNode = arrayNodeList.at(arrayIndex); - QString arrayLeft = arrayNode.firstChildElement(QStringLiteral("ipxact:left")).firstChild().nodeValue(); - QString arrayRight = arrayNode.firstChildElement(QStringLiteral("ipxact:right")).firstChild().nodeValue(); + auto arrayLeft = arrayNode.firstChildElement(QStringLiteral("ipxact:left")).firstChild().nodeValue(); + auto arrayRight = arrayNode.firstChildElement(QStringLiteral("ipxact:right")).firstChild().nodeValue(); - newPort->getArrays()->append(QSharedPointer<Array>(new Array(arrayLeft, arrayRight))); + parsedArrays.append(Array(arrayLeft, arrayRight)); } + + return parsedArrays; } //----------------------------------------------------------------------------- diff --git a/IPXACTmodels/Component/PortReader.h b/IPXACTmodels/Component/PortReader.h index f3f6deb68..f3df2360f 100644 --- a/IPXACTmodels/Component/PortReader.h +++ b/IPXACTmodels/Component/PortReader.h @@ -176,15 +176,21 @@ namespace PortReader */ void parseStructuredVectors(QDomElement const& structuredElement, QSharedPointer<Structured> newStructured); + /*! + * Parse the sub-ports in the structured port. + * + * @param [in] structuredElementt The XML description of the structured port. + * @param [in] newStructured The containing structured port. + */ void parseSubPorts(QDomElement const& structuredElement, QSharedPointer<Structured> newStructured); /*! * Parse the port arrays. * - * @param [in] portNode XML description of the port. + * @param [in] parentNode XML node . * @param [in] newPort The containing port item. */ - void parseArrays(QDomNode const& portNode, QSharedPointer<Port> newPort); + QList<Array> createArrays(QDomNode const& parentNode); /*! * Parse the port vendor extensions. diff --git a/IPXACTmodels/Component/PortWriter.cpp b/IPXACTmodels/Component/PortWriter.cpp index eb7509f98..98b464a66 100644 --- a/IPXACTmodels/Component/PortWriter.cpp +++ b/IPXACTmodels/Component/PortWriter.cpp @@ -395,7 +395,7 @@ void PortWriter::writeSubPorts(QXmlStreamWriter& writer, QSharedPointer<Structur //----------------------------------------------------------------------------- // Function: PortWriter::writeArrays() //----------------------------------------------------------------------------- -void PortWriter::writeArrays(QXmlStreamWriter& writer, QSharedPointer<QList<QSharedPointer<Array> > > arrays) const +void PortWriter::writeArrays(QXmlStreamWriter& writer, QSharedPointer<QList<Array> > arrays) const { if (arrays->isEmpty()) { @@ -408,8 +408,8 @@ void PortWriter::writeArrays(QXmlStreamWriter& writer, QSharedPointer<QList<QSha { writer.writeStartElement(QStringLiteral("ipxact:array")); - writer.writeTextElement(QStringLiteral("ipxact:left"), singleArray->getLeft()); - writer.writeTextElement(QStringLiteral("ipxact:right"), singleArray->getRight()); + writer.writeTextElement(QStringLiteral("ipxact:left"), singleArray.getLeft()); + writer.writeTextElement(QStringLiteral("ipxact:right"), singleArray.getRight()); writer.writeEndElement(); // ipxact:array } diff --git a/IPXACTmodels/Component/PortWriter.h b/IPXACTmodels/Component/PortWriter.h index ef416f9db..bb661e25f 100644 --- a/IPXACTmodels/Component/PortWriter.h +++ b/IPXACTmodels/Component/PortWriter.h @@ -167,7 +167,7 @@ class IPXACTMODELS_EXPORT PortWriter * @param [in] writer Used XML writer. * @param [in] arrays The arrays to be written. */ - void writeArrays(QXmlStreamWriter& writer, QSharedPointer<QList<QSharedPointer<Array> > > arrays) const; + void writeArrays(QXmlStreamWriter& writer, QSharedPointer<QList<Array> > arrays) const; }; diff --git a/IPXACTmodels/Component/Structured.h b/IPXACTmodels/Component/Structured.h index a9adf72fb..f85e300be 100644 --- a/IPXACTmodels/Component/Structured.h +++ b/IPXACTmodels/Component/Structured.h @@ -35,36 +35,30 @@ class IPXACTMODELS_EXPORT Structured }; /*! - * Description + * Set the structured port as packed. * - * @param [in] packed - * - * @return + * @param [in] packed Packed or not. */ constexpr void setPacked(bool packed) noexcept { packed_ = packed; } /*! - * Description - * + * Check if the structured port can be packed. * - * @return + * @return True, if the port can be packed, otherwise false. */ [[nodiscard]] bool isPacked() const noexcept { return packed_; } /*! - * Description + * Set the port type. * - * @param [in] type - * - * @return + * @param [in] type The type to set. */ constexpr void setType(Type type) noexcept { portType_ = type; } /*! - * Description - * + * Get the port type. * - * @return + * @return The port type. */ [[nodiscard]] constexpr Type getType() const noexcept { return portType_; } @@ -82,12 +76,25 @@ class IPXACTMODELS_EXPORT Structured */ [[nodiscard]] constexpr DirectionTypes::Direction getDirection() const noexcept { return direction_; } + /*! + * Get the vectors in the structured port. + * + * @return The vectors in the port. + */ [[nodiscard]] QSharedPointer<QList<Vector> > getVectors() const { return vectors_; } - + /*! + * Get the sub-ports in the structured port. + * + * @return The sub-ports in the port. + */ [[nodiscard]] SubPort::List getSubPorts() const { return subPorts_; } - + /*! + * Convert the structured type to string. + * + * @return The string representation of the type. + */ [[nodiscard]] static QString toString(Type type); private: diff --git a/IPXACTmodels/Component/SubPort.h b/IPXACTmodels/Component/SubPort.h index b366da54e..dfe258ef3 100644 --- a/IPXACTmodels/Component/SubPort.h +++ b/IPXACTmodels/Component/SubPort.h @@ -12,6 +12,7 @@ #ifndef SUBPORT_H #define SUBPORT_H +#include <IPXACTmodels/common/Array.h> #include <IPXACTmodels/common/NameGroup.h> #include <IPXACTmodels/ipxactmodels_global.h> @@ -84,6 +85,8 @@ class IPXACTMODELS_EXPORT SubPort : public NameGroup */ [[nodiscard]] QSharedPointer<Structured> getStructured() const { return structured_; } + [[nodiscard]] QSharedPointer<QList<Array> > getArrays() const { return arrays_; } + private: //! The sub-port wire port. @@ -92,6 +95,9 @@ class IPXACTMODELS_EXPORT SubPort : public NameGroup //! The nested structured port. QSharedPointer<Structured> structured_{ nullptr }; + //! The sub-port arrays. + QSharedPointer<QList<Array> > arrays_{ new QList<Array>() }; + //! Is the sub-port input, output or inout in an interface. bool isIO_; }; diff --git a/IPXACTmodels/Component/validators/PortValidator.cpp b/IPXACTmodels/Component/validators/PortValidator.cpp index eab18df88..4c2ab1e4c 100644 --- a/IPXACTmodels/Component/validators/PortValidator.cpp +++ b/IPXACTmodels/Component/validators/PortValidator.cpp @@ -109,9 +109,9 @@ bool PortValidator::hasValidIsPresent(QSharedPointer<Port> port) const bool PortValidator::hasValidArrays(QSharedPointer<Port> port) const { // Any arrays must have valid left and right. - for ( QSharedPointer<Array> array : *port->getArrays() ) + for ( auto const& array : *port->getArrays() ) { - if (!arrayValueIsValid(array->getLeft()) || !arrayValueIsValid(array->getRight())) + if (!arrayValueIsValid(array.getLeft()) || !arrayValueIsValid(array.getRight())) { return false; } @@ -338,17 +338,17 @@ void PortValidator::findErrorsIn(QVector<QString>& errors, QSharedPointer<Port> } // Any arrays must have valid left and right. - for ( QSharedPointer<Array> array : *port->getArrays() ) + for ( auto const& array : *port->getArrays() ) { - if (!arrayValueIsValid(array->getLeft())) + if (!arrayValueIsValid(array.getLeft())) { - errors.append(QObject::tr("The left of array is invalid: %1 in port %2").arg(array->getLeft(), + errors.append(QObject::tr("The left of array is invalid: %1 in port %2").arg(array.getLeft(), port->name())); } - if (!arrayValueIsValid(array->getRight())) + if (!arrayValueIsValid(array.getRight())) { errors.append(QObject::tr("The right of array is invalid: %1 in port %2").arg( - array->getRight(), port->name())); + array.getRight(), port->name())); } } diff --git a/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp b/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp index 1a69c023c..b7951a73e 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp +++ b/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp @@ -53,6 +53,7 @@ private slots: void readStructuredVectors_2022(); void readStructuredSubPortWire_2022(); void readNestedStructuredSubPort_2022(); + void readSubPortArrays_2022(); }; //----------------------------------------------------------------------------- @@ -1078,6 +1079,65 @@ void tst_ComponentPortReader::readNestedStructuredSubPort_2022() QCOMPARE(wire->getDirection(), DirectionTypes::IN); } +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortReader::readSubPortArrays_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortReader::readSubPortArrays_2022() +{ + + QString documentContent( + "<ipxact:port>" + "<ipxact:name>testPort</ipxact:name>" + "<ipxact:structured>" + "<ipxact:interface/>" + "<ipxact:subPorts>" + "<ipxact:subPort>" + "<ipxact:name>arrays</ipxact:name>" + "<ipxact:wire>" + "<ipxact:direction>in</ipxact:direction>" + "</ipxact:wire>" + "<ipxact:arrays>" + "<ipxact:array>" + "<ipxact:left>0</ipxact:left>" + "<ipxact:right>0</ipxact:right>" + "</ipxact:array>" + "<ipxact:array>" + "<ipxact:left>1</ipxact:left>" + "<ipxact:right>0</ipxact:right>" + "</ipxact:array>" + "</ipxact:arrays>" + "</ipxact:subPort>" + "</ipxact:subPorts>" + "</ipxact:structured>" + "</ipxact:port>" + ); + + QDomDocument document; + document.setContent(documentContent); + + QDomNode portNode = document.firstChildElement("ipxact:port"); + + QSharedPointer<Port> testPort = PortReader::createPortFrom(portNode, Document::Revision::Std22); + + QCOMPARE(testPort->getStructured().isNull(), false); + + auto structured = testPort->getStructured(); + QCOMPARE(structured->isPacked(), false); + QCOMPARE(structured->getSubPorts()->count(), 1); + + auto subPort = structured->getSubPorts()->first(); + QCOMPARE(subPort->getArrays()->count(), 2); + + auto firstArray = subPort->getArrays()->first(); + QCOMPARE(firstArray.getLeft(), "0"); + QCOMPARE(firstArray.getRight(), "0"); + + auto lastArray = subPort->getArrays()->last(); + QCOMPARE(lastArray.getLeft(), "1"); + QCOMPARE(lastArray.getRight(), "0"); + +} + QTEST_APPLESS_MAIN(tst_ComponentPortReader) #include "tst_ComponentPortReader.moc" diff --git a/version.h b/version.h index bf7a66105..fd9a468a1 100644 --- a/version.h +++ b/version.h @@ -10,20 +10,20 @@ #ifndef VERSIONNO__H #define VERSIONNO__H -#define VERSION_FULL 3.12.1047.0 +#define VERSION_FULL 3.12.1049.0 #define VERSION_BASEYEAR 0 #define VERSION_DATE "2023-11-22" -#define VERSION_TIME "11:33:25" +#define VERSION_TIME "13:55:07" #define VERSION_MAJOR 3 #define VERSION_MINOR 12 -#define VERSION_BUILDNO 1047 +#define VERSION_BUILDNO 1049 #define VERSION_EXTEND 0 -#define VERSION_FILE 3,12,1047,0 -#define VERSION_PRODUCT 3,12,1047,0 -#define VERSION_FILESTR "3,12,1047,0" -#define VERSION_PRODUCTSTR "3,12,1047,0" +#define VERSION_FILE 3,12,1049,0 +#define VERSION_PRODUCT 3,12,1049,0 +#define VERSION_FILESTR "3,12,1049,0" +#define VERSION_PRODUCTSTR "3,12,1049,0" #endif