Debian Codegraph @

Source/Config/CConfiguration.cpp

raw
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 "CConfiguration.h"
22
23
24 namespace Konclude {
25
26 namespace Config {
27
28 CConfiguration::CConfiguration(CConfigurationGroup *configGroup) {
29 conGroup = configGroup;
30 qint64 conCount = 0;
31 if (conGroup) {
32 conCount = conGroup->getConfigPropertyCount();
33 }
34 conData = new QVector<CConfigData *>(conCount,0);
35 checkedRefConData = new QVector<bool>(conCount,false);
36 hasRefConData = new QVector<bool>(conCount,false);
37 prevConf = 0;
38 }
39
40 CConfiguration::CConfiguration(CConfiguration *previousConfiguration) {
41 prevConf = previousConfiguration;
42 conGroup = 0;
43 if (prevConf) {
44 conGroup = prevConf->conGroup;
45 }
46 qint64 conCount = 0;
47 if (conGroup) {
48 conCount = conGroup->getConfigPropertyCount();
49 }
50 conData = new QVector<CConfigData *>(conCount,0);
51 checkedRefConData = new QVector<bool>(conCount,false);
52 hasRefConData = new QVector<bool>(conCount,false);
53 }
54
55 CConfiguration::~CConfiguration() {
56 delete conData;
57 delete checkedRefConData;
58 delete hasRefConData;
59 qDeleteAll(conDataContainer);
60 }
61
62
63 bool CConfiguration::setConfig(qint64 configIndex, CConfigData *takeData) {
64 if (configIndex >= 0 && configIndex < conData->count()) {
65 conDataContainer.append(takeData);
66 (*conData)[configIndex] = takeData;
67 return true;
68 }
69 return false;
70 }
71
72 bool CConfiguration::setConfig(const QString &configName, CConfigData *takeData) {
73 if (conGroup) {
74 qint64 index = conGroup->getConfigIndex(configName);
75 return setConfig(index,takeData);
76 }
77 return false;
78 }
79
80
81 CConfigData *CConfiguration::createAndSetConfig(const QString &configName) {
82 CConfigData *confData = createConfig(configName);
83 if (confData) {
84 setConfig(configName,confData);
85 }
86 return confData;
87 }
88
89
90 CConfigData *CConfiguration::createConfig(const QString &configName) {
91 CConfigData *data = 0;
92 if (conGroup) {
93 CConfigDescription *conDes = conGroup->getConfigDescription(configName);
94 if (conDes) {
95 data = new CConfigData(conDes,conDes->getConfigType()->getTypeCopy());
96 }
97 }
98 return data;
99 }
100
101
102 CConfigData *CConfiguration::getRelatedConfigChange(const QString &configName, bool defaultCompensation) {
103 return getLastConfigChange(configName,defaultCompensation);
104 }
105
106 CConfigData *CConfiguration::getRelatedConfigChange(qint64 configIndex, bool defaultCompensation) {
107 return getLastConfigChange(configIndex,defaultCompensation);
108 }
109
110
111
112 CConfigData *CConfiguration::getLastConfigChange(const QString &configName, bool defaultCompensation) {
113 CConfigData *data = 0;
114 if (conGroup) {
115 qint64 index = conGroup->getConfigIndex(configName);
116 data = getLastConfigChange(index,defaultCompensation);
117 }
118 return data;
119 }
120
121 CConfigData *CConfiguration::getLastConfigChange(qint64 configIndex, bool defaultCompensation) {
122 CConfigData *data = 0;
123 if (configIndex >= 0 && configIndex < conData->count()) {
124 data = (*conData)[configIndex];
125 if (!data) {
126 if (!(*checkedRefConData)[configIndex]) {
127 if (prevConf) {
128 data = prevConf->getLastConfigChange(configIndex,defaultCompensation);
129 }
130 if (!data && conGroup && defaultCompensation) {
131 data = conGroup->getConfigDefaultData(configIndex);
132 }
133 (*checkedRefConData)[configIndex] = true;
134 if (data) {
135 (*conData)[configIndex] = data;
136 (*hasRefConData)[configIndex] = true;
137 }
138 }
139 }
140 }
141 return data;
142 }
143
144
145
146 CConfigurationGroup *CConfiguration::getConfigurationGroup() {
147 return conGroup;
148 }
149
150
151 CConfiguration *CConfiguration::extendConfigurationGroup(CConfigurationGroup *referencedConfigGroup) {
152 qint64 conCount = referencedConfigGroup->getConfigPropertyCount();
153 conData->resize(conCount);
154 checkedRefConData->resize(conCount);
155 hasRefConData->resize(conCount);
156
157 conGroup = referencedConfigGroup;
158
159 return this;
160 }
161
162
163
164 }; // end namespace Config
165
166 }; // end namespace Konclude