| 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 "CConfigDataReader.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Config { |
| 27 |
|
| 28 |
CConfigDataReader::CConfigDataReader() { |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
CConfigDataReader::~CConfigDataReader() { |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
QString CConfigDataReader::readConfigString(CConfiguration *config, const QString &configString, const QString &defaultValue, bool *errorFlag) { |
| 37 |
QString stringValue = defaultValue; |
| 38 |
if (config) { |
| 39 |
CConfigData *configData = config->getRelatedConfigChange(configString,true); |
| 40 |
if (configData && configData->supportsStringConvertion()) { |
| 41 |
stringValue = configData->getString(); |
| 42 |
} else { |
| 43 |
if (errorFlag) { |
| 44 |
*errorFlag = true; |
| 45 |
} |
| 46 |
} |
| 47 |
} else { |
| 48 |
if (errorFlag) { |
| 49 |
*errorFlag = true; |
| 50 |
} |
| 51 |
} |
| 52 |
return stringValue; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
qint64 CConfigDataReader::readConfigInteger(CConfiguration *config, const QString &configString, qint64 defaultValue, bool *errorFlag) { |
| 57 |
qint64 intValue = defaultValue; |
| 58 |
if (config) { |
| 59 |
CConfigData *configData = config->getRelatedConfigChange(configString,true); |
| 60 |
if (configData && configData->supportsIntegerConvertion()) { |
| 61 |
intValue = configData->getInteger(); |
| 62 |
} else { |
| 63 |
if (errorFlag) { |
| 64 |
*errorFlag = true; |
| 65 |
} |
| 66 |
} |
| 67 |
} else { |
| 68 |
if (errorFlag) { |
| 69 |
*errorFlag = true; |
| 70 |
} |
| 71 |
} |
| 72 |
return intValue; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
double CConfigDataReader::readConfigDouble(CConfiguration *config, const QString &configString, double defaultValue, bool *errorFlag) { |
| 77 |
double doubleValue = defaultValue; |
| 78 |
if (config) { |
| 79 |
CConfigData *configData = config->getRelatedConfigChange(configString, true); |
| 80 |
if (configData && configData->supportsDoubleConvertion()) { |
| 81 |
doubleValue = configData->getDouble(); |
| 82 |
} else { |
| 83 |
if (errorFlag) { |
| 84 |
*errorFlag = true; |
| 85 |
} |
| 86 |
} |
| 87 |
} else { |
| 88 |
if (errorFlag) { |
| 89 |
*errorFlag = true; |
| 90 |
} |
| 91 |
} |
| 92 |
return doubleValue; |
| 93 |
} |
| 94 |
|
| 95 |
bool CConfigDataReader::readConfigBoolean(CConfiguration *config, const QString &configString, bool defaultValue, bool *errorFlag) { |
| 96 |
qint64 boolValue = defaultValue; |
| 97 |
if (config) { |
| 98 |
CConfigData *configData = config->getRelatedConfigChange(configString,true); |
| 99 |
if (configData && configData->supportsBooleanConvertion()) { |
| 100 |
boolValue = configData->getBoolean(); |
| 101 |
} else { |
| 102 |
if (errorFlag) { |
| 103 |
*errorFlag = true; |
| 104 |
} |
| 105 |
} |
| 106 |
} else { |
| 107 |
if (errorFlag) { |
| 108 |
*errorFlag = true; |
| 109 |
} |
| 110 |
} |
| 111 |
return boolValue; |
| 112 |
} |
| 113 |
|
| 114 |
QStringList CConfigDataReader::readConfigStringList(CConfiguration *config, const QString &configString, const QStringList& defaultValue, bool *errorFlag) { |
| 115 |
QStringList stringListValue = defaultValue; |
| 116 |
if (config) { |
| 117 |
CConfigData *configData = config->getRelatedConfigChange(configString, true); |
| 118 |
if (configData && configData->supportsStringListConvertion()) { |
| 119 |
stringListValue = configData->getStringList(); |
| 120 |
} else { |
| 121 |
if (errorFlag) { |
| 122 |
*errorFlag = true; |
| 123 |
} |
| 124 |
} |
| 125 |
} else { |
| 126 |
if (errorFlag) { |
| 127 |
*errorFlag = true; |
| 128 |
} |
| 129 |
} |
| 130 |
return stringListValue; |
| 131 |
} |
| 132 |
|
| 133 |
QString CConfigDataReader::readConfigString(CConfigurationProvider *configProv, const QString &configString, const QString &defaultValue, bool *errorFlag) { |
| 134 |
CConfiguration *config = 0; |
| 135 |
if (configProv) { |
| 136 |
config = configProv->getCurrentConfiguration(); |
| 137 |
} |
| 138 |
return readConfigString(config, configString, defaultValue, errorFlag); |
| 139 |
} |
| 140 |
|
| 141 |
double CConfigDataReader::readConfigDouble(CConfigurationProvider *configProv, const QString &configString, double defaultValue, bool *errorFlag) { |
| 142 |
CConfiguration *config = 0; |
| 143 |
if (configProv) { |
| 144 |
config = configProv->getCurrentConfiguration(); |
| 145 |
} |
| 146 |
return readConfigDouble(config,configString,defaultValue,errorFlag); |
| 147 |
} |
| 148 |
|
| 149 |
qint64 CConfigDataReader::readConfigInteger(CConfigurationProvider *configProv, const QString &configString, qint64 defaultValue, bool *errorFlag) { |
| 150 |
CConfiguration *config = 0; |
| 151 |
if (configProv) { |
| 152 |
config = configProv->getCurrentConfiguration(); |
| 153 |
} |
| 154 |
return readConfigInteger(config,configString,defaultValue,errorFlag); |
| 155 |
} |
| 156 |
|
| 157 |
bool CConfigDataReader::readConfigBoolean(CConfigurationProvider *configProv, const QString &configString, bool defaultValue, bool *errorFlag) { |
| 158 |
CConfiguration *config = 0; |
| 159 |
if (configProv) { |
| 160 |
config = configProv->getCurrentConfiguration(); |
| 161 |
} |
| 162 |
return readConfigBoolean(config,configString,defaultValue,errorFlag); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
}; // end namespace Config |
| 167 |
|
| 168 |
}; // end namespace Konclude |