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
100 public:
105
120 shared_ptr<fiftyoneDegreesResourceManager> manager);
121
126 virtual ~ResultsBase();
127
133
142
149 bool containsProperty(const string &propertyName) const;
150
161 vector<string> getProperties() const;
162
174 string getPropertyName(int requiredPropertyIndex) const;
175
181
190 Value<vector<string>> getValues(const char *propertyName);
191
200 Value<vector<string>> getValues(const string &propertyName);
201
210 Value<vector<string>> getValues(const string *propertyName);
211
221 Value<vector<string>> getValues(int requiredPropertyIndex);
222
231 Value<string> getValueAsString(const char *propertyName);
232
241 Value<string> getValueAsString(const string &propertyName);
242
251 Value<string> getValueAsString(const string *propertyName);
252
264 virtual Value<string> getValueAsString(int requiredPropertyIndex);
265
276 Value<bool> getValueAsBool(const char *propertyName);
277
288 Value<bool> getValueAsBool(const string &propertyName);
289
300 Value<bool> getValueAsBool(const string *propertyName);
301
314 virtual Value<bool> getValueAsBool(int requiredPropertyIndex);
315
327 Value<int> getValueAsInteger(const char *propertyName);
328
340 Value<int> getValueAsInteger(const string &propertyName);
341
353 Value<int> getValueAsInteger(const string *propertyName);
354
368 virtual Value<int> getValueAsInteger(int requiredPropertyIndex);
369
381 Value<double> getValueAsDouble(const char *propertyName);
382
394 Value<double> getValueAsDouble(const string &propertyName);
395
407 Value<double> getValueAsDouble(const string *propertyName);
408
422 virtual Value<double> getValueAsDouble(int requiredPropertyIndex);
423
433 Value<bool> getValueAsStrictBool(const char *propertyName);
434
438 Value<bool> getValueAsStrictBool(const string &propertyName);
439
451 Value<bool> getValueAsStrictBool(int requiredPropertyIndex);
452
462 Value<int> getValueAsStrictInteger(const char *propertyName);
463
467 Value<int> getValueAsStrictInteger(const string &propertyName);
468
480 Value<int> getValueAsStrictInteger(int requiredPropertyIndex);
481
491 Value<double> getValueAsStrictDouble(const char *propertyName);
492
496 Value<double> getValueAsStrictDouble(const string &propertyName);
497
509 Value<double> getValueAsStrictDouble(int requiredPropertyIndex);
510
514
515 protected:
518
523 int getRequiredPropertyIndex(const char *propertyName);
524
533 virtual void getValuesInternal(
534 int requiredPropertyIndex,
535 vector<string> &values) = 0;
536
545 virtual bool hasValuesInternal(int requiredPropertyIndex) = 0;
546
556 virtual const char* getNoValueMessageInternal(
558
568 int requiredPropertyIndex) = 0;
569
570 private:
579 shared_ptr<fiftyoneDegreesResourceManager> manager;
580
591 template <class T> bool getOneValueText(
592 int requiredPropertyIndex,
593 Value<T> &result,
594 string &text);
595
600 Value<vector<string>> valuesAt(int requiredPropertyIndex);
601 Value<string> valueAsStringAt(int requiredPropertyIndex);
602 Value<bool> valueAsBoolAt(int requiredPropertyIndex);
603 Value<int> valueAsIntegerAt(int requiredPropertyIndex);
604 Value<double> valueAsDoubleAt(int requiredPropertyIndex);
605 Value<bool> valueAsStrictBoolAt(int requiredPropertyIndex);
606 Value<int> valueAsStrictIntegerAt(int requiredPropertyIndex);
607 Value<double> valueAsStrictDoubleAt(int requiredPropertyIndex);
608 };
609 FIFTYONE_DEGREES_COMMON_CXX_END
610 }
611}
612
613#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".
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:517
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:234
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