Skip to content

Commit

Permalink
[CLEANUP] Clean IPXACT port-related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
epekkar committed Nov 6, 2023
1 parent 8a19d64 commit a7ad0aa
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 538 deletions.
117 changes: 35 additions & 82 deletions IPXACTmodels/Component/Port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
//-----------------------------------------------------------------------------
Port::Port(QString const& portName) :
NameGroup(portName),
Extendable(),
isPresent_(),
wire_(),
transactional_(),
configurableArrays_(new QList<QSharedPointer<Array> > ())
Extendable()
{

}
Expand All @@ -37,10 +33,7 @@ configurableArrays_(new QList<QSharedPointer<Array> > ())
Port::Port(const Port &other):
NameGroup(other),
Extendable(other),
isPresent_(other.isPresent_),
wire_(),
transactional_(),
configurableArrays_(new QList<QSharedPointer<Array> > ())
isPresent_(other.isPresent_)
{
if (other.wire_)
{
Expand Down Expand Up @@ -68,7 +61,7 @@ Port & Port::operator=( const Port &other )

if (other.wire_)
{
wire_ = QSharedPointer<Wire>(new Wire(*other.wire_.data()));
wire_ = QSharedPointer<Wire>(new Wire(*other.wire_));
}
else
{
Expand All @@ -77,7 +70,7 @@ Port & Port::operator=( const Port &other )

if (other.transactional_)
{
transactional_ = QSharedPointer<Transactional>(new Transactional(*other.transactional_.data()));
transactional_ = QSharedPointer<Transactional>(new Transactional(*other.transactional_));
}
else
{
Expand All @@ -90,16 +83,6 @@ Port & Port::operator=( const Port &other )
return *this;
}

//-----------------------------------------------------------------------------
// Function: Port::~Port()
//-----------------------------------------------------------------------------
Port::~Port()
{
wire_.clear();
transactional_.clear();
configurableArrays_.clear();
}

//-----------------------------------------------------------------------------
// Function: Port::getWire()
//-----------------------------------------------------------------------------
Expand All @@ -113,18 +96,12 @@ QSharedPointer<Wire> Port::getWire() const
//-----------------------------------------------------------------------------
void Port::setWire(QSharedPointer<Wire> newWire)
{
if (wire_)
{
wire_.clear();
}

if (transactional_)
{
transactional_.clear();
}

// change the port type
wire_ = QSharedPointer<Wire>(newWire);
wire_ = newWire;
}

//-----------------------------------------------------------------------------
Expand All @@ -145,25 +122,17 @@ void Port::setTransactional(QSharedPointer<Transactional> newTransactional)
wire_.clear();
}

if (transactional_)
{
transactional_.clear();
}

transactional_ = QSharedPointer<Transactional>(newTransactional);
transactional_ = newTransactional;
}

//-----------------------------------------------------------------------------
// Function: Port::getLeftBound()
//-----------------------------------------------------------------------------
QString Port::getLeftBound() const
{
if (wire_)
if (wire_ && wire_->getVector())
{
if (wire_->getVector())
{
return wire_->getVectorLeftBound();
}
return wire_->getVectorLeftBound();
}

return QStringLiteral("0");
Expand All @@ -174,28 +143,22 @@ QString Port::getLeftBound() const
//-----------------------------------------------------------------------------
void Port::setLeftBound(QString const& newLeftBound)
{
if (wire_)
{
wire_->setVectorLeftBound(newLeftBound);
}
else
if (wire_.isNull())
{
wire_ = QSharedPointer<Wire>(new Wire());
wire_->setVectorLeftBound(newLeftBound);
}

wire_->setVectorLeftBound(newLeftBound);
}

//-----------------------------------------------------------------------------
// Function: Port::getRightBound()
//-----------------------------------------------------------------------------
QString Port::getRightBound() const
{
if (wire_)
if (wire_ && wire_->getVector())
{
if (wire_->getVector())
{
return wire_->getVectorRightBound();
}
return wire_->getVectorRightBound();
}

return QStringLiteral("0");
Expand All @@ -206,15 +169,12 @@ QString Port::getRightBound() const
//-----------------------------------------------------------------------------
void Port::setRightBound(QString const& newRightBound)
{
if (wire_)
{
wire_->setVectorRightBound(newRightBound);
}
else
if (wire_.isNull())
{
wire_ = QSharedPointer<Wire>(new Wire());
wire_->setVectorRightBound(newRightBound);
}

wire_->setVectorRightBound(newRightBound);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -322,7 +282,7 @@ void Port::setAllLogicalDirectionsAllowed( bool allowed )
//-----------------------------------------------------------------------------
// Function: Port::getTypeName()
//-----------------------------------------------------------------------------
QString Port::getTypeName( const QString& viewName /*= QString("")*/ ) const
QString Port::getTypeName( const QString& viewName ) const
{
if (wire_)
{
Expand All @@ -341,7 +301,7 @@ QString Port::getTypeName( const QString& viewName /*= QString("")*/ ) const
//-----------------------------------------------------------------------------
// Function: Port::setTypeName()
//-----------------------------------------------------------------------------
void Port::setTypeName( const QString& typeName, const QString& viewName /*= QString("")*/ )
void Port::setTypeName( const QString& typeName, const QString& viewName )
{
if (wire_)
{
Expand All @@ -361,7 +321,7 @@ void Port::setTypeName( const QString& typeName, const QString& viewName /*= QSt
//-----------------------------------------------------------------------------
// Function: Port::hasType()
//-----------------------------------------------------------------------------
bool Port::hasType( const QString& viewName /*= QString("")*/ ) const
bool Port::hasType( const QString& viewName ) const
{
if (wire_)
{
Expand All @@ -378,7 +338,7 @@ bool Port::hasType( const QString& viewName /*= QString("")*/ ) const
//-----------------------------------------------------------------------------
// Function: Port::getTypeDefinition()
//-----------------------------------------------------------------------------
QString Port::getTypeDefinition( const QString& typeName )
QString Port::getTypeDefinition( const QString& typeName ) const
{
if (wire_)
{
Expand Down Expand Up @@ -457,25 +417,18 @@ bool Port::hasTypeDefinitions() const
//-----------------------------------------------------------------------------
bool Port::isAdHocVisible() const
{
foreach (QSharedPointer<VendorExtension> extension, *getVendorExtensions())
{
if (extension->type() == QLatin1String("kactus2:adHocVisible"))
{
return true;
}
}

return false;
return std::any_of(getVendorExtensions()->cbegin(), getVendorExtensions()->cend(),
[](auto const& extension) { return extension->type() == QStringLiteral("kactus2:adHocVisible"); });
}

//-----------------------------------------------------------------------------
// Function: Port::setAdHocVisible()
//-----------------------------------------------------------------------------
void Port::setAdHocVisible(bool visible)
{
foreach (QSharedPointer<VendorExtension> extension, *getVendorExtensions())
for (QSharedPointer<VendorExtension> extension : *getVendorExtensions())
{
if (extension->type() == QLatin1String("kactus2:adHocVisible"))
if (extension->type() == QStringLiteral("kactus2:adHocVisible"))
{
if (!visible)
{
Expand All @@ -498,7 +451,7 @@ void Port::setAdHocVisible(bool visible)
//-----------------------------------------------------------------------------
QPointF Port::getDefaultPos() const
{
foreach (QSharedPointer<VendorExtension> extension, *getVendorExtensions())
for (QSharedPointer<VendorExtension> extension : *getVendorExtensions())
{
if (extension->type() == QLatin1String("kactus2:position"))
{
Expand All @@ -515,7 +468,7 @@ QPointF Port::getDefaultPos() const
//-----------------------------------------------------------------------------
void Port::setDefaultPos(QPointF const& pos)
{
foreach (QSharedPointer<VendorExtension> extension, *getVendorExtensions())
for (QSharedPointer<VendorExtension> extension : *getVendorExtensions())
{
if (extension->type() == QLatin1String("kactus2:position"))
{
Expand Down Expand Up @@ -610,9 +563,9 @@ void Port::setArrayRight(QString const& newArrayRight)
//-----------------------------------------------------------------------------
// Function: port::getPortTags()
//-----------------------------------------------------------------------------
const QString Port::getPortTags() const
QString Port::getPortTags() const
{
foreach (QSharedPointer<VendorExtension> extension, *getVendorExtensions())
for (QSharedPointer<VendorExtension> extension : *getVendorExtensions())
{
if (extension->type() == QLatin1String("kactus2:portTags"))
{
Expand All @@ -629,7 +582,7 @@ const QString Port::getPortTags() const
//-----------------------------------------------------------------------------
void Port::setPortTags(const QString& newPortTags)
{
foreach (QSharedPointer<VendorExtension> extension, *getVendorExtensions())
for (QSharedPointer<VendorExtension> extension : *getVendorExtensions())
{
if (extension->type() == QLatin1String("kactus2:portTags"))
{
Expand Down Expand Up @@ -679,7 +632,7 @@ QSharedPointer<QList<QSharedPointer<Array> > > Port::getArrays() const
//-----------------------------------------------------------------------------
void Port::copyArrays(const Port& other)
{
foreach (QSharedPointer<Array> configurableArray, *other.configurableArrays_)
for (QSharedPointer<Array> configurableArray : *other.configurableArrays_)
{
if (configurableArray)
{
Expand All @@ -697,14 +650,14 @@ void Port::copyArrays(const Port& other)
//-----------------------------------------------------------------------------
QSharedPointer<QList<QSharedPointer<WireTypeDef> > > Port::getTypes() const
{
if (getWire())
if (wire_)
{
return getWire()->getWireTypeDefs();
return wire_->getWireTypeDefs();
}
else if (getTransactional())
else if (wire_)
{
return getTransactional()->getTransTypeDef();
return transactional_->getTransTypeDef();
}

return QSharedPointer<QList<QSharedPointer<WireTypeDef> > >();
return nullptr;
}
18 changes: 9 additions & 9 deletions IPXACTmodels/Component/Port.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable
*
* @param [in] portName Name of the port.
*/
Port(QString const& portName = QString());
explicit Port(QString const& portName = QString());

/*!
* Copy constructor.
Expand All @@ -58,7 +58,7 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable
/*!
* The destructor.
*/
~Port();
~Port() = default;

/*!
* Get a pointer to the wire element.
Expand Down Expand Up @@ -172,15 +172,15 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable
*
* @return The matching type name.
*/
QString getTypeName(const QString& viewName = QLatin1String("")) const;
QString getTypeName(const QString& viewName = QString()) const;

/*!
* Set the type name for the port in given view.
*
* @param [in] typeName The name of the type.
* @param [in] viewName The name of the view used for this type.
*/
void setTypeName(const QString& typeName, const QString& viewName = QLatin1String(""));
void setTypeName(const QString& typeName, const QString& viewName = QString());

/*!
* Check if the port has a type name in given view.
Expand All @@ -197,7 +197,7 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable
* @param [in] typeName The name of the type that's type definition is wanted.
* @return The found type definition.
*/
QString getTypeDefinition(const QString& typeName);
QString getTypeDefinition(const QString& typeName) const;

/*!
* Get the type definitions of the wired port.
Expand Down Expand Up @@ -278,7 +278,7 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable
*
* @return Tags associated with the port.
*/
const QString getPortTags() const;
QString getPortTags() const;

/*!
* Set the port tags.
Expand Down Expand Up @@ -332,13 +332,13 @@ class IPXACTMODELS_EXPORT Port : public NameGroup, public Extendable
QString isPresent_;

//! The wire port type.
QSharedPointer<Wire> wire_;
QSharedPointer<Wire> wire_{ nullptr };

//! Transactional port type.
QSharedPointer<Transactional> transactional_;
QSharedPointer<Transactional> transactional_{ nullptr };

//! The list of arrays.
QSharedPointer<QList<QSharedPointer<Array> > > configurableArrays_;
QSharedPointer<QList<QSharedPointer<Array> > > configurableArrays_{ new QList<QSharedPointer<Array> >() };
};

Q_DECLARE_METATYPE(QSharedPointer<Port>)
Expand Down
4 changes: 1 addition & 3 deletions IPXACTmodels/Component/PortReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ void PortReader::parseArrays(QDomNode const& portNode, QSharedPointer<Port> newP
QString arrayLeft = arrayNode.firstChildElement(QStringLiteral("ipxact:left")).firstChild().nodeValue();
QString arrayRight = arrayNode.firstChildElement(QStringLiteral("ipxact:right")).firstChild().nodeValue();

QSharedPointer<Array> newArray (new Array(arrayLeft, arrayRight));

newPort->getArrays()->append(newArray);
newPort->getArrays()->append(QSharedPointer<Array>(new Array(arrayLeft, arrayRight)));
}
}

Expand Down
Loading

0 comments on commit a7ad0aa

Please sign in to comment.