51Degrees Device Detection C/C++  4.1

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

FiftyoneDegrees::Common::Value< T > Class Template Reference

Detailed Description

template<class T>
class FiftyoneDegrees::Common::Value< T >

Encapsulates a value returned an instance of ResultsBase for a specified property.

An instance contains either the value, or the reason which there is no value.

Before retrieving the value itself, its presence should first be checked using the hasValue() method. The typed value can be returned either using the getValue() method, or more simply, by dereferencing (similarly to an iterator). If there is no value, then an exception will be thrown.

## Usage Example

using namespace FiftyoneDegrees::Common;
// Check that there is a valid value
if (value.hasValue()) {
// Get the value
string stringValue = *value;
// Do something with the value
// ...
}
else {
// Get the reason for the value being invalid
string message = value.getNoValueMessage();
// Do something with the message
// ...
}
// Or just try getting the value and catch the exception. Note that
// this is not the recommended method.
try {
string stringValue = *value;
}
catch (exception e) {
const char *message = e.what();
}
Template Parameters
T - the type of the value e.g. string

Public Member Functions

Constructors

 Value ()
Default constructor.

Value Methods

bool  hasValue ()
Indicates whether or not a valid value has been returned by the ResultsBase instance. More...
fiftyoneDegreesResultsNoValueReason  getNoValueReason ()
Indicates the reason why valid values are not available. More...
const char *  getNoValueMessage ()
Gets a message explaining why there is no value. More...
T  getValue ()
Gets the value contained in the Value instance. More...
void  setValue (T value)
Set the value to be contained in the Value instance. More...
void  setNoValueReason (fiftyoneDegreesResultsNoValueReason reason, const char *message)
Set the reason there is no value available. More...

Operators

T  operator * ()
Gets the value contained in the Value instance. More...

Member Function Documentation

◆ getNoValueMessage()

template<class T>
const char* FiftyoneDegrees::Common::Value< T >::getNoValueMessage ( )
inline

Gets a message explaining why there is no value.

Calling this if hasValue() returned true will result in undefined behavior.

Returns
message explaining the reason for the missing value

◆ getValue()

template<class T>
T FiftyoneDegrees::Common::Value< T >::getValue ( )
inline

Gets the value contained in the Value instance.

If there is no valid value, then an exception will be thrown. To prevent an exception, the hasValue() method should be checked first.

Returns
value

◆ operator *()

template<class T>
T FiftyoneDegrees::Common::Value< T >::operator * ( )
inline

Gets the value contained in the Value instance.

If there is no valid value, then an exception will be thrown. To prevent an exception, the hasValue() method should be checked first.

Returns
value

◆ setNoValueReason()

template<class T>
void FiftyoneDegrees::Common::Value< T >::setNoValueReason ( fiftyoneDegreesResultsNoValueReason   reason,
const char *   message  
)
inline

Set the reason there is no value available.

This will be used if an exception is thrown by the setValue method.

Parameters
reason - the reason enum indicating why the value is missing
message - the message containing a fuller description on why the value is missing

The documentation for this class was generated from the following file:
  • /home/vsts/work/1/s/apis/device-detection-cxx/src/common-cxx/Value.hpp