-
Notifications
You must be signed in to change notification settings - Fork 6
/
ResultsBase.cpp
264 lines (234 loc) · 7.98 KB
/
ResultsBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/* *********************************************************************
* This Original Work is copyright of 51 Degrees Mobile Experts Limited.
* Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
* Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
*
* This Original Work is licensed under the European Union Public Licence
* (EUPL) v.1.2 and is subject to its terms as set out below.
*
* If a copy of the EUPL was not distributed with this file, You can obtain
* one at https://opensource.org/licenses/EUPL-1.2.
*
* The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
* amended by the European Commission) shall be deemed incompatible for
* the purposes of the Work and the provisions of the compatibility
* clause in Article 5 of the EUPL shall not apply.
*
* If using the Work as, or as part of, a network application, by
* including the attribution notice(s) required under Article 5 of the EUPL
* in the end user terms of the application under an appropriate heading,
* such notice(s) shall fulfill the requirements of that article.
* ********************************************************************* */
#include "ResultsBase.hpp"
#include "fiftyone.h"
using namespace FiftyoneDegrees::Common;
ResultsBase::ResultsBase(
fiftyoneDegreesResultsBase *results,
shared_ptr<fiftyoneDegreesResourceManager> manager) {
this->available = ((DataSetBase*)results->dataSet)->available;
this->manager = manager;
}
ResultsBase::~ResultsBase() {
}
int ResultsBase::getAvailableProperties() const {
return available->count;
}
bool ResultsBase::containsProperty(
const string &propertyName) const {
return PropertiesGetRequiredPropertyIndexFromName(
available,
propertyName.c_str()) >= 0;
}
vector<string> ResultsBase::getProperties() const {
int i, size = getAvailableProperties();
vector<string> result;
for (i = 0; i < size; i++) {
result.push_back(getPropertyName(i));
}
return result;
}
string ResultsBase::getPropertyName(
int requiredPropertyIndex) const {
string name;
const char *cName;
if (requiredPropertyIndex >= 0 &&
requiredPropertyIndex < (int)available->count) {
cName = STRING(PropertiesGetNameFromRequiredIndex(
available,
requiredPropertyIndex));
if (cName != nullptr) {
name.assign(cName);
}
}
return name;
}
FiftyoneDegrees::Common::Value<string> ResultsBase::getValueAsString(int requiredPropertyIndex) {
Value<string> result;
if (hasValuesInternal(requiredPropertyIndex) == false) {
fiftyoneDegreesResultsNoValueReason reason =
getNoValueReasonInternal(requiredPropertyIndex);
result.setNoValueReason(
reason,
getNoValueMessageInternal(reason));
}
else {
vector<string> values;
getValuesInternal(requiredPropertyIndex, values);
if (values.size() > 1) {
stringstream stream;
for (vector<string>::iterator it = values.begin();
it != values.end();
it++) {
if (it != values.begin()) {
stream << "|";
}
stream << *it;
}
result.setValue(stream.str());
}
else if (values.size() != 0) {
result.setValue(*values.begin());
}
}
return result;
}
FiftyoneDegrees::Common::Value<string> ResultsBase::getValueAsString(const char* propertyName) {
return getValueAsString(getRequiredPropertyIndex(propertyName));
}
FiftyoneDegrees::Common::Value<string> ResultsBase::getValueAsString(const string &propertyName) {
return getValueAsString(propertyName.c_str());
}
FiftyoneDegrees::Common::Value<string> ResultsBase::getValueAsString(const string *propertyName) {
return getValueAsString(propertyName->c_str());
}
FiftyoneDegrees::Common::Value<bool> ResultsBase::getValueAsBool(int requiredPropertyIndex) {
Value<bool> result;
if (hasValuesInternal(requiredPropertyIndex) == false) {
fiftyoneDegreesResultsNoValueReason reason =
getNoValueReasonInternal(requiredPropertyIndex);
result.setNoValueReason(
reason,
getNoValueMessageInternal(reason));
}
else {
vector<string> values;
getValuesInternal(requiredPropertyIndex, values);
if (values.size() > 1) {
result.setNoValueReason(
FIFTYONE_DEGREES_RESULTS_NO_VALUE_REASON_TOO_MANY_VALUES,
nullptr);
}
else if (values.size() != 0) {
result.setValue((*values.begin()).compare("True") == 0);
}
}
return result;
}
FiftyoneDegrees::Common::Value<bool> ResultsBase::getValueAsBool(const char* propertyName) {
return getValueAsBool(getRequiredPropertyIndex(propertyName));
}
FiftyoneDegrees::Common::Value<bool> ResultsBase::getValueAsBool(const string &propertyName) {
return getValueAsBool(propertyName.c_str());
}
FiftyoneDegrees::Common::Value<bool> ResultsBase::getValueAsBool(const string *propertyName) {
return getValueAsBool(propertyName->c_str());
}
FiftyoneDegrees::Common::Value<int> ResultsBase::getValueAsInteger(int requiredPropertyIndex) {
Value<int> result;
if (hasValuesInternal(requiredPropertyIndex) == false) {
fiftyoneDegreesResultsNoValueReason reason =
getNoValueReasonInternal(requiredPropertyIndex);
result.setNoValueReason(
reason,
getNoValueMessageInternal(reason));
}
else {
vector<string> values;
getValuesInternal(requiredPropertyIndex, values);
if (values.size() > 1) {
result.setNoValueReason(
FIFTYONE_DEGREES_RESULTS_NO_VALUE_REASON_TOO_MANY_VALUES,
nullptr);
}
else if (values.size() != 0) {
result.setValue(atoi(values.begin()->c_str()));
}
}
return result;
}
FiftyoneDegrees::Common::Value<int> ResultsBase::getValueAsInteger(const char* propertyName) {
return getValueAsInteger(getRequiredPropertyIndex(propertyName));
}
FiftyoneDegrees::Common::Value<int> ResultsBase::getValueAsInteger(const string &propertyName) {
return getValueAsInteger(propertyName.c_str());
}
FiftyoneDegrees::Common::Value<int> ResultsBase::getValueAsInteger(const string *propertyName) {
return getValueAsInteger(propertyName->c_str());
}
FiftyoneDegrees::Common::Value<double> ResultsBase::getValueAsDouble(int requiredPropertyIndex) {
Value<double> result;
if (hasValuesInternal(requiredPropertyIndex) == false) {
fiftyoneDegreesResultsNoValueReason reason =
getNoValueReasonInternal(requiredPropertyIndex);
result.setNoValueReason(
reason,
getNoValueMessageInternal(reason));
}
else {
vector<string> values;
getValuesInternal(requiredPropertyIndex, values);
if (values.size() > 1) {
result.setNoValueReason(
FIFTYONE_DEGREES_RESULTS_NO_VALUE_REASON_TOO_MANY_VALUES,
nullptr);
}
else if (values.size() != 0) {
result.setValue(strtod(values.begin()->c_str(), nullptr));
}
}
return result;
}
FiftyoneDegrees::Common::Value<double> ResultsBase::getValueAsDouble(const char* propertyName) {
return getValueAsDouble(getRequiredPropertyIndex(propertyName));
}
FiftyoneDegrees::Common::Value<double> ResultsBase::getValueAsDouble(const string &propertyName) {
return getValueAsDouble(propertyName.c_str());
}
FiftyoneDegrees::Common::Value<double> ResultsBase::getValueAsDouble(const string *propertyName) {
return getValueAsDouble(propertyName->c_str());
}
FiftyoneDegrees::Common::Value<vector<string>> ResultsBase::getValues(
int requiredPropertyIndex) {
Value<vector<string>> result;
if (hasValuesInternal(requiredPropertyIndex) == false) {
fiftyoneDegreesResultsNoValueReason reason =
getNoValueReasonInternal(requiredPropertyIndex);
result.setNoValueReason(
reason,
getNoValueMessageInternal(reason));
}
else {
vector<string> values;
getValuesInternal(requiredPropertyIndex, values);
result.setValue(values);
}
return result;
}
FiftyoneDegrees::Common::Value<vector<string>> ResultsBase::getValues(
const char *propertyName) {
return getValues(getRequiredPropertyIndex(propertyName));
}
FiftyoneDegrees::Common::Value<vector<string>> ResultsBase::getValues(
const string &propertyName) {
return getValues(propertyName.c_str());
}
FiftyoneDegrees::Common::Value<vector<string>> ResultsBase::getValues(
const string *propertyName) {
return getValues(propertyName->c_str());
}
int ResultsBase::getRequiredPropertyIndex(
const char *propertyName) {
return PropertiesGetRequiredPropertyIndexFromName(
available,
propertyName);
}