diff --git a/IPXACTmodels/Component/ComponentReader.cpp b/IPXACTmodels/Component/ComponentReader.cpp index af3305361..53404447b 100644 --- a/IPXACTmodels/Component/ComponentReader.cpp +++ b/IPXACTmodels/Component/ComponentReader.cpp @@ -48,14 +48,6 @@ ComponentReader::ComponentReader(): DocumentReader() } -//----------------------------------------------------------------------------- -// Function: ComponentReader::~DocumentReader() -//----------------------------------------------------------------------------- -ComponentReader::~ComponentReader() -{ - -} - //----------------------------------------------------------------------------- // Function: ComponentReader::createComponentFrom() //----------------------------------------------------------------------------- @@ -460,8 +452,7 @@ void ComponentReader::parseComponentGenerators(QDomNode const& componentNode, //----------------------------------------------------------------------------- void ComponentReader::parseChoices(QDomNode const& componentNode, QSharedPointer newComponent) const { - auto parsedChoices = CommonItemsReader::parseChoices(componentNode); - newComponent->setChoices(parsedChoices); + newComponent->setChoices(CommonItemsReader::parseChoices(componentNode)); } //----------------------------------------------------------------------------- @@ -836,24 +827,10 @@ void ComponentReader::parseFileDependencies(QDomNode const& fileNode, QSharedPoi QString file2 = dependencyElement.firstChildElement(QStringLiteral("kactus2:fileRef2")).firstChild().nodeValue(); QString description = dependencyElement.firstChildElement(QStringLiteral("ipxact:description")).firstChild().nodeValue(); - bool locked = false; - if (dependencyElement.attribute(QStringLiteral("locked")) == QLatin1String("true")) - { - locked = true; - } - - bool biDirectional = false; - if (dependencyElement.attribute(QStringLiteral("bidirectional")) == QLatin1String("true")) - { - biDirectional = true; - } + bool locked = dependencyElement.attribute(QStringLiteral("locked")) == QLatin1String("true"); + bool biDirectional = dependencyElement.attribute(QStringLiteral("bidirectional")) == QLatin1String("true"); + bool manual = dependencyElement.attribute(QStringLiteral("manual")) == QLatin1String("true"); - bool manual = false; - if (dependencyElement.attribute(QStringLiteral("manual")) == QLatin1String("true")) - { - manual = true; - } - QSharedPointer newDependency (new FileDependency()); newDependency->setFile1(file1); newDependency->setFile2(file2); diff --git a/IPXACTmodels/Component/ComponentReader.h b/IPXACTmodels/Component/ComponentReader.h index b2837fac0..a4631d6ef 100644 --- a/IPXACTmodels/Component/ComponentReader.h +++ b/IPXACTmodels/Component/ComponentReader.h @@ -35,7 +35,7 @@ class IPXACTMODELS_EXPORT ComponentReader : public DocumentReader /*! * The destructor. */ - ~ComponentReader(); + ~ComponentReader() = default; /*! * Creates a new component from a given component document. diff --git a/IPXACTmodels/Component/ComponentWriter.cpp b/IPXACTmodels/Component/ComponentWriter.cpp index ae20df8c0..6995a2458 100644 --- a/IPXACTmodels/Component/ComponentWriter.cpp +++ b/IPXACTmodels/Component/ComponentWriter.cpp @@ -41,14 +41,6 @@ ComponentWriter::ComponentWriter() : DocumentWriter() } -//----------------------------------------------------------------------------- -// Function: ComponentWriter::~ComponentWriter() -//----------------------------------------------------------------------------- -ComponentWriter::~ComponentWriter() -{ - -} - //----------------------------------------------------------------------------- // Function: ComponentWriter::writeComponent() //----------------------------------------------------------------------------- @@ -210,7 +202,7 @@ void ComponentWriter::writeModes(QXmlStreamWriter& writer, QSharedPointergetModes()) + for (auto const& mode : *component->getModes()) { ModeWriter::writeMode(writer, mode); } @@ -228,7 +220,7 @@ void ComponentWriter::writeAddressSpaces(QXmlStreamWriter& writer, QSharedPointe { writer.writeStartElement(QStringLiteral("ipxact:addressSpaces")); - foreach (QSharedPointer addressSpace, *component->getAddressSpaces()) + for (QSharedPointer addressSpace : *component->getAddressSpaces()) { AddressSpaceWriter::writeAddressSpace(writer, addressSpace, component->getRevision()); } @@ -369,7 +361,7 @@ void ComponentWriter::writeChoices(QXmlStreamWriter& writer, QSharedPointer choice, *component->getChoices()) + for (QSharedPointer choice : *component->getChoices()) { ChoiceWriter::writeChoice(writer, choice); } @@ -425,7 +417,7 @@ void ComponentWriter::writeOtherClockDrivers(QXmlStreamWriter& writer, QSharedPo writer.writeStartElement(QStringLiteral("ipxact:otherClockDrivers")); - foreach (QSharedPointer driver, *component->getOtherClockDrivers()) + for (QSharedPointer driver : *component->getOtherClockDrivers()) { clockWriter.writeOtherClockDriver(writer, driver); } diff --git a/IPXACTmodels/Component/ComponentWriter.h b/IPXACTmodels/Component/ComponentWriter.h index ead7ec800..125ef38c3 100644 --- a/IPXACTmodels/Component/ComponentWriter.h +++ b/IPXACTmodels/Component/ComponentWriter.h @@ -35,7 +35,7 @@ class IPXACTMODELS_EXPORT ComponentWriter : public DocumentWriter /*! * The destructor. */ - ~ComponentWriter(); + ~ComponentWriter() = default; /*! * Write a component to an XML file. diff --git a/IPXACTmodels/Component/Model.cpp b/IPXACTmodels/Component/Model.cpp index 8a9fd7abf..1687ec155 100644 --- a/IPXACTmodels/Component/Model.cpp +++ b/IPXACTmodels/Component/Model.cpp @@ -19,24 +19,16 @@ #include #include -//----------------------------------------------------------------------------- -// Function: Model::Model() -//----------------------------------------------------------------------------- -Model::Model() -{ - -} - //----------------------------------------------------------------------------- // Function: Model::Model() //----------------------------------------------------------------------------- Model::Model(Model const& other) { - copyViews(other); - copyComponentInstantiations(other); - copyDesignInstantiations(other); - copyDesignConfigurationInstantiations(other); - copyPorts(other); + Copy::copyList(other.views_, views_); + Copy::copyList(other.componentInstantiations_, componentInstantiations_); + Copy::copyList(other.designInstantiations_, designInstantiations_); + Copy::copyList(other.designConfigurationInstantiations_, designConfigurationInstantiations_); + Copy::copyList(other.ports_, ports_); } //----------------------------------------------------------------------------- @@ -47,31 +39,19 @@ Model& Model::operator=(Model const& other ) if (this != &other) { views_->clear(); - copyViews(other); + Copy::copyList(other.views_, views_); componentInstantiations_->clear(); - copyComponentInstantiations(other); + Copy::copyList(other.componentInstantiations_, componentInstantiations_); designInstantiations_->clear(); - copyDesignInstantiations(other); + Copy::copyList(other.designInstantiations_, designInstantiations_); designConfigurationInstantiations_->clear(); - copyDesignInstantiations(other); + Copy::copyList(other.designConfigurationInstantiations_, designConfigurationInstantiations_); ports_->clear(); - copyPorts(other); + Copy::copyList(other.ports_, ports_); } return *this; } -//----------------------------------------------------------------------------- -// Function: Model::~Model() -//----------------------------------------------------------------------------- -Model::~Model() -{ - views_.clear(); - componentInstantiations_.clear(); - designInstantiations_.clear(); - designConfigurationInstantiations_.clear(); - ports_.clear(); -} - //----------------------------------------------------------------------------- // Function: Model::getViews() //----------------------------------------------------------------------------- @@ -378,43 +358,3 @@ bool Model::hasContents() const return (!views_->isEmpty() || !componentInstantiations_->isEmpty() || !designInstantiations_->isEmpty() || !designConfigurationInstantiations_->isEmpty() || !ports_->isEmpty()); } - -//----------------------------------------------------------------------------- -// Function: Model::copyViews() -//----------------------------------------------------------------------------- -void Model::copyViews(Model const& other) const -{ - Copy::copyList(other.views_, views_); -} - -//----------------------------------------------------------------------------- -// Function: Model::copyComponentInstantiations() -//----------------------------------------------------------------------------- -void Model::copyComponentInstantiations(Model const& other) const -{ - Copy::copyList(other.componentInstantiations_, componentInstantiations_); -} - -//----------------------------------------------------------------------------- -// Function: Model::copyDesignInstantiations() -//----------------------------------------------------------------------------- -void Model::copyDesignInstantiations(Model const& other) const -{ - Copy::copyList(other.designInstantiations_, designInstantiations_); -} - -//----------------------------------------------------------------------------- -// Function: Model::copyDesignConfigurationInstantiations() -//----------------------------------------------------------------------------- -void Model::copyDesignConfigurationInstantiations(const Model& other) const -{ - Copy::copyList(other.designConfigurationInstantiations_, designConfigurationInstantiations_); -} - -//----------------------------------------------------------------------------- -// Function: Model::copyPorts() -//----------------------------------------------------------------------------- -void Model::copyPorts(Model const& other) const -{ - Copy::copyList(other.ports_, ports_); -} diff --git a/IPXACTmodels/Component/Model.h b/IPXACTmodels/Component/Model.h index 74a60c968..16c941f29 100644 --- a/IPXACTmodels/Component/Model.h +++ b/IPXACTmodels/Component/Model.h @@ -37,7 +37,7 @@ class IPXACTMODELS_EXPORT Model /*! * The default constructor. */ - Model(); + Model() = default; //! Copy constructor. Model(const Model &other); @@ -48,7 +48,7 @@ class IPXACTMODELS_EXPORT Model /*! * The destructor. */ - ~Model(); + ~Model() = default; /*! * Get the views of this model. @@ -247,41 +247,6 @@ class IPXACTMODELS_EXPORT Model private: - /*! - * Copy the views. - * - * @param [in] other The model being copied. - */ - void copyViews(const Model& other) const; - - /*! - * Copy the component instantiations. - * - * @param [in] other The model being copied. - */ - void copyComponentInstantiations(const Model& other) const; - - /*! - * Copy the design instantiations. - * - * @param [in] other The model being copied. - */ - void copyDesignInstantiations(const Model& other) const; - - /*! - * Copy the design configurations. - * - * @param [in] other The model being copied. - */ - void copyDesignConfigurationInstantiations(const Model& other) const; - - /*! - * Copy the ports. - * - * @param [in] other The model being copied. - */ - void copyPorts(const Model& other) const; - //! Contains the views for this model. View::List views_ = View::List(new QList >()); diff --git a/IPXACTmodels/Component/Port.cpp b/IPXACTmodels/Component/Port.cpp index 06e3a324b..058ea6212 100644 --- a/IPXACTmodels/Component/Port.cpp +++ b/IPXACTmodels/Component/Port.cpp @@ -93,6 +93,7 @@ QSharedPointer Port::getWire() const void Port::setWire(QSharedPointer newWire) { transactional_.clear(); + structured_.clear(); wire_ = newWire; } @@ -111,16 +112,36 @@ QSharedPointer Port::getTransactional() const void Port::setTransactional(QSharedPointer newTransactional) { wire_.clear(); + structured_.clear(); transactional_ = newTransactional; } +//----------------------------------------------------------------------------- +// Function: Port::getStructured() +//----------------------------------------------------------------------------- +QSharedPointer Port::getStructured() const +{ + return structured_; +} + +//----------------------------------------------------------------------------- +// Function: Port::setStructural() +//----------------------------------------------------------------------------- +void Port::setStructured(QSharedPointer newStructured) +{ + wire_.clear(); + transactional_.clear(); + + structured_ = newStructured; +} + //----------------------------------------------------------------------------- // Function: Port::getLeftBound() //----------------------------------------------------------------------------- QString Port::getLeftBound() const { - if (wire_ && wire_->getVector()) + if (wire_) { return wire_->getVectorLeftBound(); } @@ -146,7 +167,7 @@ void Port::setLeftBound(QString const& newLeftBound) //----------------------------------------------------------------------------- QString Port::getRightBound() const { - if (wire_ && wire_->getVector()) + if (wire_) { return wire_->getVectorRightBound(); } @@ -469,7 +490,7 @@ QString Port::getArrayLeft() const return QString(); } - return configurableArrays_->first()->getLeft(); + return configurableArrays_->first().getLeft(); } //----------------------------------------------------------------------------- @@ -479,19 +500,18 @@ void Port::setArrayLeft(QString const& newArrayLeft) { if (configurableArrays_->isEmpty()) { - QSharedPointer newArray (new Array(newArrayLeft, QStringLiteral("0"))); - configurableArrays_->append(newArray); + configurableArrays_->append(Array(newArrayLeft, QStringLiteral("0"))); } else { - QSharedPointer 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); } } } @@ -506,7 +526,7 @@ QString Port::getArrayRight() const return QString(); } - return configurableArrays_->first()->getRight(); + return configurableArrays_->first().getRight(); } //----------------------------------------------------------------------------- @@ -516,19 +536,18 @@ void Port::setArrayRight(QString const& newArrayRight) { if (configurableArrays_->isEmpty()) { - QSharedPointer newArray (new Array(QStringLiteral("0"), newArrayRight)); - configurableArrays_->append(newArray); + configurableArrays_->append(Array(QStringLiteral("0"), newArrayRight)); } else { - QSharedPointer 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); } } } @@ -588,7 +607,7 @@ void Port::setIsPresent(QString const& newIsPresent) //----------------------------------------------------------------------------- // Function: Port::getArrays() //----------------------------------------------------------------------------- -QSharedPointer > > Port::getArrays() const +QSharedPointer > Port::getArrays() const { return configurableArrays_; } diff --git a/IPXACTmodels/Component/Port.h b/IPXACTmodels/Component/Port.h index 24cb34f00..98cf3ae9b 100644 --- a/IPXACTmodels/Component/Port.h +++ b/IPXACTmodels/Component/Port.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -87,7 +88,21 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable * @param [in] newTransactional The new transactional element. */ void setTransactional(QSharedPointer newTransactional); - + + /*! + * Get the structured element. + * + * @return The structured element. + */ + QSharedPointer getStructured() const; + + /*! + * Set the structured element for the port. + * + * @param [in] newStructural The new structural element. + */ + void setStructured(QSharedPointer newStructured); + /*! * Get the left bound of a vectored port. * @@ -306,7 +321,7 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable * * @return Pointer to a list containing the arrays. */ - QSharedPointer > > getArrays() const; + QSharedPointer > getArrays() const; /*! * Get the wire type definitions. @@ -337,8 +352,11 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable //! Transactional port type. QSharedPointer transactional_{ nullptr }; + //! Structural port type. + QSharedPointer structured_{ nullptr }; + //! The list of arrays. - QSharedPointer > > configurableArrays_{ new QList >() }; + QSharedPointer > configurableArrays_{ new QList() }; }; Q_DECLARE_METATYPE(QSharedPointer) diff --git a/IPXACTmodels/Component/PortReader.cpp b/IPXACTmodels/Component/PortReader.cpp index afd962e9d..b3ad2c591 100644 --- a/IPXACTmodels/Component/PortReader.cpp +++ b/IPXACTmodels/Component/PortReader.cpp @@ -26,18 +26,28 @@ QSharedPointer PortReader::createPortFrom(QDomNode const& portNode, Docume newPort->setIsPresent(portNode.firstChildElement(QStringLiteral("ipxact:isPresent")).firstChild().nodeValue()); - QDomElement wireElement = portNode.firstChildElement(QStringLiteral("ipxact:wire")); - if (!wireElement.isNull()) + if (QDomElement wireElement = portNode.firstChildElement(QStringLiteral("ipxact:wire")); + !wireElement.isNull()) { - Details::parseWire(wireElement, newPort, docRevision); + newPort->setWire(Details::createWireFrom(wireElement, docRevision)); } - QDomElement transactionalElement = portNode.firstChildElement(QStringLiteral("ipxact:transactional")); - if (!transactionalElement.isNull()) + + if (QDomElement transactionalElement = portNode.firstChildElement(QStringLiteral("ipxact:transactional")); + !transactionalElement.isNull()) { Details::parseTransactional(transactionalElement, newPort); } - Details::parseArrays(portNode, newPort); + if (docRevision == Document::Revision::Std22) + { + if (QDomElement structuredElement = portNode.firstChildElement(QStringLiteral("ipxact:structured")); + !structuredElement.isNull()) + { + newPort->setStructured(Details::createStructuredFrom(structuredElement)); + } + } + + newPort->getArrays()->append(Details::createArrays(portNode)); Details::parsePortExtensions(portNode, newPort); @@ -47,7 +57,7 @@ QSharedPointer PortReader::createPortFrom(QDomNode const& portNode, Docume //----------------------------------------------------------------------------- // Function: PortReader::Details::parseWire() //----------------------------------------------------------------------------- -void PortReader::Details::parseWire(QDomElement const& wireElement, QSharedPointer newPort, +QSharedPointer PortReader::Details::createWireFrom(QDomElement const& wireElement, Document::Revision docRevision) { QDomElement directionElement = wireElement.firstChildElement(QStringLiteral("ipxact:direction")); @@ -68,7 +78,7 @@ void PortReader::Details::parseWire(QDomElement const& wireElement, QSharedPoint newWire->setAllLogicalDirectionsAllowed(true); } - parseWireVectors(wireElement.firstChildElement(QStringLiteral("ipxact:vectors")), newWire, docRevision); + parseWireVectors(wireElement, newWire, docRevision); QDomElement wireTypeDefsElement = wireElement.firstChildElement(QStringLiteral("ipxact:wireTypeDefs")); if (!wireTypeDefsElement.isNull()) @@ -79,30 +89,53 @@ void PortReader::Details::parseWire(QDomElement const& wireElement, QSharedPoint parseWireDefaultValue(wireElement, newWire); - newPort->setWire(newWire); + return newWire; } //----------------------------------------------------------------------------- // Function: PortReader::Details::parseWireVectors() //----------------------------------------------------------------------------- -void PortReader::Details::parseWireVectors(QDomElement const& vectorsElement, QSharedPointer newWire, +void PortReader::Details::parseWireVectors(QDomElement const& wireElement, QSharedPointer newWire, Document::Revision docRevision) { - QDomNodeList vectorNodeList = vectorsElement.elementsByTagName(QStringLiteral("ipxact:vector")); - for (int vectorIndex = 0; vectorIndex < vectorNodeList.count(); ++vectorIndex) + newWire->getVectors()->append(parseVectors(wireElement, docRevision)); +} + +//----------------------------------------------------------------------------- +// Function: PortReader::Details::parseVectors() +//----------------------------------------------------------------------------- +QList PortReader::Details::parseVectors(QDomElement const& parentElement, Document::Revision docRevision) +{ + auto const vectorsElement = parentElement.firstChildElement(QStringLiteral("ipxact:vectors")); + + auto const vectorNodeList = vectorsElement.elementsByTagName(QStringLiteral("ipxact:vector")); + + QList vectors; + const auto VECTOR_COUNT = vectorNodeList.size(); + for (int i = 0; i < VECTOR_COUNT; ++i) { - QDomNode vectorNode = vectorNodeList.at(vectorIndex); + vectors.append(parseVector(vectorNodeList.at(i), docRevision)); + } - newWire->setVectorLeftBound(vectorNode.firstChildElement(QStringLiteral("ipxact:left")).firstChild().nodeValue()); - newWire->setVectorRightBound(vectorNode.firstChildElement(QStringLiteral("ipxact:right")).firstChild().nodeValue()); + return vectors; +} - auto vector = newWire->getVector(); - if (docRevision == Document::Revision::Std22) - { - vector->setId(vectorNode.toElement().attribute(QStringLiteral("vectorId"))); - } +//----------------------------------------------------------------------------- +// Function: PortReader::Details::parseVector() +//----------------------------------------------------------------------------- +Vector PortReader::Details::parseVector(QDomNode const& vectorNode, Document::Revision docRevision) +{ + auto readVector = Vector(); + + readVector.setLeft(vectorNode.firstChildElement(QStringLiteral("ipxact:left")).firstChild().nodeValue()); + readVector.setRight(vectorNode.firstChildElement(QStringLiteral("ipxact:right")).firstChild().nodeValue()); + if (docRevision == Document::Revision::Std22) + { + readVector.setId(vectorNode.toElement().attribute(QStringLiteral("vectorId"))); } + + return readVector; } //----------------------------------------------------------------------------- @@ -283,43 +316,129 @@ void PortReader::Details::parseTransactionalProtocol(QDomNode const& transaction void PortReader::Details::parseTransactionalConnectionsMinMax(QDomElement const& transactionalElement, QSharedPointer transactional) { - QDomElement connectionsElement = transactionalElement.firstChildElement(QStringLiteral("ipxact:connection")); + auto const connectionsElement = transactionalElement.firstChildElement(QStringLiteral("ipxact:connection")); if (!connectionsElement.isNull()) { - QDomElement maxElement = connectionsElement.firstChildElement(QStringLiteral("ipxact:maxConnections")); - if (!maxElement.isNull()) + auto const maxElement = connectionsElement.firstChildElement(QStringLiteral("ipxact:maxConnections")); + transactional->setMaxConnections(maxElement.firstChild().nodeValue()); + + auto const minElement = connectionsElement.firstChildElement(QStringLiteral("ipxact:minConnections")); + transactional->setMinConnections(minElement.firstChild().nodeValue()); + } +} + +//----------------------------------------------------------------------------- +// Function: PortReader::Details::parseStructured() +//----------------------------------------------------------------------------- +QSharedPointer PortReader::Details::createStructuredFrom(QDomElement const& structuredElement) +{ + QSharedPointer newStructured(new Structured()); + + newStructured->setPacked(structuredElement.attribute(QStringLiteral("packed")) == QStringLiteral("true")); + + parseStructuredType(structuredElement, newStructured); + + parseStructuredVectors(structuredElement, newStructured); + + parseSubPorts(structuredElement, newStructured); + + return newStructured; +} + +//----------------------------------------------------------------------------- +// Function: PortReader::Details::parseStructuralType() +//----------------------------------------------------------------------------- +void PortReader::Details::parseStructuredType(QDomElement const& structuredElement, + QSharedPointer newStructured) +{ + using namespace DirectionTypes; + if (auto const structElement = structuredElement.firstChildElement(QStringLiteral("ipxact:struct")); + structElement.isNull() == false) + { + newStructured->setType(Structured::Type::Struct); + newStructured->setDirection(str2Direction(structElement.attribute(QStringLiteral("direction")))); + } + else if (auto const unionElement = structuredElement.firstChildElement(QStringLiteral("ipxact:union")); + unionElement.isNull() == false) + { + newStructured->setType(Structured::Type::Union); + newStructured->setDirection(str2Direction(unionElement.attribute(QStringLiteral("direction")))); + } + else if (auto const interfaceElement = structuredElement.firstChildElement(QStringLiteral("ipxact:interface")); + interfaceElement.isNull() == false) + { + newStructured->setType(Structured::Type::Interface); + if (interfaceElement.attribute(QStringLiteral("phantom")) == QStringLiteral("true")) { - QString maxConnections = maxElement.firstChild().nodeValue(); - transactional->setMaxConnections(maxConnections); + newStructured->setDirection(DIRECTION_PHANTOM); } + } +} + +//----------------------------------------------------------------------------- +// Function: PortReader::Details::parseStructuralVectors() +//----------------------------------------------------------------------------- +void PortReader::Details::parseStructuredVectors(QDomElement const& structuredElement, + QSharedPointer newStructured) +{ + newStructured->getVectors()->append(parseVectors(structuredElement, Document::Revision::Std22)); +} + +//----------------------------------------------------------------------------- +// Function: PortReader::Details::parseSubPorts() +//----------------------------------------------------------------------------- +void PortReader::Details::parseSubPorts(QDomElement const& structuredElement, QSharedPointer newStructured) +{ + const auto subPortsElement = structuredElement.firstChildElement(QStringLiteral("ipxact:subPorts")); + const auto subPortList = subPortsElement.childNodes(); - QDomElement minElement = connectionsElement.firstChildElement(QStringLiteral("ipxact:minConnections")); - if (!minElement.isNull()) + const auto SUBPORT_COUNT = subPortList.count(); + for (int i = 0; i < SUBPORT_COUNT; ++i) + { + const auto subPortElement = subPortList.at(i).toElement(); + + QSharedPointer parsedSubPort(new SubPort()); + parsedSubPort->setIsIO(subPortElement.attribute(QStringLiteral("isIO")) == QStringLiteral("true")); + NameGroupReader::parseNameGroup(subPortElement, parsedSubPort); + + if (QDomElement wireElement = subPortElement.firstChildElement(QStringLiteral("ipxact:wire")); + !wireElement.isNull()) + { + parsedSubPort->setWire(Details::createWireFrom(wireElement, Document::Revision::Std22)); + } + else if (QDomElement nestedStructured = subPortElement.firstChildElement(QStringLiteral("ipxact:structured")); + !nestedStructured.isNull()) { - QString minConnections = minElement.firstChild().nodeValue(); - transactional->setMinConnections(minConnections); + 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 newPort) +QList 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 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(new Array(arrayLeft, arrayRight))); + parsedArrays.append(Array(arrayLeft, arrayRight)); } + + return parsedArrays; } //----------------------------------------------------------------------------- @@ -329,20 +448,20 @@ void PortReader::Details::parsePortExtensions(QDomNode const& portNode, QSharedP { QDomElement extensionsNode = portNode.firstChildElement(QStringLiteral("ipxact:vendorExtensions")); - QDomElement adHocElement = extensionsNode.firstChildElement(QStringLiteral("kactus2:adHocVisible")); - if (!adHocElement.isNull()) + if (QDomElement adHocElement = extensionsNode.firstChildElement(QStringLiteral("kactus2:adHocVisible")); + !adHocElement.isNull()) { newPort->setAdHocVisible(true); } - QDomElement positionElement = extensionsNode.firstChildElement(QStringLiteral("kactus2:position")); - if (!positionElement.isNull()) + if (QDomElement positionElement = extensionsNode.firstChildElement(QStringLiteral("kactus2:position")); + !positionElement.isNull()) { parsePosition(positionElement, newPort); } - QDomElement tagsElement = extensionsNode.firstChildElement(QStringLiteral("kactus2:portTags")); - if (!tagsElement.isNull()) + if (QDomElement tagsElement = extensionsNode.firstChildElement(QStringLiteral("kactus2:portTags")); + !tagsElement.isNull()) { newPort->setPortTags(tagsElement.firstChild().nodeValue()); } diff --git a/IPXACTmodels/Component/PortReader.h b/IPXACTmodels/Component/PortReader.h index 8adce8d6a..f3df2360f 100644 --- a/IPXACTmodels/Component/PortReader.h +++ b/IPXACTmodels/Component/PortReader.h @@ -44,20 +44,40 @@ namespace PortReader * Parses a wire port. * * @param [in] wireElement XML description of the wire. - * @param [in] newPort The port containing the wire. + * @param [in] docRevision The applied IP-XACT revision. */ - void parseWire(QDomElement const& wireElement, QSharedPointer newPort, + QSharedPointer createWireFrom(QDomElement const& wireElement, Document::Revision docRevision); /*! * Parse vectors. * - * @param [in] vectorsElement XML description of the vectors. + * @param [in] wireElement XML description of the wire. * @param [in] newWire The containing wire item. */ - void parseWireVectors(QDomElement const& vectorsElement, QSharedPointer newWire, + void parseWireVectors(QDomElement const& wireElement, QSharedPointer newWire, Document::Revision docRevision); + /*! + * Parse the vectors in the given element. + * + * @param [in] parentElement The element containing vectors. + * @param [in] docRevision The applied IP-XACT revision. + * + * @return The parsed vectors. + */ + QList parseVectors(QDomElement const& parentElement, Document::Revision docRevision); + + /*! + * Parse a single vector. + * + * @param [in] vectorNode The xml presentation of the vector. + * @param [in] docRevision The applied IP-XACT revision. + * + * @return The parsed vector. + */ + Vector parseVector(QDomNode const& vectorNode, Document::Revision docRevision); + /*! * Parse the wire type definitions. * @@ -67,8 +87,8 @@ namespace PortReader * * @return Pointer to a list containing the created type definitions. */ - QSharedPointer > >parseWireTypeDefinitions - (QDomElement const& typeDefinitionsElement, QString const& elementName, QString const& attributeName); + QSharedPointer > >parseWireTypeDefinitions( + QDomElement const& typeDefinitionsElement, QString const& elementName, QString const& attributeName); /*! * Parse the type definitions. @@ -130,13 +150,47 @@ namespace PortReader void parseTransactionalConnectionsMinMax(QDomElement const& transactionalElement, QSharedPointer transactional); + /*! + * Parse a structured port. + * + * @param [in] structuredElement The XML description of the structured port. + * @param [in] newPort The containing port item. + * + * @return + */ + QSharedPointer createStructuredFrom(QDomElement const& structuredElement); + + /*! + * Parse the structured port type. + * + * @param [in] structuredElementt The XML description of the structured port. + * @param [in] newStructured The containing structured port. + */ + void parseStructuredType(QDomElement const& structuredElement, QSharedPointer newStructured); + + /*! + * Parse the vectors in the structured port. + * + * @param [in] structuredElementt The XML description of the structured port. + * @param [in] newStructured The containing structured port. + */ + void parseStructuredVectors(QDomElement const& structuredElement, QSharedPointer 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 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 newPort); + QList createArrays(QDomNode const& parentNode); /*! * Parse the port vendor extensions. @@ -156,4 +210,4 @@ namespace PortReader } }; -#endif // PORTREADER_H \ No newline at end of file +#endif // PORTREADER_H diff --git a/IPXACTmodels/Component/PortWriter.cpp b/IPXACTmodels/Component/PortWriter.cpp index c015026b7..98b464a66 100644 --- a/IPXACTmodels/Component/PortWriter.cpp +++ b/IPXACTmodels/Component/PortWriter.cpp @@ -39,6 +39,10 @@ void PortWriter::writePort(QXmlStreamWriter& writer, QSharedPointer port, { writeTransactional(writer, port->getTransactional(), docRevision); } + else if (port->getStructured() && docRevision == Document::Revision::Std22) + { + writeStructured(writer, port->getStructured()); + } writeArrays(writer, port->getArrays()); @@ -66,11 +70,8 @@ void PortWriter::writeWire(QXmlStreamWriter& writer, QSharedPointer wire, QualifierWriter::writeQualifier(writer, wire->getQualifier()); } - if (wire->getVector() && (!wire->getVector()->getLeft().isEmpty() || !wire->getVector()->getRight().isEmpty())) - { - writeVector(writer, wire->getVector(), docRevision); - } - + writeVectors(writer, wire->getVectors(), docRevision); + writeWireTypeDefinitions(writer, wire->getWireTypeDefs()); writeWireDriver(writer, wire->getDriver()); @@ -81,27 +82,32 @@ void PortWriter::writeWire(QXmlStreamWriter& writer, QSharedPointer wire, //----------------------------------------------------------------------------- // Function: PortWriter::writeVector() //----------------------------------------------------------------------------- -void PortWriter::writeVector(QXmlStreamWriter& writer, QSharedPointer vector, +void PortWriter::writeVectors(QXmlStreamWriter& writer, QSharedPointer > vectors, Document::Revision docRevision) const { - if (vector) + if (vectors->isEmpty()) { - writer.writeStartElement(QStringLiteral("ipxact:vectors")); + return; + } + + writer.writeStartElement(QStringLiteral("ipxact:vectors")); + for (auto const& vector : *vectors) + { writer.writeStartElement(QStringLiteral("ipxact:vector")); - if (docRevision == Document::Revision::Std22 && vector->getId().isEmpty() == false) + if (docRevision == Document::Revision::Std22 && vector.getId().isEmpty() == false) { - writer.writeAttribute(QStringLiteral("vectorId"), vector->getId()); + writer.writeAttribute(QStringLiteral("vectorId"), vector.getId()); } - writer.writeTextElement(QStringLiteral("ipxact:left"), vector->getLeft()); - writer.writeTextElement(QStringLiteral("ipxact:right"), vector->getRight()); + writer.writeTextElement(QStringLiteral("ipxact:left"), vector.getLeft()); + writer.writeTextElement(QStringLiteral("ipxact:right"), vector.getRight()); writer.writeEndElement(); // ipxact:vector - - writer.writeEndElement(); // ipxact:vectors } + + writer.writeEndElement(); // ipxact:vectors } //----------------------------------------------------------------------------- @@ -310,24 +316,103 @@ void PortWriter::writeTransactionalMinMaxConnections(QXmlStreamWriter& writer, } //----------------------------------------------------------------------------- -// Function: PortWriter::writeArrays() +// Function: PortWriter::writeStructured() +//----------------------------------------------------------------------------- +void PortWriter::writeStructured(QXmlStreamWriter& writer, QSharedPointer structured) const +{ + writer.writeStartElement(QStringLiteral("ipxact:structured")); + + if (structured->isPacked()) + { + writer.writeAttribute(QStringLiteral("packed"), QStringLiteral("true")); + } + + writeStructuredType(writer, structured); + + writeVectors(writer, structured->getVectors(), Document::Revision::Std22); + + writeSubPorts(writer, structured); + + writer.writeEndElement(); // ipxact:structured +} + //----------------------------------------------------------------------------- -void PortWriter::writeArrays(QXmlStreamWriter& writer, QSharedPointer > > arrays) const +// Function: PortWriter::writeStructuredType() +//----------------------------------------------------------------------------- +void PortWriter::writeStructuredType(QXmlStreamWriter& writer, QSharedPointer structured) const { - if (!arrays->isEmpty()) + writer.writeStartElement(QStringLiteral("ipxact:") + Structured::toString(structured->getType())); + if (structured->getType() == Structured::Type::Struct || structured->getType() == Structured::Type::Union) + { + writer.writeAttribute(QStringLiteral("direction"), DirectionTypes::direction2Str(structured->getDirection())); + } + else if (structured->getType() == Structured::Type::Interface && + structured->getDirection() == DirectionTypes::DIRECTION_PHANTOM) { - writer.writeStartElement(QStringLiteral("ipxact:arrays")); + writer.writeAttribute(QStringLiteral("phantom"), QStringLiteral("true")); + } + writer.writeEndElement(); // ipxact:struct/union/interface +} - for (QSharedPointer singleArray : *arrays) +//----------------------------------------------------------------------------- +// Function: PortWriter::writeSubPorts() +//----------------------------------------------------------------------------- +void PortWriter::writeSubPorts(QXmlStreamWriter& writer, QSharedPointer structured) const +{ + if (structured->getSubPorts()->isEmpty()) + { + return; + } + + writer.writeStartElement(QStringLiteral("ipxact:subPorts")); + + for (auto const& subPort : *structured->getSubPorts()) + { + writer.writeStartElement(QStringLiteral("ipxact:subPort")); + + if (subPort->isIO()) { - writer.writeStartElement(QStringLiteral("ipxact:array")); + writer.writeAttribute(QStringLiteral("isIO"), QStringLiteral("true")); + } - writer.writeTextElement(QStringLiteral("ipxact:left"), singleArray->getLeft()); - writer.writeTextElement(QStringLiteral("ipxact:right"), singleArray->getRight()); + NameGroupWriter::writeNameGroup(writer, subPort, Document::Revision::Std22); - writer.writeEndElement(); // ipxact:array + if (subPort->isWire()) + { + writeWire(writer, subPort->getWire(), Document::Revision::Std22); + } + else if (subPort->isStructured()) + { + writeStructured(writer, subPort->getStructured()); } - writer.writeEndElement(); // ipxact:arrays + writer.writeEndElement(); // ipxact:subPort } + + writer.writeEndElement(); // ipxact:subPorts +} + +//----------------------------------------------------------------------------- +// Function: PortWriter::writeArrays() +//----------------------------------------------------------------------------- +void PortWriter::writeArrays(QXmlStreamWriter& writer, QSharedPointer > arrays) const +{ + if (arrays->isEmpty()) + { + return; + } + + writer.writeStartElement(QStringLiteral("ipxact:arrays")); + + for (auto const& singleArray : *arrays) + { + writer.writeStartElement(QStringLiteral("ipxact:array")); + + writer.writeTextElement(QStringLiteral("ipxact:left"), singleArray.getLeft()); + writer.writeTextElement(QStringLiteral("ipxact:right"), singleArray.getRight()); + + writer.writeEndElement(); // ipxact:array + } + + writer.writeEndElement(); // ipxact:arrays } diff --git a/IPXACTmodels/Component/PortWriter.h b/IPXACTmodels/Component/PortWriter.h index c7da68ee1..bb661e25f 100644 --- a/IPXACTmodels/Component/PortWriter.h +++ b/IPXACTmodels/Component/PortWriter.h @@ -57,14 +57,6 @@ class IPXACTMODELS_EXPORT PortWriter void writeTransactional(QXmlStreamWriter& writer, QSharedPointer transactional, Document::Revision docRevision) const; - /*! - * Write the port arrays. - * - * @param [in] writer Used XML writer. - * @param [in] arrays The arrays to be written. - */ - void writeArrays(QXmlStreamWriter& writer, QSharedPointer > > arrays) const; - /*! * Write a vector. * @@ -72,7 +64,8 @@ class IPXACTMODELS_EXPORT PortWriter * @param [in] vector The vector to be written. * @param [in] docRevision The applied IP-XACT standard revision. */ - void writeVector(QXmlStreamWriter& writer, QSharedPointer vector, Document::Revision docRevision) const; + void writeVectors(QXmlStreamWriter& writer, QSharedPointer > vectors, + Document::Revision docRevision) const; /*! * Write the wire type definitions. @@ -143,6 +136,39 @@ class IPXACTMODELS_EXPORT PortWriter */ void writeTransactionalMinMaxConnections(QXmlStreamWriter& writer, QSharedPointer transactional) const; + + /*! + * Write the structural port. + * + * @param [in] writer The used XML writer. + * @param [in] structured The structured port description to write. + */ + void writeStructured(QXmlStreamWriter& writer, QSharedPointer structured) const; + + /*! + * Write the type of the structural port. + * + * @param [in] writer The used XML writer. + * @param [in] structured The structured port whose type to write. + */ + void writeStructuredType(QXmlStreamWriter& writer, QSharedPointer structured) const; + + /*! + * Write the sub-ports in a structural port. + * + * @param [in] writer The used XML writer. + * @param [in] structured The structured port whose sub-ports to write. + */ + void writeSubPorts(QXmlStreamWriter& writer, QSharedPointer structured) const; + + /*! + * Write the port arrays. + * + * @param [in] writer Used XML writer. + * @param [in] arrays The arrays to be written. + */ + void writeArrays(QXmlStreamWriter& writer, QSharedPointer > arrays) const; + }; #endif // INSTANTIATIONSWRITER_H \ No newline at end of file diff --git a/IPXACTmodels/Component/Structured.cpp b/IPXACTmodels/Component/Structured.cpp new file mode 100644 index 000000000..830bf596d --- /dev/null +++ b/IPXACTmodels/Component/Structured.cpp @@ -0,0 +1,33 @@ +//----------------------------------------------------------------------------- +// File: Structured.cpp +//----------------------------------------------------------------------------- +// Project: Kactus2 +// Author: Esko Pekkarinen +// Date: 20.11.2023 +// +// Description: +// Implementation of ipxact:structured in component port. +//----------------------------------------------------------------------------- + +#include "Structured.h" + +//----------------------------------------------------------------------------- +// Function: Structural::toString() +//----------------------------------------------------------------------------- +QString Structured::toString(Type type) +{ + if (type == Type::Struct) + { + return QStringLiteral("struct"); + } + else if (type == Type::Union) + { + return QStringLiteral("union"); + } + else if (type == Type::Interface) + { + return QStringLiteral("interface"); + } + + return QString(); +} diff --git a/IPXACTmodels/Component/Structured.h b/IPXACTmodels/Component/Structured.h new file mode 100644 index 000000000..f85e300be --- /dev/null +++ b/IPXACTmodels/Component/Structured.h @@ -0,0 +1,118 @@ +//----------------------------------------------------------------------------- +// File: Structured.h +//----------------------------------------------------------------------------- +// Project: Kactus2 +// Author: Esko Pekkarinen +// Date: 20.11.2023 +// +// Description: +// Implementation of ipxact:structured in component port. +//----------------------------------------------------------------------------- + +#ifndef STRUCTURED_H +#define STRUCTURED_H + +#include +#include + +#include "SubPort.h" + +#include + +//----------------------------------------------------------------------------- +//! Implementation of ipxact:structured in component port. +//----------------------------------------------------------------------------- +class IPXACTMODELS_EXPORT Structured +{ +public: + + enum class Type + { + Struct, + Union, + Interface, + Undefined + }; + + /*! + * Set the structured port as packed. + * + * @param [in] packed Packed or not. + */ + constexpr void setPacked(bool packed) noexcept { packed_ = packed; } + + /*! + * Check if the structured port can be packed. + * + * @return True, if the port can be packed, otherwise false. + */ + [[nodiscard]] bool isPacked() const noexcept { return packed_; } + + /*! + * Set the port type. + * + * @param [in] type The type to set. + */ + constexpr void setType(Type type) noexcept { portType_ = type; } + + /*! + * Get the port type. + * + * @return The port type. + */ + [[nodiscard]] constexpr Type getType() const noexcept { return portType_; } + + /*! + * Set the direction of this port. + * + * @param [in] direction The new direction. + */ + constexpr void setDirection(DirectionTypes::Direction direction) noexcept { direction_ = direction; } + + /*! + * Get the direction of the port. + * + * @return Enum direction specifying the port direction. + */ + [[nodiscard]] constexpr DirectionTypes::Direction getDirection() const noexcept { return direction_; } + + /*! + * Get the vectors in the structured port. + * + * @return The vectors in the port. + */ + [[nodiscard]] QSharedPointer > 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: + + //! Port is mappable to packed bit sequence. + bool packed_{ true }; + + //! The type of this port. + Type portType_{ Type::Undefined }; + + //! The direction of the port. + DirectionTypes::Direction direction_{ DirectionTypes::DIRECTION_INVALID }; + + //! The vectors of the port. + QSharedPointer > vectors_{ new QList() }; + + //! The sub-ports of the structural port. + SubPort::List subPorts_{ new QList >() }; +}; + +#endif // STRUCTURED_H \ No newline at end of file diff --git a/IPXACTmodels/Component/SubPort.cpp b/IPXACTmodels/Component/SubPort.cpp new file mode 100644 index 000000000..56583130c --- /dev/null +++ b/IPXACTmodels/Component/SubPort.cpp @@ -0,0 +1,30 @@ +//----------------------------------------------------------------------------- +// File: SubPort.cpp +//----------------------------------------------------------------------------- +// Project: Kactus2 +// Author: Esko Pekkarinen +// Date: 21.11.2023 +// +// Description: +// Implementation of ipxact:SubPort in component port. +//----------------------------------------------------------------------------- + +#include "SubPort.h" + +//----------------------------------------------------------------------------- +// Function: SubPort::setWire() +//----------------------------------------------------------------------------- +void SubPort::setWire(QSharedPointer wire) +{ + structured_.clear(); + wire_ = wire; +} + +//----------------------------------------------------------------------------- +// Function: SubPort::setStructured() +//----------------------------------------------------------------------------- +void SubPort::setStructured(QSharedPointer structured) +{ + wire_.clear(); + structured_ = structured; +} diff --git a/IPXACTmodels/Component/SubPort.h b/IPXACTmodels/Component/SubPort.h new file mode 100644 index 000000000..dfe258ef3 --- /dev/null +++ b/IPXACTmodels/Component/SubPort.h @@ -0,0 +1,105 @@ +//----------------------------------------------------------------------------- +// File: SubPort.h +//----------------------------------------------------------------------------- +// Project: Kactus2 +// Author: Esko Pekkarinen +// Date: 21.11.2023 +// +// Description: +// Implementation of ipxact:subPort in component port. +//----------------------------------------------------------------------------- + +#ifndef SUBPORT_H +#define SUBPORT_H + +#include +#include + +#include + +class Structured; +class Wire; + +//----------------------------------------------------------------------------- +//! Implementation of ipxact:SubPort in component port. +//----------------------------------------------------------------------------- +class IPXACTMODELS_EXPORT SubPort : public NameGroup +{ +public: + + using List = QSharedPointer > >; + + /*! + * Set for input, inout or output ports in an interface. + * + * @param [in] isIO Wheter the port is an input, inout or output. + */ + void setIsIO(bool isIO) noexcept { isIO_ = isIO; } + + /*! + * Check if the port is an input, output or inout. + * + * @return True, if the port is input, output or inout, otherwise false. + */ + [[nodiscard]] bool isIO() const noexcept { return isIO_; } + + /*! + * Check if the sub-port has a wire definition. + * + * @return True, if the sub-port has a wire, otherwise false. + */ + [[nodiscard]] bool isWire() const noexcept { return wire_.isNull() == false; } + + /*! + * Set the wire port in the sub-port. + * + * @param [in] wire The wire to set. + */ + void setWire(QSharedPointer wire); + + /*! + * Get the wire port in the sub-port. + * + * @return The wire port, if available, otherwise nullptr. + */ + [[nodiscard]] QSharedPointer getWire() const { return wire_; } + + /*! + * Check if the sub-port has a structured definition. + * + * @return True, if the sub-port has a structured, otherwise false. + */ + [[nodiscard]] bool isStructured() const noexcept { return structured_.isNull() == false; } + + /*! + * Set the structured port in the sub-port. + * + * @param [in] structured The structured port to set. + */ + void setStructured(QSharedPointer structured); + + /*! + * Get the structured port in the sub-port. + * + * @return The structured port, if available, otherwise nullptr. + */ + [[nodiscard]] QSharedPointer getStructured() const { return structured_; } + + [[nodiscard]] QSharedPointer > getArrays() const { return arrays_; } + +private: + + //! The sub-port wire port. + QSharedPointer wire_{ nullptr }; + + //! The nested structured port. + QSharedPointer structured_{ nullptr }; + + //! The sub-port arrays. + QSharedPointer > arrays_{ new QList() }; + + //! Is the sub-port input, output or inout in an interface. + bool isIO_; +}; + +#endif // SUBPORT_H \ No newline at end of file diff --git a/IPXACTmodels/Component/Wire.cpp b/IPXACTmodels/Component/Wire.cpp index f289e96ca..c44e75eba 100644 --- a/IPXACTmodels/Component/Wire.cpp +++ b/IPXACTmodels/Component/Wire.cpp @@ -28,10 +28,7 @@ direction_(other.direction_), allLogicalDirectionsAllowed_(other.allLogicalDirectionsAllowed_), qualifier_(other.qualifier_->clone()) { - if (other.vector_) - { - vector_ = QSharedPointer(other.vector_->clone()); - } + Copy::copyList(other.vectors_, vectors_); Copy::copyList(other.wireTypeDefs_, wireTypeDefs_); @@ -52,11 +49,8 @@ Wire& Wire::operator=( const Wire &other ) allLogicalDirectionsAllowed_ = other.allLogicalDirectionsAllowed_; qualifier_ = QSharedPointer(other.qualifier_->clone()); - vector_.clear(); - if (other.vector_) - { - vector_ = QSharedPointer(other.vector_->clone()); - } + vectors_->clear(); + Copy:: copyList(other.vectors_, vectors_); wireTypeDefs_->clear(); Copy::copyList(other.wireTypeDefs_, wireTypeDefs_); @@ -95,27 +89,19 @@ QSharedPointer Wire::getQualifier() const } //----------------------------------------------------------------------------- -// Function: Wire::getWireTypeDefs() +// Function: Wire::getVectors() //----------------------------------------------------------------------------- -QSharedPointer > > Wire::getWireTypeDefs() const +QSharedPointer > Wire::getVectors() const { - return wireTypeDefs_; + return vectors_; } //----------------------------------------------------------------------------- -// Function: Wire::getVector() -//----------------------------------------------------------------------------- -QSharedPointer Wire::getVector() const -{ - return vector_; -} - -//----------------------------------------------------------------------------- -// Function: Wire::setVector() +// Function: Wire::getWireTypeDefs() //----------------------------------------------------------------------------- -void Wire::setVector(QSharedPointer newVector) +QSharedPointer > > Wire::getWireTypeDefs() const { - vector_ = newVector; + return wireTypeDefs_; } //----------------------------------------------------------------------------- @@ -181,12 +167,12 @@ QString Wire::getDefaultDriverValue() const //----------------------------------------------------------------------------- void Wire::setVectorLeftBound(QString const& expression) { - if (!vector_) + if (vectors_->isEmpty()) { - vector_ = QSharedPointer(new Vector(QStringLiteral("0"), QStringLiteral("0"))); + vectors_->append(Vector(QStringLiteral("0"), QStringLiteral("0"))); } - vector_->setLeft(expression); + vectors_->first().setLeft(expression); } //----------------------------------------------------------------------------- @@ -194,12 +180,12 @@ void Wire::setVectorLeftBound(QString const& expression) //----------------------------------------------------------------------------- void Wire::setVectorRightBound(QString const& expression) { - if (!vector_) + if (vectors_->isEmpty()) { - vector_ = QSharedPointer(new Vector(QStringLiteral("0"), QStringLiteral("0"))); + vectors_->append(Vector(QStringLiteral("0"), QStringLiteral("0"))); } - vector_->setRight(expression); + vectors_->first().setRight(expression); } //----------------------------------------------------------------------------- @@ -207,12 +193,12 @@ void Wire::setVectorRightBound(QString const& expression) //----------------------------------------------------------------------------- QString Wire::getVectorLeftBound() const { - if (!vector_) + if (vectors_->isEmpty()) { return QString(); } - return vector_->getLeft(); + return vectors_->first().getLeft(); } //----------------------------------------------------------------------------- @@ -220,12 +206,12 @@ QString Wire::getVectorLeftBound() const //----------------------------------------------------------------------------- QString Wire::getVectorRightBound() const { - if (!vector_) + if (vectors_->isEmpty()) { return QString(); } - return vector_->getRight(); + return vectors_->first().getRight(); } //----------------------------------------------------------------------------- diff --git a/IPXACTmodels/Component/Wire.h b/IPXACTmodels/Component/Wire.h index a3b5e6878..6ca698d73 100644 --- a/IPXACTmodels/Component/Wire.h +++ b/IPXACTmodels/Component/Wire.h @@ -74,14 +74,19 @@ class IPXACTMODELS_EXPORT Wire */ DirectionTypes::Direction getDirection() const; + /*! + * Get the qualifier of the port. + * + * @return The wire port qualifier. + */ QSharedPointer getQualifier() const; - /*! - * Get the vector element of this port. + /*! + * Get the vectors element of this port. * - * @return Pointer to a vector element. + * @return The vectors of the wire. */ - QSharedPointer getVector() const; + QSharedPointer > getVectors() const; /*! * Get the list of this port's wire type definitions. @@ -104,13 +109,6 @@ class IPXACTMODELS_EXPORT Wire */ void setDirection(DirectionTypes::Direction direction); - /*! - * Set the vector element for this port. - * - * @param [in] newVector The new vector element. - */ - void setVector(QSharedPointer newVector); - /*! * Set the wire type definitions. * @@ -233,8 +231,7 @@ class IPXACTMODELS_EXPORT Wire QSharedPointer qualifier_{ new Qualifier }; //! Determines the vector qualities of the port. - //! Multiple vectors not supported. - QSharedPointer vector_{ nullptr }; + QSharedPointer > vectors_{ new QList() }; //! Specifies a driver for this port. //! Multiple drivers not supported. 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) const bool PortValidator::hasValidArrays(QSharedPointer port) const { // Any arrays must have valid left and right. - for ( QSharedPointer 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& errors, QSharedPointer } // Any arrays must have valid left and right. - for ( QSharedPointer 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/IPXACTmodels/IPXACTmodels.pri b/IPXACTmodels/IPXACTmodels.pri index 75413e81d..5d583486e 100644 --- a/IPXACTmodels/IPXACTmodels.pri +++ b/IPXACTmodels/IPXACTmodels.pri @@ -2,7 +2,6 @@ # This file is generated by the Qt Visual Studio Tools. # ------------------------------------------------------ - HEADERS += ./generaldeclarations.h \ ./ipxactmodels_global.h \ ./kactusExtensions/ApiDefinition.h \ @@ -304,7 +303,9 @@ HEADERS += ./generaldeclarations.h \ ./DesignConfiguration/ViewConfiguration.h \ ./DesignConfiguration/validators/DesignConfigurationValidator.h \ ./DesignConfiguration/validators/InterconnectionConfigurationValidator.h \ - ./DesignConfiguration/validators/ViewConfigurationValidator.h + ./DesignConfiguration/validators/ViewConfigurationValidator.h \ + ./Component/Structured.h \ + ./Component/SubPort.h SOURCES += ./generaldeclarations.cpp \ ./kactusExtensions/ApiDefinition.cpp \ ./kactusExtensions/ApiDefinitionReader.cpp \ @@ -601,4 +602,6 @@ SOURCES += ./generaldeclarations.cpp \ ./DesignConfiguration/ViewConfiguration.cpp \ ./DesignConfiguration/validators/DesignConfigurationValidator.cpp \ ./DesignConfiguration/validators/InterconnectionConfigurationValidator.cpp \ - ./DesignConfiguration/validators/ViewConfigurationValidator.cpp + ./DesignConfiguration/validators/ViewConfigurationValidator.cpp \ + ./Component/Structured.cpp \ + ./Component/SubPort.cpp diff --git a/IPXACTmodels/IPXACTmodels.pro b/IPXACTmodels/IPXACTmodels.pro index b0b2a178e..f8215781a 100644 --- a/IPXACTmodels/IPXACTmodels.pro +++ b/IPXACTmodels/IPXACTmodels.pro @@ -6,7 +6,7 @@ TEMPLATE = lib TARGET = IPXACTmodels QT += core xml gui -CONFIG += c++11 release dll +CONFIG += c++17 release dll DEFINES += IPXACTMODELS_LIB QT_NO_CAST_FROM_ASCII INCLUDEPATH += ./GeneratedFiles \ diff --git a/IPXACTmodels/IPXACTmodels.vcxproj b/IPXACTmodels/IPXACTmodels.vcxproj index 91d239a8f..7229dddbf 100644 --- a/IPXACTmodels/IPXACTmodels.vcxproj +++ b/IPXACTmodels/IPXACTmodels.vcxproj @@ -305,6 +305,8 @@ + + @@ -462,6 +464,8 @@ + + diff --git a/IPXACTmodels/IPXACTmodels.vcxproj.filters b/IPXACTmodels/IPXACTmodels.vcxproj.filters index 307918601..34578582d 100644 --- a/IPXACTmodels/IPXACTmodels.vcxproj.filters +++ b/IPXACTmodels/IPXACTmodels.vcxproj.filters @@ -1022,6 +1022,12 @@ Source Files\common\validators + + Source Files\Component + + + Source Files\Component + @@ -1768,6 +1774,12 @@ Header Files\common\validators + + Header Files\Component + + + Header Files\Component + diff --git a/IPXACTmodels/common/ClockUnit.cpp b/IPXACTmodels/common/ClockUnit.cpp index 1cda2fa58..5492df02c 100644 --- a/IPXACTmodels/common/ClockUnit.cpp +++ b/IPXACTmodels/common/ClockUnit.cpp @@ -15,40 +15,7 @@ // Function: ClockUnit::ClockUnit() //----------------------------------------------------------------------------- ClockUnit::ClockUnit(QString const& value) : -value_(value), -timeUnit_(TIMEUNIT_UNSPECIFIED) -{ - -} - -//----------------------------------------------------------------------------- -// Function: ClockUnit::ClockUnit() -//----------------------------------------------------------------------------- -ClockUnit::ClockUnit(const ClockUnit& other) : -value_(other.value_), -timeUnit_(other.timeUnit_) -{ - -} - -//----------------------------------------------------------------------------- -// Function: ClockUnit::operator=() -//----------------------------------------------------------------------------- -ClockUnit& ClockUnit::operator=(const ClockUnit& other) -{ - if (this != &other) - { - value_ = other.value_; - timeUnit_ = other.timeUnit_; - } - - return *this; -} - -//----------------------------------------------------------------------------- -// Function: ClockUnit::~ClockUnit() -//----------------------------------------------------------------------------- -ClockUnit::~ClockUnit() +value_(value) { } diff --git a/IPXACTmodels/common/ClockUnit.h b/IPXACTmodels/common/ClockUnit.h index 79d255673..eb0f048be 100644 --- a/IPXACTmodels/common/ClockUnit.h +++ b/IPXACTmodels/common/ClockUnit.h @@ -36,16 +36,7 @@ class IPXACTMODELS_EXPORT ClockUnit * * @param [in] value The contained value. */ - ClockUnit(QString const& value = QString()); - - //! Copy constructor. - ClockUnit(const ClockUnit& other); - - //! Assignment operator. - ClockUnit& operator=(const ClockUnit& other); - - //! The destructor. - ~ClockUnit(); + explicit ClockUnit(QString const& value = QString()); /*! * Get the assigned value. @@ -95,7 +86,7 @@ class IPXACTMODELS_EXPORT ClockUnit QString value_; //! The used time unit. - TimeUnit timeUnit_; + TimeUnit timeUnit_{ TIMEUNIT_UNSPECIFIED }; }; #endif // CLOCKUNIT_H diff --git a/IPXACTmodels/common/Range.h b/IPXACTmodels/common/Range.h index 30fc7971f..2ffcd8f23 100644 --- a/IPXACTmodels/common/Range.h +++ b/IPXACTmodels/common/Range.h @@ -23,6 +23,8 @@ class IPXACTMODELS_EXPORT Range { public: + Range() = default; + //! The constructor. Range(QString const& left, QString const& right); diff --git a/IPXACTmodels/common/Vector.h b/IPXACTmodels/common/Vector.h index 6be85a494..11c83c8d4 100644 --- a/IPXACTmodels/common/Vector.h +++ b/IPXACTmodels/common/Vector.h @@ -25,6 +25,11 @@ class IPXACTMODELS_EXPORT Vector : public Range { public: + /*! + * The constructor. + */ + Vector() = default; + /*! * The constructor. * @@ -34,7 +39,7 @@ class IPXACTMODELS_EXPORT Vector : public Range Vector(QString const& left, QString const& right); //! The destructor. - ~Vector() final = default; + ~Vector() = default; /*! * Create a copy of the Vector. diff --git a/IPXACTmodels/utilities/Copy.h b/IPXACTmodels/utilities/Copy.h index 40d77824a..cfd0ddf8a 100644 --- a/IPXACTmodels/utilities/Copy.h +++ b/IPXACTmodels/utilities/Copy.h @@ -35,6 +35,18 @@ namespace Copy }; + template + void copyList(QSharedPointer > from, QSharedPointer > to) + { + if (from.isNull() || to.isNull()) + { + return; + } + + std::for_each(from->cbegin(), from->cend(), [&to](auto const& item) + { to->append(Item(item)); }); + + }; }; //----------------------------------------------------------------------------- diff --git a/KactusAPI/interfaces/component/PortsInterface.cpp b/KactusAPI/interfaces/component/PortsInterface.cpp index da9b46815..99d5edc5b 100644 --- a/KactusAPI/interfaces/component/PortsInterface.cpp +++ b/KactusAPI/interfaces/component/PortsInterface.cpp @@ -431,10 +431,9 @@ std::string PortsInterface::getLeftBoundValue(std::string const& portName, unsig if (QSharedPointer editedPort = getPort(portName); portIsWire(editedPort)) { - QSharedPointer wireVector = editedPort->getWire()->getVector(); - if (wireVector) + if (editedPort->getWire()->getVectors()->isEmpty() == false) { - return parseExpressionToBaseNumber(wireVector->getLeft(), baseNumber).toStdString(); + return parseExpressionToBaseNumber(editedPort->getWire()->getVectorLeftBound(), baseNumber).toStdString(); } } @@ -449,10 +448,9 @@ std::string PortsInterface::getLeftBoundFormattedExpression(std::string const& p if (QSharedPointer editedPort = getPort(portName); portIsWire(editedPort)) { - QSharedPointer wireVector = editedPort->getWire()->getVector(); - if (wireVector) + if (editedPort->getWire()->getVectors()->isEmpty() == false) { - return formattedValueFor(wireVector->getLeft()).toStdString(); + return formattedValueFor(editedPort->getWire()->getVectorLeftBound()).toStdString(); } } @@ -467,10 +465,9 @@ std::string PortsInterface::getLeftBoundExpression(std::string const& portName) if (QSharedPointer editedPort = getPort(portName); portIsWire(editedPort)) { - QSharedPointer wireVector = editedPort->getWire()->getVector(); - if (wireVector) + if (editedPort->getWire()->getVectors()->isEmpty() == false) { - return wireVector->getLeft().toStdString(); + return editedPort->getWire()->getVectorLeftBound().toStdString(); } } @@ -502,10 +499,9 @@ std::string PortsInterface::getRightBoundValue(std::string const& portName, unsi if (QSharedPointer editedPort = getPort(portName); portIsWire(editedPort)) { - QSharedPointer wireVector = editedPort->getWire()->getVector(); - if (wireVector) + if (editedPort->getWire()->getVectors()->isEmpty() == false) { - return parseExpressionToBaseNumber(wireVector->getRight(), baseNumber).toStdString(); + return parseExpressionToBaseNumber(editedPort->getWire()->getVectorRightBound(), baseNumber).toStdString(); } } @@ -520,10 +516,9 @@ std::string PortsInterface::getRightBoundFormattedExpression(std::string const& if (QSharedPointer editedPort = getPort(portName); portIsWire(editedPort)) { - QSharedPointer wireVector = editedPort->getWire()->getVector(); - if (wireVector) + if (editedPort->getWire()->getVectors()->isEmpty() == false) { - return formattedValueFor(wireVector->getRight()).toStdString(); + return formattedValueFor(editedPort->getWire()->getVectorRightBound()).toStdString(); } } @@ -538,10 +533,9 @@ std::string PortsInterface::getRightBoundExpression(std::string const& portName) if (QSharedPointer editedPort = getPort(portName); portIsWire(editedPort)) { - QSharedPointer wireVector = editedPort->getWire()->getVector(); - if (wireVector) + if (editedPort->getWire()->getVectors()->isEmpty() == false) { - return wireVector->getRight().toStdString(); + return editedPort->getWire()->getVectorRightBound().toStdString(); } } diff --git a/editors/ComponentEditor/memoryMaps/memorymapseditor.cpp b/editors/ComponentEditor/memoryMaps/memorymapseditor.cpp index ce367f6ee..079446ef0 100644 --- a/editors/ComponentEditor/memoryMaps/memorymapseditor.cpp +++ b/editors/ComponentEditor/memoryMaps/memorymapseditor.cpp @@ -39,11 +39,14 @@ MemoryMapsEditor::MemoryMapsEditor(MemoryMapInterface* mapInterface, QSharedPoin ItemEditor(component, handler, parent), view_(new MemoryMapsView(this)), proxy_(new EditableTreeSortFilter(this)), -model_(new MemoryMapsModel(parameterFinder, expressionParser, mapInterface, component->getRevision(), this)), +model_(new MemoryMapsModel(parameterFinder, expressionParser, mapInterface, component->getRevision(), + fontMetrics().height() + 8, this)), delegate_(), interface_(mapInterface), component_(component) { + view_->setUniformRowHeights(true); + mapInterface->setMemoryMaps(component); // display a label on top the table diff --git a/editors/ComponentEditor/memoryMaps/memorymapsmodel.cpp b/editors/ComponentEditor/memoryMaps/memorymapsmodel.cpp index 4027cced2..733419056 100644 --- a/editors/ComponentEditor/memoryMaps/memorymapsmodel.cpp +++ b/editors/ComponentEditor/memoryMaps/memorymapsmodel.cpp @@ -37,12 +37,13 @@ // Function: memorymapsmodel::MemoryMapsModel() //----------------------------------------------------------------------------- MemoryMapsModel::MemoryMapsModel(QSharedPointer parameterFinder, - QSharedPointer expressionParser, MemoryMapInterface* mapInterface, - Document::Revision docRevision, QObject *parent) : + QSharedPointer expressionParser, MemoryMapInterface* mapInterface, + Document::Revision docRevision, const int ROWHEIGHT, QObject *parent): QAbstractItemModel(parent), ParameterizableTable(parameterFinder), mapInterface_(mapInterface), -docRevision_(docRevision) +docRevision_(docRevision), +ROWHEIGHT_(ROWHEIGHT) { setExpressionParser(expressionParser); } @@ -257,6 +258,10 @@ QVariant MemoryMapsModel::data(QModelIndex const& index, int role) const return KactusColors::REGULAR_FIELD; } } + else if (index.column() == MemoryMapsColumns::NAME_COLUMN && role == Qt::SizeHintRole) + { + return QSize(40, ROWHEIGHT_); + } return QVariant(); } diff --git a/editors/ComponentEditor/memoryMaps/memorymapsmodel.h b/editors/ComponentEditor/memoryMaps/memorymapsmodel.h index 72869e92b..8f683ecfa 100644 --- a/editors/ComponentEditor/memoryMaps/memorymapsmodel.h +++ b/editors/ComponentEditor/memoryMaps/memorymapsmodel.h @@ -50,11 +50,12 @@ class MemoryMapsModel : public QAbstractItemModel, public ParameterizableTable * @param [in] expressionParser The used expression parser. * @param [in] mapInterface Interface for memory maps. * @param [in] docRevision The IP-XACT standard revision to use. + * @param [in] ROWHEIGHT Height for rows. * @param [in] parent The owner of the model. */ MemoryMapsModel( QSharedPointer parameterFinder, QSharedPointer expressionParser, MemoryMapInterface* mapInterface, - Document::Revision docRevision, QObject *parent); + Document::Revision docRevision, const int ROWHEIGHT, QObject *parent); //! No copying MemoryMapsModel(const MemoryMapsModel& other) = delete; @@ -370,6 +371,9 @@ public slots: //! The IP-XACT standard revision to use. Document::Revision docRevision_; + + //! Height for rows. + const int ROWHEIGHT_; }; #endif // MEMORYMAPSMODEL_H diff --git a/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp b/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp index 4e64c8104..b7951a73e 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp +++ b/tests/IPXACTmodels/Component/tst_ComponentPortReader.cpp @@ -10,6 +10,7 @@ //----------------------------------------------------------------------------- #include +#include #include @@ -46,6 +47,13 @@ private slots: void readTransactionalProtocol(); void readTransactionalTypeDefinitions(); void readTransactionalConnectionMinMax(); + + void readStrucuredType_2022(); + void readStrucuredType_2022_data(); + void readStructuredVectors_2022(); + void readStructuredSubPortWire_2022(); + void readNestedStructuredSubPort_2022(); + void readSubPortArrays_2022(); }; //----------------------------------------------------------------------------- @@ -362,6 +370,10 @@ void tst_ComponentPortReader::readWirePortVectors() "4+18-Yaoxao" "Yaoxao" "" + "" + "1" + "0" + "" "" "" "" @@ -379,9 +391,12 @@ void tst_ComponentPortReader::readWirePortVectors() QCOMPARE(testPort->getTransactional().isNull(), true); QCOMPARE(testPort->getWire().isNull(), false); - QCOMPARE(testPort->getWire()->getVectorLeftBound(), QStringLiteral("4+18-Yaoxao")); - QCOMPARE(testPort->getWire()->getVectorRightBound(), QStringLiteral("Yaoxao")); - QCOMPARE(testPort->getWire()->getVector()->getId(), QString()); + QCOMPARE(testPort->getWire()->getVectors()->count(), 2); + + auto const& vector = testPort->getWire()->getVectors()->first(); + QCOMPARE(vector.getLeft(), QStringLiteral("4+18-Yaoxao")); + QCOMPARE(vector.getRight(), QStringLiteral("Yaoxao")); + QCOMPARE(vector.getId(), QString()); } //----------------------------------------------------------------------------- @@ -416,9 +431,11 @@ void tst_ComponentPortReader::readWirePortVectors_2022() QCOMPARE(testPort->getTransactional().isNull(), true); QCOMPARE(testPort->getWire().isNull(), false); - QCOMPARE(testPort->getWire()->getVector()->getLeft(), QStringLiteral("1")); - QCOMPARE(testPort->getWire()->getVector()->getRight(), QStringLiteral("0")); - QCOMPARE(testPort->getWire()->getVector()->getId(), QStringLiteral("testVector")); + + auto const& vector = testPort->getWire()->getVectors()->first(); + QCOMPARE(vector.getLeft(), QStringLiteral("1")); + QCOMPARE(vector.getRight(), QStringLiteral("0")); + QCOMPARE(vector.getId(), QStringLiteral("testVector")); } //----------------------------------------------------------------------------- @@ -844,6 +861,283 @@ void tst_ComponentPortReader::readTransactionalConnectionMinMax() QCOMPARE(testPort->getTransactional()->getMinConnections(), QString("8*2")); } +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortReader::readStrucuredType_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortReader::readStrucuredType_2022() +{ + QFETCH(QString, content); + QFETCH(Structured::Type, expectedType); + QFETCH(DirectionTypes::Direction, expectedDirection); + + QString documentContent( + "" + "testPort" + "" + + content + + "" + "" + ); + + QDomDocument document; + document.setContent(documentContent); + + QDomNode portNode = document.firstChildElement("ipxact:port"); + + QSharedPointer testPort = PortReader::createPortFrom(portNode, Document::Revision::Std22); + + QCOMPARE(testPort->name(), QString("testPort")); + QCOMPARE(testPort->getWire().isNull(), true); + QCOMPARE(testPort->getTransactional().isNull(), true); + QCOMPARE(testPort->getStructured().isNull(), false); + + auto structured = testPort->getStructured(); + QCOMPARE(structured->isPacked(), false); + QCOMPARE(structured->getType(), expectedType); + QCOMPARE(structured->getDirection(), expectedDirection); +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortReader::readStrucuredType_2022_data() +//----------------------------------------------------------------------------- +void tst_ComponentPortReader::readStrucuredType_2022_data() +{ + QTest::addColumn("content"); + QTest::addColumn("expectedType"); + QTest::addColumn("expectedDirection"); + + QTest::addRow("Struct without direction") << + "" << Structured::Type::Struct << DirectionTypes::DIRECTION_INVALID; + QTest::addRow("Struct with in direction") << + "" << Structured::Type::Struct << DirectionTypes::IN; + + QTest::addRow("Union without direction") << + "" << Structured::Type::Union << DirectionTypes::DIRECTION_INVALID; + QTest::addRow("Union with out direction") << + "" << Structured::Type::Union << DirectionTypes::OUT; + + QTest::addRow("Interface without phantom attribute") << + "" << Structured::Type::Interface << DirectionTypes::DIRECTION_INVALID; + QTest::addRow("Interface with true phantom attribute") << + "" << Structured::Type::Interface << DirectionTypes::DIRECTION_PHANTOM; + QTest::addRow("Interface with false phantom attribute") << + "" << Structured::Type::Interface << DirectionTypes::DIRECTION_INVALID; +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortReader::readStructuredVectors_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortReader::readStructuredVectors_2022() +{ + QString documentContent( + "" + "testPort" + "" + "" + "" + "1" + "0" + "" + "" + "2" + "0" + "" + "" + "" + "" + ); + + QDomDocument document; + document.setContent(documentContent); + + QDomNode portNode = document.firstChildElement("ipxact:port"); + + QSharedPointer testPort = PortReader::createPortFrom(portNode, Document::Revision::Std22); + + QCOMPARE(testPort->getStructured().isNull(), false); + + auto structured = testPort->getStructured(); + QCOMPARE(structured->isPacked(), true); + QCOMPARE(structured->getVectors()->count(), 2); + + auto const& lastVector = structured->getVectors()->last(); + QCOMPARE(lastVector.getLeft(), "2"); + QCOMPARE(lastVector.getRight(), "0"); +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortReader::readStructuredSubPortWire_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortReader::readStructuredSubPortWire_2022() +{ + QString documentContent( + "" + "testPort" + "" + "" + "" + "" + "minimalWire" + "" + "in" + "" + "" + "" + "" + "" + ); + + QDomDocument document; + document.setContent(documentContent); + + QDomNode portNode = document.firstChildElement("ipxact:port"); + + QSharedPointer 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->isIO(), true); + QCOMPARE(subPort->name(), QString("minimalWire")); + + QCOMPARE(subPort->getWire().isNull(), false); + QCOMPARE(subPort->getWire()->getDirection(), DirectionTypes::IN); +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortReader::readNestedStructuredSubPort_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortReader::readNestedStructuredSubPort_2022() +{ + QString documentContent( + "" + "testPort" + "" + "" + "" + "" + "firstLayer" + "" + "" + "" + "" + "middleLayer" + "" + "" + "" + "" + "wireLayer" + "" + "in" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ); + + QDomDocument document; + document.setContent(documentContent); + + QDomNode portNode = document.firstChildElement("ipxact:port"); + + QSharedPointer testPort = PortReader::createPortFrom(portNode, Document::Revision::Std22); + + QCOMPARE(testPort->getStructured().isNull(), false); + + auto structured = testPort->getStructured(); + QCOMPARE(structured->getSubPorts()->count(), 1); + + auto const& firstSubPort = structured->getSubPorts()->first(); + QCOMPARE(firstSubPort->name(), "firstLayer"); + QCOMPARE(firstSubPort->getWire().isNull(), true); + QCOMPARE(firstSubPort->getStructured().isNull(), false); + QCOMPARE(firstSubPort->getStructured()->getSubPorts()->count(), 1); + + auto const& middleSubPort = firstSubPort->getStructured()->getSubPorts()->first(); + QCOMPARE(middleSubPort->name(), "middleLayer"); + QCOMPARE(middleSubPort->getWire().isNull(), true); + QCOMPARE(middleSubPort->getStructured().isNull(), false); + QCOMPARE(middleSubPort->getStructured()->getSubPorts()->count(), 1); + + auto const& finalSubPort = middleSubPort->getStructured()->getSubPorts()->first(); + QCOMPARE(finalSubPort->name(), QString("wireLayer")); + QCOMPARE(finalSubPort->getStructured().isNull(), true); + QCOMPARE(finalSubPort->getWire().isNull(), false); + + auto const& wire = finalSubPort->getWire(); + QCOMPARE(wire->getDirection(), DirectionTypes::IN); +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortReader::readSubPortArrays_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortReader::readSubPortArrays_2022() +{ + + QString documentContent( + "" + "testPort" + "" + "" + "" + "" + "arrays" + "" + "in" + "" + "" + "" + "0" + "0" + "" + "" + "1" + "0" + "" + "" + "" + "" + "" + "" + ); + + QDomDocument document; + document.setContent(documentContent); + + QDomNode portNode = document.firstChildElement("ipxact:port"); + + QSharedPointer 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/tests/IPXACTmodels/Component/tst_ComponentPortReader.pro b/tests/IPXACTmodels/Component/tst_ComponentPortReader.pro index 69629e5f1..0300262fb 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentPortReader.pro +++ b/tests/IPXACTmodels/Component/tst_ComponentPortReader.pro @@ -16,7 +16,7 @@ TARGET = tst_ComponentPortReader QT += core xml testlib QT -= gui -CONFIG += c++11 testcase console +CONFIG += c++17 testcase console linux-g++ | linux-g++-64 | linux-g++-32 { LIBS += -L../../../executable \ @@ -24,7 +24,7 @@ linux-g++ | linux-g++-64 | linux-g++-32 { } win64 | win32 { - LIBS += -L../../../x64/executable \ + LIBS += -L../../../executable \ -lIPXACTmodelsd } diff --git a/tests/IPXACTmodels/Component/tst_ComponentPortValidator.cpp b/tests/IPXACTmodels/Component/tst_ComponentPortValidator.cpp index 59c36e163..dc56cafbc 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentPortValidator.cpp +++ b/tests/IPXACTmodels/Component/tst_ComponentPortValidator.cpp @@ -9,7 +9,7 @@ // Unit test for class ComponentPortValidator. //----------------------------------------------------------------------------- -#include +#include #include diff --git a/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pri b/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pri index 26c713c23..80d0069f9 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pri +++ b/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pri @@ -2,7 +2,4 @@ # This file is generated by the Qt Visual Studio Tools. # ------------------------------------------------------ -HEADERS += ../../../editors/ComponentEditor/common/SystemVerilogExpressionParser.h - -SOURCES += ../../../editors/ComponentEditor/common/SystemVerilogExpressionParser.cpp \ - ./tst_ComponentPortValidator.cpp \ No newline at end of file +SOURCES += ./tst_ComponentPortValidator.cpp \ No newline at end of file diff --git a/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pro b/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pro index 39902e6bf..2f6cffc8e 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pro +++ b/tests/IPXACTmodels/Component/tst_ComponentPortValidator.pro @@ -15,16 +15,16 @@ TARGET = tst_ComponentPortValidator QT += core gui xml testlib -CONFIG += c++11 testcase console +CONFIG += c++17 testcase console linux-g++ | linux-g++-64 | linux-g++-32 { LIBS += -L../../../executable \ - -lIPXACTmodels + -lIPXACTmodels -lKactusAPI } win64 | win32 { - LIBS += -L../../../x64/executable \ - -lIPXACTmodelsd + LIBS += -L../../../executable \ + -lIPXACTmodelsd -lKactusAPId } INCLUDEPATH += $$DESTDIR diff --git a/tests/IPXACTmodels/Component/tst_ComponentPortWriter.cpp b/tests/IPXACTmodels/Component/tst_ComponentPortWriter.cpp index 713281766..3507d4f84 100755 --- a/tests/IPXACTmodels/Component/tst_ComponentPortWriter.cpp +++ b/tests/IPXACTmodels/Component/tst_ComponentPortWriter.cpp @@ -37,7 +37,6 @@ private slots: void writeWirePortAllLogicalDirectionsAllowed(); void writeWirePortVectors(); void writeWirePortVectors_2022(); - void emptyVectorIsNotWritten(); void writeWireTypeDefinitions(); void emptyWireTypeDefinitionIsNotWritten(); void writeWireDefaultDriver(); @@ -50,6 +49,11 @@ private slots: void writeTransactionalProtocol(); void writeTransactionalTypeDefinitions(); void writeTransactionalConnectionMinMax(); + + void writeStructuredType_2022(); + void writeStructuredType_2022_data(); + void writeStructuredVectors_2022(); + void writeStructuredWirePort_2022(); }; //----------------------------------------------------------------------------- @@ -380,7 +384,7 @@ void tst_ComponentPortWriter::writeWirePortVectors_2022() testPort->setDirection(DirectionTypes::OUT); testPort->getWire()->setVectorLeftBound("4+18-Yaoxao"); testPort->getWire()->setVectorRightBound("Yaoxao"); - testPort->getWire()->getVector()->setId("testID"); + testPort->getWire()->getVectors()->first().setId("testID"); QString expectedOutput( "" @@ -402,33 +406,6 @@ void tst_ComponentPortWriter::writeWirePortVectors_2022() QCOMPARE(output, expectedOutput); } -//----------------------------------------------------------------------------- -// Function: tst_ComponentPortWriter::emptyVectorIsNotWritten() -//----------------------------------------------------------------------------- -void tst_ComponentPortWriter::emptyVectorIsNotWritten() -{ - QString output; - QXmlStreamWriter xmlStreamWriter(&output); - - QSharedPointer testPort(new Port("testPort")); - testPort->setDirection(DirectionTypes::OUT); - testPort->getWire()->setVectorLeftBound(""); - testPort->getWire()->setVectorRightBound(""); - - QString expectedOutput( - "" - "testPort" - "" - "out" - "" - "" - ); - - PortWriter portWriter; - portWriter.writePort(xmlStreamWriter, testPort, Document::Revision::Std14); - QCOMPARE(output, expectedOutput); -} - //----------------------------------------------------------------------------- // Function: tst_ComponentPortWriter::writeWireTypeDefinitions() //----------------------------------------------------------------------------- @@ -905,6 +882,161 @@ void tst_ComponentPortWriter::writeTransactionalConnectionMinMax() QCOMPARE(output, expectedOutput); } +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortWriter::writeStructuredType_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortWriter::writeStructuredType_2022() +{ + QFETCH(Structured::Type, type); + QFETCH(DirectionTypes::Direction, direction); + QFETCH(QString, expectedType); + + QString output; + QXmlStreamWriter xmlStreamWriter(&output); + + QSharedPointer testStructured(new Structured()); + testStructured->setPacked(true); + testStructured->setType(type); + testStructured->setDirection(direction); + + QSharedPointer testPort(new Port("testPort")); + testPort->setStructured(testStructured); + + QString expectedOutput( + "" + "testPort" + "" + + expectedType + + "" + "" + ); + + PortWriter portWriter; + portWriter.writePort(xmlStreamWriter, testPort, Document::Revision::Std22); + QCOMPARE(output, expectedOutput); +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortWriter::writeStructuredType_2022_data() +//----------------------------------------------------------------------------- +void tst_ComponentPortWriter::writeStructuredType_2022_data() +{ + QTest::addColumn("type"); + QTest::addColumn("direction"); + QTest::addColumn("expectedType"); + + QTest::addRow("Struct with out direction") << Structured::Type::Struct << DirectionTypes::OUT << + ""; + QTest::addRow("Struct with inout direction") << Structured::Type::Struct << DirectionTypes::INOUT << + ""; + QTest::addRow("Struct with in direction") << Structured::Type::Struct << DirectionTypes::IN << + ""; + QTest::addRow("Struct with phantom direction") << Structured::Type::Struct << + DirectionTypes::DIRECTION_PHANTOM << + ""; + QTest::addRow("Struct with invalid direction") << Structured::Type::Struct << + DirectionTypes::DIRECTION_INVALID << + ""; + + QTest::addRow("Union with in direction") << Structured::Type::Union << DirectionTypes::IN << + ""; + + QTest::addRow("Interface with phantom direction") << + Structured::Type::Interface << DirectionTypes::DIRECTION_PHANTOM << + ""; + + QTest::addRow("Interface with invalid direction") << Structured::Type::Interface << DirectionTypes::IN << + ""; +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortWriter::writeStructuredVectors_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortWriter::writeStructuredVectors_2022() +{ + QString output; + QXmlStreamWriter xmlStreamWriter(&output); + + QSharedPointer testStructured(new Structured()); + testStructured->setPacked(true); + testStructured->setType(Structured::Type::Union); + testStructured->setDirection(DirectionTypes::OUT); + + testStructured->getVectors()->append(Vector("1", "0")); + testStructured->getVectors()->append(Vector("2", "0")); + + QSharedPointer testPort(new Port("testPort")); + testPort->setStructured(testStructured); + + QString expectedOutput( + "" + "testPort" + "" + "" + "" + "" + "1" + "0" + "" + "" + "2" + "0" + "" + "" + "" + "" + ); + + PortWriter portWriter; + portWriter.writePort(xmlStreamWriter, testPort, Document::Revision::Std22); + QCOMPARE(output, expectedOutput); +} + +//----------------------------------------------------------------------------- +// Function: tst_ComponentPortWriter::writeStructuredWirePort_2022() +//----------------------------------------------------------------------------- +void tst_ComponentPortWriter::writeStructuredWirePort_2022() +{ + QString output; + QXmlStreamWriter xmlStreamWriter(&output); + + QSharedPointer testStructured(new Structured()); + testStructured->setType(Structured::Type::Interface); + testStructured->setPacked(false); + + QSharedPointer testPort(new Port("testPort")); + testPort->setStructured(testStructured); + + QSharedPointer wireSubPort(new SubPort()); + wireSubPort->setName("simpleWire"); + + QSharedPointer testWire(new Wire); + testWire->setDirection(DirectionTypes::IN); + wireSubPort->setWire(testWire); + testStructured->getSubPorts()->append(wireSubPort); + + QString expectedOutput( + "" + "testPort" + "" + "" + "" + "" + "simpleWire" + "" + "in" + "" + "" + "" + "" + "" + ); + + PortWriter portWriter; + portWriter.writePort(xmlStreamWriter, testPort, Document::Revision::Std22); + QCOMPARE(output, expectedOutput); +} + QTEST_APPLESS_MAIN(tst_ComponentPortWriter) #include "tst_ComponentPortWriter.moc" diff --git a/tests/IPXACTmodels/Component/tst_ComponentPortWriter.pro b/tests/IPXACTmodels/Component/tst_ComponentPortWriter.pro index 53a939019..0bb2d7c8d 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentPortWriter.pro +++ b/tests/IPXACTmodels/Component/tst_ComponentPortWriter.pro @@ -16,7 +16,7 @@ TARGET = tst_ComponentPortWriter QT += core xml testlib QT -= gui -CONFIG += c++11 testcase console +CONFIG += c++17 testcase console linux-g++ | linux-g++-64 | linux-g++-32 { LIBS += -L../../../executable \ @@ -24,7 +24,7 @@ linux-g++ | linux-g++-64 | linux-g++-32 { } win64 | win32 { - LIBS += -L../../../x64/executable \ + LIBS += -L../../../executable \ -lIPXACTmodelsd } diff --git a/version.h b/version.h index adb1934f5..fd9a468a1 100644 --- a/version.h +++ b/version.h @@ -10,20 +10,20 @@ #ifndef VERSIONNO__H #define VERSIONNO__H -#define VERSION_FULL 3.12.1018.0 +#define VERSION_FULL 3.12.1049.0 #define VERSION_BASEYEAR 0 -#define VERSION_DATE "2023-11-21" -#define VERSION_TIME "12:24:57" +#define VERSION_DATE "2023-11-22" +#define VERSION_TIME "13:55:07" #define VERSION_MAJOR 3 #define VERSION_MINOR 12 -#define VERSION_BUILDNO 1018 +#define VERSION_BUILDNO 1049 #define VERSION_EXTEND 0 -#define VERSION_FILE 3,12,1018,0 -#define VERSION_PRODUCT 3,12,1018,0 -#define VERSION_FILESTR "3,12,1018,0" -#define VERSION_PRODUCTSTR "3,12,1018,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