knowL: Knowledge Libraries
Loading...
Searching...
No Matches
knowCore::Value Class Reference
Inheritance diagram for knowCore::Value:

Classes

struct  Private
 

Public Member Functions

 Value ()
 
 Value (const Value &_rhs)
 
Valueoperator= (const Value &_rhs)
 
QVariant toVariant () const
 
Uri datatype () const
 
bool isEmpty () const
 
bool operator< (const Value &_rhs) const
 
bool operator== (const Value &_rhs) const
 
bool operator!= (const Value &_rhs) const
 
ReturnValue< bool > compare (const Value &_value, ComparisonOperators _operators) const
 
ReturnValue< Valueconvert (const Uri &_uri, TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
 
ReturnValue< Valuecompute (const Value &_value, ArithmeticOperator _operator) const
 
template<typename _T_ >
ReturnValue< _T_ > value (TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
 
template<typename _T_ >
_T_ value (const _T_ &_default, TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
 
template<typename _T_ >
bool canConvert (TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
 
bool canConvert (const Uri &_uri, TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
 
template<typename _T_ >
bool is () const
 
ReturnValue< QByteArray > md5 () const
 
ReturnValue< QJsonValue > toJsonValue (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
ReturnValue< QCborValue > toCborValue (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
ReturnValue< QString > toRdfLiteral (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
ReturnValue< QString > printable () const
 
ReturnValue< QJsonObject > toJsonObject (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
ReturnValue< QCborMap > toCborMap (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
ReturnValue< ValueListtoList () const
 
ReturnValue< ValueHashtoHash () const
 

Static Public Member Functions

template<typename _T_ >
static Value fromValue (const _T_ &_value)
 
static ReturnValue< ValuefromValue (const QVariant &_value)
 
template<typename _T_ >
static ReturnValue< ValuefromValue (const Uri &_datatype, const _T_ &_value, TypeCheckingMode _conversion=TypeCheckingMode::Safe)
 
static ReturnValue< ValuefromVariant (const Uri &_datatype, const QVariant &_value, TypeCheckingMode _conversion=TypeCheckingMode::Safe)
 
static ReturnValue< ValuefromVariant (const QVariant &_variant)
 
static ReturnValue< ValuefromJsonValue (const Uri &_datatype, const QJsonValue &_value, const DeserialisationContexts &_context=defaultDeserialisationContext())
 
template<typename _T_ >
static ReturnValue< _T_ > fromJsonValue (const QJsonValue &_value, const DeserialisationContexts &_context=defaultDeserialisationContext())
 
static ReturnValue< ValuefromCborValue (const Uri &_datatype, const QCborValue &_value, const DeserialisationContexts &_context=defaultDeserialisationContext())
 
static ReturnValue< ValuefromRdfLiteral (const Uri &_datatype, const QString &_value, const DeserialisationContexts &_context=defaultDeserialisationContext())
 
static ReturnValue< ValuefromJsonObject (const QJsonObject &_value, const DeserialisationContexts &_context=defaultDeserialisationContext())
 
static ReturnValue< ValuefromCborMap (const QCborMap &_value, const DeserialisationContexts &_context=defaultDeserialisationContext())
 
template<>
ReturnValue< ValuefromValue (const Uri &_datatype, const QVariant &_value, TypeCheckingMode _conversion)
 

Constructor & Destructor Documentation

◆ Value()

Value::Value ( )

Construct an empty value

Member Function Documentation

◆ canConvert() [1/2]

bool Value::canConvert ( const Uri & _uri,
TypeCheckingMode _conversion = TypeCheckingMode::Safe ) const
Returns
true if this value can be converted to the type identified by
Parameters
_uri.

◆ canConvert() [2/2]

template<typename _T_ >
bool knowCore::Value::canConvert ( TypeCheckingMode _conversion = TypeCheckingMode::Safe) const
inline
Returns
true if it is possible to convert

◆ compare()

ReturnValue< bool > Value::compare ( const Value & _value,
ComparisonOperators _operators ) const

Compare two values. With different operators, if one returns true then compare return true.

◆ compute()

ReturnValue< Value > Value::compute ( const Value & _value,
ArithmeticOperator _operator ) const

Compute the arithmetic operation between this value and _value.

◆ datatype()

Uri Value::datatype ( ) const
Returns
the URI corresponding to the datatype

◆ fromCborMap()

ReturnValue< Value > Value::fromCborMap ( const QCborMap & _value,
const DeserialisationContexts & _context = defaultDeserialisationContext() )
static
Returns
a value from a cbor map that contains the datatype and the value (i.e. one created with toCborMap).

◆ fromJsonObject()

ReturnValue< Value > Value::fromJsonObject ( const QJsonObject & _value,
const DeserialisationContexts & _context = defaultDeserialisationContext() )
static
Returns
a value from a json object that contains the datatype and the value (i.e. one created with toJsonObject).

◆ fromValue() [1/3]

template<typename _T_ >
Value knowCore::Value::fromValue ( const _T_ & _value)
inlinestatic

Create a Value from any value _value. The type of _value needs to be register in knowCore's metatype system. This function will guess the data type uri.

◆ fromValue() [2/3]

ReturnValue< Value > knowCore::Value::fromValue ( const QVariant & _value)
inlinestatic

Attempt to create a Value from a variant _value. The type of _value needs to be register in knowCore's metatype system, if it is not, the function return an error.

◆ fromValue() [3/3]

template<typename _T_ >
ReturnValue< Value > knowCore::Value::fromValue ( const Uri & _datatype,
const _T_ & _value,
TypeCheckingMode _conversion = TypeCheckingMode::Safe )
inlinestatic

Create a Value from any value _value. The type of _value needs to be register in knowCore's metatype system. This function will use the datatype _datatype and attempt to convert _value into _datatype.

◆ fromVariant() [1/2]

ReturnValue< Value > Value::fromVariant ( const QVariant & _variant)
static

Construct a value from a variant. If the type of the variant is not defined as a knowCore MetaType, it will return an invalid value.

◆ fromVariant() [2/2]

ReturnValue< Value > Value::fromVariant ( const Uri & _datatype,
const QVariant & _value,
TypeCheckingMode _conversion = TypeCheckingMode::Safe )
static

Construct a literal from a variant

Parameters
_datatypethe type of the literal
_valuea variant with the value

This attempt to convert the variant content to the dataype, if it fails, it returns an invalid value.

◆ isEmpty()

bool Value::isEmpty ( ) const
Returns
true if it is empty

◆ operator!=()

bool knowCore::Value::operator!= ( const Value & _rhs) const
inline

Inequality comparison, it can only compare value of the same type.

◆ operator<()

bool Value::operator< ( const Value & _rhs) const

This operator use the printable result, it should only be used for storing values in a container. If you want proper comparison between the value you should use the compare function.

◆ operator==()

bool Value::operator== ( const Value & _rhs) const

Equality comparison, it can only compare value of the same type.

◆ toCborMap()

ReturnValue< QCborMap > Value::toCborMap ( const SerialisationContexts & _contexts = defaultSerialisationContext()) const
Returns
a cbor map that contains the datatype and the value.

◆ toHash()

ReturnValue< ValueHash > Value::toHash ( ) const

This is a convenient function for value<ValueHash>() .

◆ toJsonObject()

ReturnValue< QJsonObject > Value::toJsonObject ( const SerialisationContexts & _contexts = defaultSerialisationContext()) const
Returns
a json object that contains the datatype and the value.

◆ toList()

ReturnValue< ValueList > Value::toList ( ) const

This is a convenient function for value<ValueList>() .

◆ toVariant()

QVariant Value::toVariant ( ) const
Returns
convert to a variant

◆ value() [1/2]

template<typename _T_ >
_T_ knowCore::Value::value ( const _T_ & _default,
TypeCheckingMode _conversion = TypeCheckingMode::Safe ) const
inline

Convenient function to access the value or a default one if the stored value and _T_ are not compatible.

Returns
the value contained in the literal (no error is triggered if the type is wrong, instead a default value is returned)

◆ value() [2/2]

template<typename _T_ >
ReturnValue< _T_ > knowCore::Value::value ( TypeCheckingMode _conversion = TypeCheckingMode::Safe) const
inline

Function to access the value stored .

Returns
the value if successfull, or an error message if the value cannot be converted

The documentation for this class was generated from the following files: