A device detection library that is used natively or by 51Degrees products

ResultsBase.hpp

1/* *********************************************************************
2 * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House,
4 * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5 *
6 * This Original Work is licensed under the European Union Public Licence
7 * (EUPL) v.1.2 and is subject to its terms as set out below.
8 *
9 * If a copy of the EUPL was not distributed with this file, You can obtain
10 * one at https://opensource.org/licenses/EUPL-1.2.
11 *
12 * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 * amended by the European Commission) shall be deemed incompatible for
14 * the purposes of the Work and the provisions of the compatibility
15 * clause in Article 5 of the EUPL shall not apply.
16 *
17 * If using the Work as, or as part of, a network application, by
18 * including the attribution notice(s) required under Article 5 of the EUPL
19 * in the end user terms of the application under an appropriate heading,
20 * such notice(s) shall fulfill the requirements of that article.
21 * ********************************************************************* */
22
23#ifndef FIFTYONE_DEGREES_RESULTS_BASE_HPP
24#define FIFTYONE_DEGREES_RESULTS_BASE_HPP
25
26#include <string>
27#include <vector>
28#include <memory>
29#include <sstream>
30#include "Exceptions.hpp"
31#include "Value.hpp"
32#include "RequiredPropertiesConfig.hpp"
33#include "results.h"
34#include "resource.h"
35
36using std::shared_ptr;
37using std::stringstream;
38
39namespace FiftyoneDegrees {
40 namespace Common {
41 FIFTYONE_DEGREES_COMMON_CXX_BEGIN
98 public:
103
118 shared_ptr<fiftyoneDegreesResourceManager> manager);
119
124 virtual ~ResultsBase();
125
131
140
147 bool containsProperty(const string &propertyName) const;
148
156 vector<string> getProperties() const;
157
169 string getPropertyName(int requiredPropertyIndex) const;
170
176
185 Value<vector<string>> getValues(const char *propertyName);
186
195 Value<vector<string>> getValues(const string &propertyName);
196
205 Value<vector<string>> getValues(const string *propertyName);
206
216 Value<vector<string>> getValues(int requiredPropertyIndex);
217
226 Value<string> getValueAsString(const char *propertyName);
227
236 Value<string> getValueAsString(const string &propertyName);
237
246 Value<string> getValueAsString(const string *propertyName);
247
259 virtual Value<string> getValueAsString(int requiredPropertyIndex);
260
271 Value<bool> getValueAsBool(const char *propertyName);
272
283 Value<bool> getValueAsBool(const string &propertyName);
284
295 Value<bool> getValueAsBool(const string *propertyName);
296
309 virtual Value<bool> getValueAsBool(int requiredPropertyIndex);
310
322 Value<int> getValueAsInteger(const char *propertyName);
323
335 Value<int> getValueAsInteger(const string &propertyName);
336
348 Value<int> getValueAsInteger(const string *propertyName);
349
363 virtual Value<int> getValueAsInteger(int requiredPropertyIndex);
364
376 Value<double> getValueAsDouble(const char *propertyName);
377
389 Value<double> getValueAsDouble(const string &propertyName);
390
402 Value<double> getValueAsDouble(const string *propertyName);
403
417 virtual Value<double> getValueAsDouble(int requiredPropertyIndex);
418
428 Value<bool> getValueAsStrictBool(const char *propertyName);
429
433 Value<bool> getValueAsStrictBool(const string &propertyName);
434
446 Value<bool> getValueAsStrictBool(int requiredPropertyIndex);
447
457 Value<int> getValueAsStrictInteger(const char *propertyName);
458
462 Value<int> getValueAsStrictInteger(const string &propertyName);
463
475 Value<int> getValueAsStrictInteger(int requiredPropertyIndex);
476
486 Value<double> getValueAsStrictDouble(const char *propertyName);
487
491 Value<double> getValueAsStrictDouble(const string &propertyName);
492
504 Value<double> getValueAsStrictDouble(int requiredPropertyIndex);
505
509
510 protected:
513
518 int getRequiredPropertyIndex(const char *propertyName);
519
528 int allowedRequiredPropertyIndex(int requiredPropertyIndex) const;
529
538 virtual void getValuesInternal(
539 int requiredPropertyIndex,
540 vector<string> &values) = 0;
541
550 virtual bool hasValuesInternal(int requiredPropertyIndex) = 0;
551
561 virtual const char* getNoValueMessageInternal(
563
573 int requiredPropertyIndex) = 0;
574
575 private:
584 shared_ptr<fiftyoneDegreesResourceManager> manager;
585
596 template <class T> bool getOneValueText(
597 int requiredPropertyIndex,
598 Value<T> &result,
599 string &text);
600
607 Value<vector<string>> valuesAt(int requiredPropertyIndex);
608 Value<string> valueAsStringAt(int requiredPropertyIndex);
609 Value<bool> valueAsBoolAt(int requiredPropertyIndex);
610 Value<int> valueAsIntegerAt(int requiredPropertyIndex);
611 Value<double> valueAsDoubleAt(int requiredPropertyIndex);
612 Value<bool> valueAsStrictBoolAt(int requiredPropertyIndex);
613 Value<int> valueAsStrictIntegerAt(int requiredPropertyIndex);
614 Value<double> valueAsStrictDoubleAt(int requiredPropertyIndex);
615 };
616 FIFTYONE_DEGREES_COMMON_CXX_END
617 }
618}
619
620#endif
virtual Value< string > getValueAsString(int requiredPropertyIndex)
Get a string representation of the value associated with the required property index.
Value< double > getValueAsDouble(const string *propertyName)
Get a double representation of the value associated with the required property name.
virtual bool hasValuesInternal(int requiredPropertyIndex)=0
Get whether or not there are valid values available for the property identified by its index in the r...
Value< bool > getValueAsBool(const char *propertyName)
Get a boolean representation of the value associated with the required property name.
Value< vector< string > > getValues(const string *propertyName)
Get a vector with all values associated with the required property name.
Value< int > getValueAsStrictInteger(int requiredPropertyIndex)
Get the value as an integer only if all of its text is a whole number an int can hold.
Value< vector< string > > getValues(int requiredPropertyIndex)
Get a vector with all values associated with the required property index.
virtual Value< bool > getValueAsBool(int requiredPropertyIndex)
Get a boolean representation of the value associated with the required property index.
virtual void getValuesInternal(int requiredPropertyIndex, vector< string > &values)=0
Get the values for the index in required properties and add them to the values vector supplied.
virtual Value< int > getValueAsInteger(int requiredPropertyIndex)
Get an integer representation of the value associated with the required property index.
Value< double > getValueAsDouble(const char *propertyName)
Get a double representation of the value associated with the required property name.
Value< vector< string > > getValues(const char *propertyName)
Get a vector with all values associated with the required property name.
Value< vector< string > > getValues(const string &propertyName)
Get a vector with all values associated with the required property name.
Value< double > getValueAsStrictDouble(const char *propertyName)
Get the value as a double only if all of its text is a finite number.
virtual fiftyoneDegreesResultsNoValueReason getNoValueReasonInternal(int requiredPropertyIndex)=0
Get the reason for values not being available.
Value< bool > getValueAsStrictBool(int requiredPropertyIndex)
Get the value as a boolean only if its text is "True" or "False".
ResultsBase(fiftyoneDegreesResultsBase *results, shared_ptr< fiftyoneDegreesResourceManager > manager)
Create a new instance of Results from the results structure provided.
Value< string > getValueAsString(const string *propertyName)
Get a string representation of the value associated with the required property name.
bool containsProperty(const string &propertyName) const
Get whether or not this results instance contains a value for the requested property.
Value< bool > getValueAsStrictBool(const string &propertyName)
Get the value as a boolean only if its text is "True" or "False".
int allowedRequiredPropertyIndex(int requiredPropertyIndex) const
Get the index a read by required property index uses, which is the index given when the engine named ...
Value< int > getValueAsStrictInteger(const string &propertyName)
Get the value as an integer only if all of its text is a whole number an int can hold.
int getAvailableProperties() const
Get the number of required property indexes, which is the number of names the engine was created with...
Value< double > getValueAsStrictDouble(const string &propertyName)
Get the value as a double only if all of its text is a finite number.
virtual const char * getNoValueMessageInternal(fiftyoneDegreesResultsNoValueReason reason)=0
Get the message explaining the reason for missing values.
Value< bool > getValueAsBool(const string *propertyName)
Get a boolean representation of the value associated with the required property name.
Value< bool > getValueAsBool(const string &propertyName)
Get a boolean representation of the value associated with the required property name.
Value< int > getValueAsStrictInteger(const char *propertyName)
Get the value as an integer only if all of its text is a whole number an int can hold.
string getPropertyName(int requiredPropertyIndex) const
Get the name of the property at the required property index, or an empty string if there is no proper...
Value< string > getValueAsString(const string &propertyName)
Get a string representation of the value associated with the required property name.
Value< int > getValueAsInteger(const char *propertyName)
Get an integer representation of the value associated with the required property name.
fiftyoneDegreesPropertiesAvailable * available
Pointer to the underlying available properties structure.
Definition ResultsBase.hpp:512
vector< string > getProperties() const
Get the names of the properties the data set has, in ascending order.
Value< double > getValueAsDouble(const string &propertyName)
Get a double representation of the value associated with the required property name.
Value< int > getValueAsInteger(const string &propertyName)
Get an integer representation of the value associated with the required property name.
virtual Value< double > getValueAsDouble(int requiredPropertyIndex)
Get a double representation of the value associated with the required property index.
virtual ~ResultsBase()
Free any memory associated with the results and release any resource handles.
Value< string > getValueAsString(const char *propertyName)
Get a string representation of the value associated with the required property name.
Value< bool > getValueAsStrictBool(const char *propertyName)
Get the value as a boolean only if its text is "True" or "False".
Value< int > getValueAsInteger(const string *propertyName)
Get an integer representation of the value associated with the required property name.
Value< double > getValueAsStrictDouble(int requiredPropertyIndex)
Get the value as a double only if all of its text is a finite number.
int getRequiredPropertyIndex(const char *propertyName)
Get the required property index of the property name provided.
Encapsulates a value returned an instance of ResultsBase for a specified property.
Definition Value.hpp:76
fiftyoneDegreesPropertyAvailableArray fiftyoneDegreesPropertiesAvailable
Array of properties which are available in a data set.
Definition properties.h:223
fiftyoneDegreesResultsNoValueReason
Enum containing reasons which cause a value to not be present or valid.
Definition results.h:95
Shared classes.
Definition Collection.hpp:31
A C++ wrapper class for transform.h conversion routines.
Definition ComponentMetaDataBuilderHash.hpp:33
Base results structure which any processing results should extend.
Definition results.h:158