kDB: Knowledge DataBase
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
 
cres_qresult< bool > compare (const Value &_value, ComparisonOperators _operators) const
 
cres_qresult< Valueconvert (const Uri &_uri, TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
 
cres_qresult< Valuecompute (const Value &_value, ArithmeticOperator _operator) const
 
template<typename _T_ >
cres_qresult< _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
 
cres_qresult< QByteArray > md5 () const
 
cres_qresult< QJsonValue > toJsonValue (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
cres_qresult< QCborValue > toCborValue (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
cres_qresult< QString > toRdfLiteral (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
cres_qresult< QString > printable () const
 
cres_qresult< QJsonObject > toJsonObject (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
cres_qresult< QCborMap > toCborMap (const SerialisationContexts &_contexts=defaultSerialisationContext()) const
 
cres_qresult< ValueListtoList () const
 
cres_qresult< ValueHashtoHash () const
 

Static Public Member Functions

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

Friends

template<typename _T_ >
struct details::Value_value
 

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()

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

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

◆ compute()

cres_qresult< 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()

cres_qresult< 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()

cres_qresult< 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]

cres_qresult< 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_ >
cres_qresult< 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]

cres_qresult< 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]

cres_qresult< 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.

◆ parseVariant()

cres_qresult< Value > Value::parseVariant ( const QVariant & _value)
static

Attempt to parse a variant as a value. If the value is a hash, it might be parsed as a literal. So, a hash such as { "type": "literal", "datatype": "...", "value": "..."} will be returned as a value with the given value and datatype.

◆ toCborMap()

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

◆ toHash()

cres_qresult< ValueHash > Value::toHash ( ) const

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

◆ toJsonObject()

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

◆ toList()

cres_qresult< 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_ >
cres_qresult< _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: