Skip to content

Commit

Permalink
[ADDITIVE] Add Arrays in SubPorts
Browse files Browse the repository at this point in the history
  • Loading branch information
epekkar committed Nov 22, 2023
1 parent b6721d2 commit 7ed95c8
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 62 deletions.
28 changes: 13 additions & 15 deletions IPXACTmodels/Component/Port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ QString Port::getArrayLeft() const
return QString();
}

return configurableArrays_->first()->getLeft();
return configurableArrays_->first().getLeft();
}

//-----------------------------------------------------------------------------
Expand All @@ -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);
}
}
}
Expand All @@ -527,7 +526,7 @@ QString Port::getArrayRight() const
return QString();
}

return configurableArrays_->first()->getRight();
return configurableArrays_->first().getRight();
}

//-----------------------------------------------------------------------------
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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_;
}
Expand Down
4 changes: 2 additions & 2 deletions IPXACTmodels/Component/Port.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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>)
Expand Down
23 changes: 14 additions & 9 deletions IPXACTmodels/Component/PortReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

//-----------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions IPXACTmodels/Component/PortReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions IPXACTmodels/Component/PortWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion IPXACTmodels/Component/PortWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};

Expand Down
39 changes: 23 additions & 16 deletions IPXACTmodels/Component/Structured.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions IPXACTmodels/Component/SubPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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.
Expand All @@ -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_;
};
Expand Down
14 changes: 7 additions & 7 deletions IPXACTmodels/Component/validators/PortValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()));
}
}

Expand Down
Loading

0 comments on commit 7ed95c8

Please sign in to comment.