Commit 26f0d464 authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

The service contained holds constant pointers.

This is to emphasise that the held object should not be manipulated and
working copies should be created where needed.
parent e16226ef
......@@ -59,161 +59,75 @@ GovWrapper::~GovWrapper(void)
clearGovServices();
}
/*!
* @brief Add a newly allocated service into the service container.
*
* @note The service object is freed when it cannot be added into the container.
*
* @param[in] map Service container.
* @param[in] gs Newly allocated service object.
*/
static
void insertService(QMap<QString, const Gov::Service *> &map,
Gov::Service *gs)
{
if (Q_UNLIKELY(gs == Q_NULLPTR)) {
return;
}
const QString &key(gs->internalId());
if (!map.contains(key)) {
map.insert(key, gs);
} else {
logError("Key '%s' already exists in gov service container.",
key.toUtf8().constData());
delete gs;
}
}
void GovWrapper::initGovServices(void)
{
debugFuncCall();
clearGovServices();
Gov::Service *gs;
/* Výpis bodového hodnocení z Centrálního registru řidičů */
gs = new (std::nothrow) Gov::SrvcMvCrrVbh;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvCrrVbh);
/* Výpis z insolvenčního rejstříku */
gs = new (std::nothrow) Gov::SrvcMvIrVp;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvIrVp);
/* Výpis z Rejstříku trestů */
gs = new (std::nothrow) Gov::SrvcMvRtVt;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvRtVt);
/* Výpis z Rejstříku trestů právnických osob */
gs = new (std::nothrow) Gov::SrvcMvRtpoVt;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvRtpoVt);
/* Výpis ze seznamu kvalifikovaných dodavatelů */
gs = new (std::nothrow) Gov::SrvcMvSkdVp;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvSkdVp);
/* Výpis z veřejného rejstříku */
gs = new (std::nothrow) Gov::SrvcMvVrVp;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvVrVp);
/* Výpis z živnostenského rejstříku */
gs = new (std::nothrow) Gov::SrvcMvZrVp;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcMvZrVp);
/* Výpis z Registru obyvatel */
gs = new (std::nothrow) Gov::SrvcSzrRobVu;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcSzrRobVu);
/* Výpis o využití údajů z registru obyvatel */
gs = new (std::nothrow) Gov::SrvcSzrRobVvu;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcSzrRobVvu);
/* Veřejný výpis z registru osob */
gs = new (std::nothrow) Gov::SrvcSzrRosVv;
if (gs != Q_NULLPTR) {
const QString &key(gs->internalId());
if (!m_govServices.contains(key)) {
m_govServices.insert(key, gs);
} else {
logError(
"Key '%s' already exists in gov services container.",
key.toUtf8().constData());
delete gs;
}
}
insertService(m_govServices, new (std::nothrow) Gov::SrvcSzrRosVv);
}
void GovWrapper::clearGovServices(void)
{
debugFuncCall();
foreach (Gov::Service *gs, m_govServices.values()) {
delete gs;
foreach (const Gov::Service *gs, m_govServices.values()) {
delete const_cast<Gov::Service *>(gs);
}
m_govServices.clear();
}
......
......@@ -99,6 +99,6 @@ public:
const QVariant &formModelVariant) const;
private:
QMap<QString, Gov::Service *> m_govServices; /*!< Holds pointers to all available Gov services. */
QMap<QString, const Gov::Service *> m_govServices; /*!< Holds pointers to all available Gov services. */
IsdsWrapper *m_isds; /*!< Pointer to isds wrapper. */
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment