Skip to content
Nicuvëo edited this page Mar 29, 2014 · 2 revisions

A value object is a wrapper around some sqlite3 data. It is implemented using a boost::variant, which is a kind of type-safe union. Variants provide a visitor-based API, which is used here for data conversion.

Such a value is either:

  • an Integer,
  • a Float,
  • some Text,
  • a Blob,
  • or Null (lack of value).

See the types page for more information about those underlying types.

class Value : public boost::variant<Null, Integer, Float, Text, Blob>
{
};

--

Constructors

Name Description
Value(Integer x) Creates a Integer Value instance (implicitly).
Value(int x) Creates a Integer Value instance (implicitly).
Value(Float x) Creates a Float Value instance (implicitly).
Value(float x) Creates a Float Value instance (implicitly).
Value(Text x) Creates a Text Value instance (implicitly).
Value(const char* x) Creates a Text Value instance (implicitly).
Value(Blob x) Creates a Blob Value instance (implicitly).
Value(Null x) Creates a Null Value instance (implicitly).
Value() Creates a Null Value instance.

--

Value info

Name Description
bool null() const Tells whether the object is Null or not.

--

Value conversion

Name Description
template <typename T> Integer as_integer(T const& cvert) const Applies visitor, enforces Integer conversion
template <typename T> Float as_float(T const& cvert) const Applies visitor, enforces Float conversion
template <typename T> Text as_text(T const& cvert) const Applies visitor, enforces Text conversion
template <typename T> Blob as_blob(T const& cvert) const Applies visitor, enforces Blob conversion
template <typename T> T as() const Applies default T converter
Integer as_integer() const Applies default Integer converter
Float as_float() const Applies default Float converter
Text as_text() const Applies default Text converter
Blob as_blob() const Applies default Blob converter

--

Generic visitor API

Name Description
template <typename T> typename T::result_type apply(T const& vtor) const Applies visitor

--

Default converters

Name Description
static Integer to_integer(Integer const& x) id
static Integer to_integer(Float const& x) static cast
static Integer to_integer(Text const& x) lexical cast
static Integer to_integer(Blob const& x) to_integer(to_text(x))
static Integer to_integer(Null const& x) Integer(0)
static Float to_float(Integer const& x) static cast
static Float to_float(Float const& x) id
static Float to_float(Text const& x) lexical cast
static Float to_float(Blob const& x) to_float(to_text(x))
static Float to_float(Null const& x) Float(0)
static Text to_text(Integer const& x) lexical cast
static Text to_text(Float const& x) lexical cast
static Text to_text(Text const& x) id
static Text to_text(Blob const& x) reads blob as char array
static Text to_text(Null const& x) empty string
static Blob to_blob(Integer const& x) to_blob(to_text(x))
static Blob to_blob(Float const& x) to_blob(to_text(x))
static Blob to_blob(Text const& x) dumps text as char array
static Blob to_blob(Blob const& x) id
static Blob to_blob(Null const& x) empty blob