# class LiteralValue

###

Module | soprano
Namespace | Soprano
Class | LiteralValue
Inherits |

\class LiteralValue literalvalue.h Soprano/LiteralValue

Represents a literal value of an RDF Node.

LiteralValue is based on QVariant to support a subset of the XML Schema types that are compatible with QT types.

The following types are supported natively including automatic type conversion. Other types are represented as strings.

- int (Vocabulary.XMLSchema.xsdInt)
- qlonglong (Vocabulary.XMLSchema.xsdLong)
- unsigned int (Vocabulary.XMLSchema.unsignedInt)
- qulonglong (Vocabulary.XMLSchema.unsignedLong)
- bool (Vocabulary.XMLSchema.boolean)
- double and float (Vocabulary.XMLSchema.xsdDouble) (float values are always converted to double)
- QString (Vocabulary.XMLSchema.string or Vocabulary.RDF.XMLLiteral)
- QDate (Vocabulary.XMLSchema.date)
- QTime (Vocabulary.XMLSchema.time)
- QDateTime (Vocabulary.XMLSchema.dateTime)
- QByteArray (Vocabulary.XMLSchema.base64Binary)

Literal values can be converted from strings via fromString().

Be aware that string literals in %Soprano always have type xsd:string. There is no direct support for rdfs:Literal. Backend implementations should honour this restriction.

See also Vocabulary.XMLSchema

Author Sebastian Trueg <trueg@kde.org>

### methods

- LiteralValue ( )

  returns ctor

  Create an empty literal value

- LiteralValue (other)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  other | Soprano.LiteralValue |

  Default copy constructor

- LiteralValue (v)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  v | QVariant |

  Creates a new LiteralValue from a QVariant. User types are not supported. If v contains an unsupported type an invalid LiteralValue is created.

