| 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 "CDataLiteralXMLValue.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Ontology { |
| 29 |
|
| 30 |
|
| 31 |
CDataLiteralXMLValue::CDataLiteralXMLValue() { |
| 32 |
clearValue(); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
CDataLiteralValue::DATA_LITERAL_VALUE_TYPE CDataLiteralXMLValue::getDataValueType() { |
| 37 |
return CDataLiteralValue::DLVT_XML; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
CDataLiteralCompareValue* CDataLiteralXMLValue::initValue(CDataLiteralCompareValue* value) { |
| 42 |
clearValue(); |
| 43 |
CDataLiteralXMLValue* xmlValue = dynamic_cast<CDataLiteralXMLValue*>(value); |
| 44 |
if (xmlValue) { |
| 45 |
mInfiniteLength = xmlValue->mInfiniteLength; |
| 46 |
mLength = xmlValue->mLength; |
| 47 |
mXMLString = xmlValue->mXMLString; |
| 48 |
} |
| 49 |
return this; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
QString CDataLiteralXMLValue::getValueString() { |
| 54 |
return mXMLString; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
CDataLiteralXMLValue* CDataLiteralXMLValue::initValueFromInfiniteLength() { |
| 59 |
clearValue(); |
| 60 |
mInfiniteLength = true; |
| 61 |
return this; |
| 62 |
} |
| 63 |
|
| 64 |
CDataLiteralXMLValue* CDataLiteralXMLValue::initValueFromLength(cuint64 length) { |
| 65 |
clearValue(); |
| 66 |
mLength = length; |
| 67 |
return this; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
CDataLiteralXMLValue* CDataLiteralXMLValue::initValueFromXMLString(const QString& xmlString) { |
| 72 |
clearValue(); |
| 73 |
mXMLString = xmlString; |
| 74 |
return this; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
CDataLiteralXMLValue* CDataLiteralXMLValue::initValue(CDataLiteralXMLValue* value) { |
| 79 |
if (value) { |
| 80 |
mInfiniteLength = value->mInfiniteLength; |
| 81 |
mLength = value->mLength; |
| 82 |
mXMLString = value->mXMLString; |
| 83 |
} |
| 84 |
return this; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
CDataLiteralXMLValue* CDataLiteralXMLValue::clearValue() { |
| 89 |
mInfiniteLength = false; |
| 90 |
mLength = 0; |
| 91 |
mXMLString.clear(); |
| 92 |
return this; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
bool CDataLiteralXMLValue::isInfiniteLength() { |
| 97 |
return mInfiniteLength; |
| 98 |
} |
| 99 |
|
| 100 |
cuint64 CDataLiteralXMLValue::getLength() { |
| 101 |
if (mLength > 0) { |
| 102 |
return mLength; |
| 103 |
} else { |
| 104 |
return mXMLString.length(); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
QString CDataLiteralXMLValue::getXMLValue() { |
| 109 |
return mXMLString; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
bool CDataLiteralXMLValue::isEqualTo(CDataLiteralValue* value) { |
| 114 |
CDataLiteralXMLValue* xmlValue = dynamic_cast<CDataLiteralXMLValue*>(value); |
| 115 |
if (xmlValue) { |
| 116 |
return isEqualTo(xmlValue); |
| 117 |
} |
| 118 |
return false; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
bool CDataLiteralXMLValue::isLessEqualThan(CDataLiteralCompareValue* value) { |
| 124 |
CDataLiteralXMLValue* xmlValue = dynamic_cast<CDataLiteralXMLValue*>(value); |
| 125 |
if (xmlValue) { |
| 126 |
return isEqualTo(xmlValue) || isLessThan(xmlValue); |
| 127 |
} |
| 128 |
return false; |
| 129 |
} |
| 130 |
|
| 131 |
bool CDataLiteralXMLValue::isLessEqualThan(CDataLiteralXMLValue* xmlValue) { |
| 132 |
return isEqualTo(xmlValue) || isLessThan(xmlValue); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
bool CDataLiteralXMLValue::isEqualTo(CDataLiteralCompareValue* value) { |
| 137 |
CDataLiteralXMLValue* xmlValue = dynamic_cast<CDataLiteralXMLValue*>(value); |
| 138 |
if (xmlValue) { |
| 139 |
return isEqualTo(xmlValue); |
| 140 |
} |
| 141 |
return false; |
| 142 |
} |
| 143 |
|
| 144 |
bool CDataLiteralXMLValue::isEqualTo(CDataLiteralXMLValue* xmlValue) { |
| 145 |
if (mInfiniteLength && xmlValue->mInfiniteLength) { |
| 146 |
return true; |
| 147 |
} |
| 148 |
if (mInfiniteLength || xmlValue->mInfiniteLength) { |
| 149 |
return false; |
| 150 |
} |
| 151 |
if (mLength > 0 && mLength == xmlValue->mLength) { |
| 152 |
return true; |
| 153 |
} |
| 154 |
if (mXMLString == xmlValue->mXMLString) { |
| 155 |
return true; |
| 156 |
} |
| 157 |
return false; |
| 158 |
} |
| 159 |
|
| 160 |
bool CDataLiteralXMLValue::isGreaterEqualThan(CDataLiteralXMLValue* xmlValue) { |
| 161 |
return isEqualTo(xmlValue) || isGreaterThan(xmlValue); |
| 162 |
} |
| 163 |
|
| 164 |
bool CDataLiteralXMLValue::isGreaterEqualThan(CDataLiteralCompareValue* value) { |
| 165 |
CDataLiteralXMLValue* xmlValue = dynamic_cast<CDataLiteralXMLValue*>(value); |
| 166 |
if (xmlValue) { |
| 167 |
return isEqualTo(xmlValue) || isGreaterThan(xmlValue); |
| 168 |
} |
| 169 |
return false; |
| 170 |
} |
| 171 |
|
| 172 |
bool CDataLiteralXMLValue::isGreaterThan(CDataLiteralCompareValue* value) { |
| 173 |
return value->isLessThan(this); |
| 174 |
} |
| 175 |
|
| 176 |
bool CDataLiteralXMLValue::isGreaterThan(CDataLiteralXMLValue* xmlValue) { |
| 177 |
return xmlValue->isLessThan(this); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
bool CDataLiteralXMLValue::isLessThan(CDataLiteralCompareValue* value) { |
| 182 |
CDataLiteralXMLValue* xmlValue = dynamic_cast<CDataLiteralXMLValue*>(value); |
| 183 |
if (xmlValue) { |
| 184 |
return isLessThan(xmlValue); |
| 185 |
} |
| 186 |
return false; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
bool CDataLiteralXMLValue::isLessThan(CDataLiteralXMLValue* xmlValue) { |
| 194 |
if (!mInfiniteLength && xmlValue->mInfiniteLength) { |
| 195 |
return true; |
| 196 |
} |
| 197 |
if (mInfiniteLength) { |
| 198 |
return false; |
| 199 |
} |
| 200 |
if (getLength() < xmlValue->getLength()) { |
| 201 |
return true; |
| 202 |
} else if (getLength() > xmlValue->getLength()) { |
| 203 |
return false; |
| 204 |
} else { |
| 205 |
int stringComp = mXMLString.compare(xmlValue->mXMLString); |
| 206 |
if (stringComp < 0) { |
| 207 |
return true; |
| 208 |
} else if (stringComp > 0) { |
| 209 |
return false; |
| 210 |
} |
| 211 |
} |
| 212 |
return false; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
}; // end namespace Ontology |
| 218 |
|
| 219 |
}; // end namespace Reasoner |
| 220 |
|
| 221 |
}; // end namespace Konclude |