| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CConfigurationGroup.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Config { |
| 27 |
|
| 28 |
CConfigurationGroup::CConfigurationGroup() { |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
CConfigurationGroup::~CConfigurationGroup() { |
| 33 |
qDeleteAll(configDesContainer); |
| 34 |
qDeleteAll(configDataContainer); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
qint64 CConfigurationGroup::addConfigProperty(CConfigDescription *takeConfigDescription, CConfigData *takeDefaultConfigValue) { |
| 39 |
readWriteSync.lockForWrite(); |
| 40 |
|
| 41 |
if (takeConfigDescription){ |
| 42 |
configDesContainer.append(takeConfigDescription); |
| 43 |
} |
| 44 |
if (takeDefaultConfigValue){ |
| 45 |
configDataContainer.append(takeDefaultConfigValue); |
| 46 |
} |
| 47 |
|
| 48 |
qint64 configIdx = 0; |
| 49 |
if (!propertyNameIndexHash.contains(takeConfigDescription->getConfigName())) { |
| 50 |
configIdx = configDesVector.getItemCount(); |
| 51 |
propertyNameIndexHash.insert(takeConfigDescription->getConfigName(),configIdx); |
| 52 |
} else { |
| 53 |
configIdx = propertyNameIndexHash.value(takeConfigDescription->getConfigName()); |
| 54 |
} |
| 55 |
configDesVector.setData(configIdx,takeConfigDescription); |
| 56 |
configDataVector.setData(configIdx,takeDefaultConfigValue); |
| 57 |
|
| 58 |
takeConfigDescription->setConfigID(configIdx); |
| 59 |
readWriteSync.unlock(); |
| 60 |
return configIdx; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
CConfigurationGroup *CConfigurationGroup::setConfigDefaultData(qint64 index, CConfigData *takeDefaultConfigValue) { |
| 65 |
readWriteSync.lockForWrite(); |
| 66 |
if (takeDefaultConfigValue){ |
| 67 |
configDataVector.setData(index,takeDefaultConfigValue); |
| 68 |
configDataContainer.append(takeDefaultConfigValue); |
| 69 |
} |
| 70 |
readWriteSync.unlock(); |
| 71 |
return this; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
qint64 CConfigurationGroup::addConfigProperty(CConfigDescription *takeConfigDescription) { |
| 77 |
CConfigData *takeDefaultConfigValue = new CConfigData(takeConfigDescription,takeConfigDescription->getConfigType()->getTypeCopy()); |
| 78 |
return addConfigProperty(takeConfigDescription,takeDefaultConfigValue); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
qint64 CConfigurationGroup::addConfigProperty(CConfigDescription *takeConfigDescription, CConfigType *takeDefaultConfigType) { |
| 83 |
CConfigData *takeDefaultConfigValue = new CConfigData(takeConfigDescription,takeDefaultConfigType); |
| 84 |
return addConfigProperty(takeConfigDescription,takeDefaultConfigValue); |
| 85 |
} |
| 86 |
|
| 87 |
CConfigDescription *CConfigurationGroup::getConfigDescription(qint64 index) { |
| 88 |
readWriteSync.lockForRead(); |
| 89 |
CConfigDescription *des = 0; |
| 90 |
if (index >= 0 && index < configDesVector.getItemCount()) { |
| 91 |
des = configDesVector.getData(index); |
| 92 |
} |
| 93 |
readWriteSync.unlock(); |
| 94 |
return des; |
| 95 |
} |
| 96 |
|
| 97 |
CConfigData *CConfigurationGroup::getConfigDefaultData(qint64 index) { |
| 98 |
readWriteSync.lockForRead(); |
| 99 |
CConfigData *dat = 0; |
| 100 |
if (index >= 0 && index < configDataVector.getItemCount()) { |
| 101 |
dat = configDataVector.getData(index); |
| 102 |
} |
| 103 |
readWriteSync.unlock(); |
| 104 |
return dat; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
CConfigDescription *CConfigurationGroup::getConfigDescription(const QString &name) { |
| 109 |
qint64 index = getConfigIndex(name); |
| 110 |
return getConfigDescription(index); |
| 111 |
} |
| 112 |
|
| 113 |
CConfigData *CConfigurationGroup::getConfigDefaultData(const QString &name) { |
| 114 |
qint64 index = getConfigIndex(name); |
| 115 |
return getConfigDefaultData(index); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
qint64 CConfigurationGroup::getConfigPropertyCount() { |
| 120 |
return configDesVector.getItemCount(); |
| 121 |
} |
| 122 |
|
| 123 |
qint64 CConfigurationGroup::getConfigIndex(const QString &name) { |
| 124 |
qint64 index = propertyNameIndexHash.value(name,-1); |
| 125 |
return index; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
CConfigurationGroup* CConfigurationGroup::getReferencedConfigurationGroup() { |
| 130 |
CConfigurationGroup *refConfGroup = new CConfigurationGroup(); |
| 131 |
refConfGroup->propertyNameIndexHash = propertyNameIndexHash; |
| 132 |
refConfGroup->configDesVector.reference(&configDesVector); |
| 133 |
refConfGroup->configDataVector.reference(&configDataVector); |
| 134 |
return refConfGroup; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
QList<CConfigDescription*> CConfigurationGroup::getConfigDescriptonList() { |
| 140 |
QList<CConfigDescription*> desList; |
| 141 |
for (cint64 i = configDesVector.getItemCount()-1; i >= 0; --i) { |
| 142 |
desList.append(configDesVector.getData(i)); |
| 143 |
} |
| 144 |
return desList; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
}; // end namespace Config |
| 150 |
|
| 151 |
}; // end namespace Konclude |