- LiteralValue (i)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  i | int |

  Creates a literal value of type int (i.e. http://www.w3.org/2001/XMLSchema#int)

- LiteralValue (i)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  i | qlonglong |

  Creates a literal value of type long long (i.e. http://www.w3.org/2001/XMLSchema#long)

- LiteralValue (i)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  i | uint |

  Creates a literal value of type unsigned int (i.e. http://www.w3.org/2001/XMLSchema#unsignedInt)

- LiteralValue (i)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  i | qulonglong |

  Creates a literal value of type unsigned long long (i.e. http://www.w3.org/2001/XMLSchema#unsignedLong)

- LiteralValue (b)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  b | bool |

  Creates a literal value of type bool (i.e. http://www.w3.org/2001/XMLSchema#boolean)

- LiteralValue (d)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  d | double |

  Creates a literal value of type double (i.e. http://www.w3.org/2001/XMLSchema#double)

- LiteralValue (string)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  string | char |

  Creates a literal value of type QString (i.e. http://www.w3.org/2001/XMLSchema#string)

  string - The value of the new literal interpreted as UTF-8 encoded string.

- LiteralValue (string)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  string | QLatin1String |

  Creates a literal value of type QString (i.e. http://www.w3.org/2001/XMLSchema#string)

- LiteralValue (string)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  string | QString |

  Creates a literal value of type QString (i.e. http://www.w3.org/2001/XMLSchema#string)

- LiteralValue (date)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  date | QDate |

  Creates a literal value of type QDate (i.e. http://www.w3.org/2001/XMLSchema#date)

- LiteralValue (time)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  time | QTime |

  Creates a literal value of type QTime (i.e. http://www.w3.org/2001/XMLSchema#time)

- LiteralValue (datetime)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  datetime | QDateTime |

  Creates a literal value of type QDateTime (i.e. http://www.w3.org/2001/XMLSchema#dateTime)

- LiteralValue (data)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  data | QByteArray |

  Creates a literal value of type QByteArray (i.e. http://www.w3.org/2001/XMLSchema#base64Binary)

- dataTypeUri ( )

  returns QUrl

  The XML Schema datatype URI.

  Returns The URI of the XML Schema type referring to the stored type or an empty QUrl if the LiteralValue is empty.

- dataTypeUriFromType (type)

  returns QUrl
  static

  Argument | Type | Default
  --- | --- | ---
  type | QVariant.Type |

  Convert a QVariant.Type into an XML Schema URI. Returns The XML Schema URI that corresponds to type or an empty QUrl if the type os unknown, i.e. can not be mapped to an XML Schema type.

- fromString (value, type)

  returns Soprano.LiteralValue
  static

  Argument | Type | Default
  --- | --- | ---
  value | QString |
  type | QVariant.Type |

  Create a LiteralValue object by parsing string value based on type. If type is unknown a simple string LiteralValue object is returned containing the plain string value.

  See also fromString(const QString&, const QUrl&)

- fromString (value, dataTypeUri)

  returns Soprano.LiteralValue
  static

  Argument | Type | Default
  --- | --- | ---
  value | QString |
  dataTypeUri | QUrl |

  Create a LiteralValue object by parsing string value based on dataTypeUri.

  value - The value of the literal. Might be converted based on dataTypeUri.

  dataTypeUri - The data type URI. %Soprano can automatically convert all XML schema types. All other (unknown) types will be stored as a string value with the plain dataTypeUri as type. Thus, unknown literal types can still be used without automatic type conversion. (Be aware though, that changing the value of a LiteralValue instance will reset the type, ie. custom data type URIs will be lost.)

  Both an empty value and dataTypeUri will result in an invalid LiteralValue instance but an empty value with a valid dataTypeUri is possible. A valid value with an invalid dataTypeUri will result in a LiteralValue of type Vocabulary.XMLSchema.string.

  Returns A newly created LiteralValue instance based on the provided value and dataTypeUri.

  See also fromString(const QString&, QVariant.Type), Vocabulary.XMLSchema

- isBool ( )

  returns bool

- isByteArray ( )

  returns bool

- isDate ( )

  returns bool

- isDateTime ( )

  returns bool

- isDouble ( )

  returns bool

- isInt ( )

  returns bool

- isInt64 ( )

  returns bool

- isString ( )

  returns bool

  Check if the literal contains a string value. Be aware that unknown literal types are also treated as strings. In that case compare dataTypeUrl.

- isTime ( )

  returns bool

- isUnsignedInt ( )

  returns bool

- isUnsignedInt64 ( )

  returns bool

- isValid ( )

  returns bool

- operator != (other)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  other | Soprano.LiteralValue |

- operator == (other)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  other | Soprano.LiteralValue |

- toBool ( )

  returns bool

- toByteArray ( )

  returns QByteArray

- toDate ( )

  returns QDate

- toDateTime ( )

  returns QDateTime

- toDouble ( )

  returns double

- toInt ( )

  returns int

- toInt64 ( )

  returns qlonglong

- toString ( )

  returns QString

  Each type can be converted to a string which means that toString in combination with dataTypeUrl provides all the information necessary to store this literal as RDF.

  The string value is cached so calling it multiple times in a row is fast.

- toTime ( )

  returns QTime

- toUnsignedInt ( )

  returns uint

- toUnsignedInt64 ( )

  returns qulonglong

- type ( )

  returns QVariant.Type

  The type of the data.

  Returns The QVariant type of the stored data or QVariant.Invalid if it is an empty value.

- typeFromDataTypeUri (dataTypeUri)

  returns QVariant.Type
  static

  Argument | Type | Default
  --- | --- | ---
  dataTypeUri | QUrl |

  Convert an XML Schema URI into a QVariant.Type. Returns The QVariant.Type corresponding to dataTypeUri or QVariant.Invalid if dataTypeUri is unknown.

- variant ( )

  returns QVariant

  The literal value represented in a QVariant. Be aware that the RDF typing information is lost in the converted variant.