-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADDITIVE] Boilerplate for field access policy editor. Also add acces…
…s policy base class.
- Loading branch information
Showing
54 changed files
with
1,446 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//----------------------------------------------------------------------------- | ||
// File: AccessPolicy.cpp | ||
//----------------------------------------------------------------------------- | ||
// Project: Kactus 2 | ||
// Author: Anton Hagqvist | ||
// Date: 8.8.2023 | ||
// | ||
// Description: | ||
// Describes the ipxact:accessPolicy element. | ||
//----------------------------------------------------------------------------- | ||
|
||
#include "AccessPolicy.h" | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicy::AccessPolicy() | ||
//----------------------------------------------------------------------------- | ||
AccessPolicy::AccessPolicy(): | ||
Extendable() | ||
{ | ||
|
||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicy::AccessPolicy() | ||
//----------------------------------------------------------------------------- | ||
AccessPolicy::AccessPolicy(AccessPolicy const& other) : | ||
Extendable(other), | ||
modeReferences_(new QList<QSharedPointer<ModeReference> >()), | ||
access_(other.access_) | ||
{ | ||
for (auto const& modeRef : *other.modeReferences_) | ||
{ | ||
if (modeRef) | ||
{ | ||
auto copy = QSharedPointer<ModeReference>(new ModeReference(*modeRef)); | ||
modeReferences_->append(copy); | ||
} | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicy::getModeReferences() | ||
//----------------------------------------------------------------------------- | ||
QSharedPointer<QList<QSharedPointer<ModeReference> > > AccessPolicy::getModeReferences() const | ||
{ | ||
return modeReferences_; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicy::setModeReferences() | ||
//----------------------------------------------------------------------------- | ||
void AccessPolicy::setModeReferences(QSharedPointer<QList<QSharedPointer<ModeReference> > > modeRefs) | ||
{ | ||
modeReferences_ = modeRefs; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicy::getAccess() | ||
//----------------------------------------------------------------------------- | ||
AccessTypes::Access AccessPolicy::getAccess() const | ||
{ | ||
return access_; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicy::setAccess() | ||
//----------------------------------------------------------------------------- | ||
void AccessPolicy::setAccess(AccessTypes::Access newAccess) | ||
{ | ||
access_ = newAccess; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//----------------------------------------------------------------------------- | ||
// File: AccessPolicy.h | ||
//----------------------------------------------------------------------------- | ||
// Project: Kactus 2 | ||
// Author: Anton Hagqvist | ||
// Date: 8.8.2023 | ||
// | ||
// Description: | ||
// Describes the ipxact:accessPolicy element. | ||
//----------------------------------------------------------------------------- | ||
|
||
#ifndef ACCESSPOLICY_H | ||
#define ACCESSPOLICY_H | ||
|
||
#include "ModeReference.h" | ||
|
||
#include <IPXACTmodels/ipxactmodels_global.h> | ||
#include <IPXACTmodels/generaldeclarations.h> | ||
|
||
#include <IPXACTmodels/common/AccessTypes.h> | ||
#include <IPXACTmodels/common/Extendable.h> | ||
|
||
class IPXACTMODELS_EXPORT AccessPolicy : public Extendable | ||
{ | ||
public: | ||
|
||
AccessPolicy(); | ||
|
||
AccessPolicy(AccessPolicy const& other); | ||
|
||
virtual ~AccessPolicy() = default; | ||
|
||
/*! | ||
* Get the mode references of the field access policy. | ||
* | ||
* @return A pointer to the list of mode references. | ||
*/ | ||
QSharedPointer<QList<QSharedPointer<ModeReference> > > getModeReferences() const; | ||
|
||
/*! | ||
* Set the mode references of the field access policy. | ||
* | ||
* @param [in] modeRefs The mode references to set. | ||
*/ | ||
void setModeReferences(QSharedPointer<QList<QSharedPointer<ModeReference> > > modeRefs); | ||
|
||
/*! | ||
* Get the field access policy access value. | ||
* | ||
* @return The access value. | ||
*/ | ||
AccessTypes::Access getAccess() const; | ||
|
||
/*! | ||
* Set the access value. | ||
* | ||
* @param [in] newAccess The new access value. | ||
*/ | ||
void setAccess(AccessTypes::Access newAccess); | ||
|
||
private: | ||
|
||
//! The operating modes for which this field access policy is active. | ||
QSharedPointer<QList<QSharedPointer<ModeReference> > > modeReferences_ = | ||
QSharedPointer<QList<QSharedPointer<ModeReference> > >(new QList<QSharedPointer<ModeReference> >()); | ||
|
||
//! Contains the access type of the field. | ||
AccessTypes::Access access_ = AccessTypes::ACCESS_COUNT; | ||
|
||
}; | ||
|
||
#endif // ACCESSPOLICY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//----------------------------------------------------------------------------- | ||
// File: AccessPolicyReader.cpp | ||
//----------------------------------------------------------------------------- | ||
// Project: Kactus 2 | ||
// Author: Anton Hagqvist | ||
// Date: 8.8.2023 | ||
// | ||
// Description: | ||
// Reader for ipxact:accessPolicy. | ||
//----------------------------------------------------------------------------- | ||
|
||
#include "AccessPolicyReader.h" | ||
|
||
#include <IPXACTmodels/common/CommonItemsReader.h> | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicyReader::createAccessPolicyFrom() | ||
//----------------------------------------------------------------------------- | ||
QSharedPointer<AccessPolicy> AccessPolicyReader::createAccessPolicyFrom(QDomNode const& accessPolicyNode) | ||
{ | ||
QSharedPointer<AccessPolicy> accessPolicy(new AccessPolicy()); | ||
|
||
Details::parseModeRefs(accessPolicyNode, accessPolicy->getModeReferences()); | ||
|
||
Details::parseAccess(accessPolicyNode, accessPolicy); | ||
|
||
CommonItemsReader::parseVendorExtensions(accessPolicyNode, accessPolicy); | ||
|
||
return accessPolicy; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicyReader::Details::parseModeRefs() | ||
//----------------------------------------------------------------------------- | ||
void AccessPolicyReader::Details::parseModeRefs(QDomNode const& rootNode, | ||
QSharedPointer<QList<QSharedPointer<ModeReference> > > modeRefList) | ||
{ | ||
auto modeRefNodes = rootNode.childNodes(); | ||
|
||
for (int i = 0; i < modeRefNodes.size(); ++i) | ||
{ | ||
if (auto const& modeRefNode = modeRefNodes.at(i); | ||
modeRefNode.nodeName() == QStringLiteral("ipxact:modeRef")) | ||
{ | ||
QSharedPointer<ModeReference> newModeRef(new ModeReference()); | ||
|
||
newModeRef->setReference(modeRefNode.firstChild().nodeValue()); | ||
|
||
if (auto const& priority = modeRefNode.attributes().namedItem(QStringLiteral("priority")).nodeValue(); | ||
!priority.isEmpty()) | ||
{ | ||
newModeRef->setPriority(priority); | ||
} | ||
|
||
modeRefList->append(newModeRef); | ||
} | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicyReader::Details::parseAccess() | ||
//----------------------------------------------------------------------------- | ||
void AccessPolicyReader::Details::parseAccess(QDomNode const& accessPolicyNode, | ||
QSharedPointer<AccessPolicy> accessPolicy) | ||
{ | ||
auto accessElement = accessPolicyNode.firstChildElement(QStringLiteral("ipxact:access")); | ||
if (!accessElement.isNull()) | ||
{ | ||
auto accessString = accessElement.firstChild().nodeValue(); | ||
AccessTypes::Access access = AccessTypes::str2Access(accessString, AccessTypes::ACCESS_COUNT); | ||
accessPolicy->setAccess(access); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//----------------------------------------------------------------------------- | ||
// File: AccessPolicyReader.h | ||
//----------------------------------------------------------------------------- | ||
// Project: Kactus 2 | ||
// Author: Anton Hagqvist | ||
// Date: 8.8.2023 | ||
// | ||
// Description: | ||
// Reader for ipxact:accessPolicy. | ||
//----------------------------------------------------------------------------- | ||
|
||
#ifndef ACCESSPOLICYREADER_H | ||
#define ACCESSPOLICYREADER_H | ||
|
||
#include "AccessPolicy.h" | ||
|
||
#include <IPXACTmodels/ipxactmodels_global.h> | ||
|
||
#include <QDomNode> | ||
|
||
namespace AccessPolicyReader | ||
{ | ||
|
||
/*! | ||
* Create a field access policy from XML description. | ||
* | ||
* @param [in] accessPolicyNode The XML description of the access policy. | ||
* | ||
* @return The created field access policy. | ||
*/ | ||
IPXACTMODELS_EXPORT QSharedPointer<AccessPolicy> createAccessPolicyFrom(QDomNode const& accessPolicyNode); | ||
|
||
namespace Details | ||
{ | ||
/*! | ||
* Read mode references. | ||
* | ||
* @param [in] rootNode The containing element. | ||
* @param [in/out] modeRefList The mode reference list to read to. | ||
*/ | ||
void parseModeRefs(QDomNode const& rootNode, QSharedPointer<QList<QSharedPointer<ModeReference> > > modeRefList); | ||
|
||
/*! | ||
* Parse field access policy access value. | ||
* | ||
* @param [in] accessPolicyNode The XML description of the field access policy. | ||
* @param [in] accessPolicy The created field access policy. | ||
*/ | ||
void parseAccess(QDomNode const& accessPolicyNode, QSharedPointer<AccessPolicy> accessPolicy); | ||
} | ||
} | ||
|
||
#endif // FIELDACCESSPOLICYREADER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//----------------------------------------------------------------------------- | ||
// File: AccessPolicyWriter.cpp | ||
//----------------------------------------------------------------------------- | ||
// Project: Kactus 2 | ||
// Author: Anton Hagqvist | ||
// Date: 8.8.2023 | ||
// | ||
// Description: | ||
// Writer for ipxact:accessPolicy. | ||
//----------------------------------------------------------------------------- | ||
|
||
#include "AccessPolicyWriter.h" | ||
|
||
#include <IPXACTmodels/common/CommonItemsWriter.h> | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicyWriter::writeAccessPolicy() | ||
//----------------------------------------------------------------------------- | ||
void AccessPolicyWriter::writeAccessPolicy(QXmlStreamWriter& writer, | ||
QSharedPointer<AccessPolicy> fieldAccessPolicy) | ||
{ | ||
writer.writeStartElement(QStringLiteral("ipxact:accessPolicy")); | ||
|
||
Details::writeModeRefs(writer, fieldAccessPolicy->getModeReferences()); | ||
|
||
Details::writeAccess(writer, fieldAccessPolicy); | ||
|
||
CommonItemsWriter::writeVendorExtensions(writer, fieldAccessPolicy); | ||
|
||
writer.writeEndElement(); // ipxact:accessPolicy | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicyWriter::Details::writeModeRefs() | ||
//----------------------------------------------------------------------------- | ||
void AccessPolicyWriter::Details::writeModeRefs(QXmlStreamWriter& writer, | ||
QSharedPointer<QList<QSharedPointer<ModeReference> > > modeRefs) | ||
{ | ||
if (modeRefs->isEmpty()) | ||
{ | ||
return; | ||
} | ||
|
||
for (auto const& modeRef : *modeRefs) | ||
{ | ||
writer.writeStartElement(QStringLiteral("ipxact:modeRef")); | ||
|
||
if (auto const& priority = modeRef->getPriority(); !priority.isEmpty()) | ||
{ | ||
writer.writeAttribute(QStringLiteral("priority"), priority); | ||
} | ||
|
||
writer.writeCharacters(modeRef->getReference()); | ||
writer.writeEndElement(); // ipxact:modeRef | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Function: AccessPolicyWriter::Details::writeAccess() | ||
//----------------------------------------------------------------------------- | ||
void AccessPolicyWriter::Details::writeAccess(QXmlStreamWriter& writer, QSharedPointer<AccessPolicy> fieldAccessPolicy) | ||
{ | ||
if (fieldAccessPolicy->getAccess() != AccessTypes::ACCESS_COUNT) | ||
{ | ||
QString access = AccessTypes::access2Str(fieldAccessPolicy->getAccess()); | ||
writer.writeTextElement(QStringLiteral("ipxact:access"), access); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//----------------------------------------------------------------------------- | ||
// File: AccessPolicyWriter.h | ||
//----------------------------------------------------------------------------- | ||
// Project: Kactus 2 | ||
// Author: Anton Hagqvist | ||
// Date: 8.8.2023 | ||
// | ||
// Description: | ||
// Writer for ipxact:accessPolicy. | ||
//----------------------------------------------------------------------------- | ||
|
||
#ifndef ACCESSPOLICYWRITER_H | ||
#define ACCESSPOLICYWRITER_H | ||
|
||
#include "AccessPolicy.h" | ||
|
||
#include <IPXACTmodels/ipxactmodels_global.h> | ||
|
||
#include <QXmlStreamWriter> | ||
|
||
namespace AccessPolicyWriter | ||
{ | ||
|
||
/*! | ||
* Write a given access policy to XML. | ||
* | ||
* @param [in] writer The XML writer to use. | ||
* @param [in] accessPolicy The field access policy to write. | ||
*/ | ||
IPXACTMODELS_EXPORT void writeAccessPolicy(QXmlStreamWriter& writer, QSharedPointer<AccessPolicy> accessPolicy); | ||
|
||
namespace Details | ||
{ | ||
void writeModeRefs(QXmlStreamWriter& writer, QSharedPointer<QList<QSharedPointer<ModeReference> > > modeRefs); | ||
|
||
void writeAccess(QXmlStreamWriter& writer, QSharedPointer<AccessPolicy> accessPolicy); | ||
} | ||
} | ||
|
||
#endif // ACCESSPOLICYWRITER_H |
Oops, something went wrong.