Types

Type utilities and generic and typed interfaces to objects in a store.

stored::Function

template<typename T, typename Container>
class Function

A typed function in a store.

This class only works for functions with fixed-length arguments (see stored::Type::isFixed()). Otherwise, use stored::Variant.

A Function is very small (it contains two words). It is default copyable and assignable, so it is fine to pass it by value.

Public Types

typedef T type

The type of the function’s argument.

Public Functions

inline constexpr Function() noexcept

Constructor for an invalid Function.

inline constexpr Function(Container &container, unsigned int f) noexcept

Constructor for a valid Function.

template<typename U>
inline U as() const

Returns the value, like get(), cast to the given type.

Only call this function when it is valid().

inline size_t callback(bool set, type &value) const

Invoke the callback at the container().

inline size_t callback(bool set, void *buffer, size_t len) const

Invoke the callback at the container().

inline Container &container() const noexcept

Returns the container this Function belongs to.

Only call this function when it is valid().

inline type get() const

Calls the function and return its value.

Only call this function when it is valid().

inline size_t get(void *dst, size_t len) const

Calls the function and write its value in the given buffer.

Only call this function when it is valid().

Parameters:
  • dst – the buffer to write to

  • len – the length of dst, normally equal to size()

Returns:

the number of bytes written to dst

inline unsigned int id() const noexcept

Returns the function ID.

Only call this function when it is valid().

inline explicit operator type() const

Returns the value, which is identical to get().

inline bool operator!=(Function const &rhs) const noexcept

Checks if this Function points to the same Function as the given one.

inline type operator()() const

Call the function, like get().

inline void operator()(type value)

Call the function, like set().

inline Function &operator=(type v)

Sets the value, which is identical to set().

inline bool operator==(Function const &rhs) const noexcept

Checks if this Function points to the same Function as the given one.

inline void set(type value) const

Call the function to write the value.

Only call this function when it is valid().

inline size_t set(void *src, size_t len)

Call the function to write the value.

Only call this function when it is valid().

Parameters:
  • src – the buffer to read from

  • len – the length of src, normally equal to size()

Returns:

the number of bytes read from src

inline constexpr bool valid() const noexcept

Checks if this Function is valid.

Public Static Functions

static inline constexpr size_t size() noexcept

Returns the size of the function’s argument.

stored::toType

template<typename T>
struct toType

Returns the stored::Type::type that corresponds to the given type T.

Public Static Attributes

static Type::type const type = Type::Blob

stored::Variable

template<typename T, typename Container, bool Hooks = Config::EnableHooks>
class Variable

A typed variable in a store.

This class only works for fixed-length variables (see stored::Type::isFixed()). Otherwise, use stored::Variant.

A Variable is very small (it contains only a pointer). It is copyable and assignable, so it is fine to pass it by value.

Public Types

typedef T type

The (fixed-length) type of this variable.

Public Functions

inline constexpr Variable() noexcept

Constructor for an invalid Variable.

inline Variable(Container &container, type &buffer) noexcept

Constructor for a valid Variable.

Parameters:
  • container – the Container this Variable belongs to

  • buffer – the reference to this Variable’s buffer inside container’s buffer

inline Variable(Variable &&v) noexcept

Move-construct.

inline Variable(Variable const &v) noexcept

Copy construct, such that this Variable points to the same buffer the given Variable does.

~Variable() noexcept = default

Dtor.

template<typename U>
inline U as() const noexcept

Returns the value, like get(), cast to the given type.

Only call this function when it is valid().

Container &container() const

Returns the container this Variable belongs to.

inline type get() const noexcept

Returns the value.

Only call this function when it is valid().

inline explicit operator type() const noexcept

Returns the value, which is identical to get().

inline constexpr bool operator!=(Variable const &rhs) const noexcept

Checks if two Variables do not point to the same buffer.

inline Variable &operator=(type v) noexcept

Sets the value, which is identical to set().

inline Variable &operator=(Variable &&v) noexcept

Move-assign.

inline Variable &operator=(Variable const &v) noexcept

Let this Variable point to the same buffer as the given Variable.

inline constexpr bool operator==(Variable const &rhs) const noexcept

Checks if two Variables point to the same buffer, or are both invalid.

inline void set(type v) noexcept

Sets the value.

Only call this function when it is valid().

inline constexpr bool valid() const noexcept

Checks if this Variable points to a valid buffer.

Public Static Functions

static inline constexpr size_t size() noexcept

Returns the size of the data.

stored::Variable with hooks

template<typename T, typename Container>
class Variable<T, Container, true> : public stored::Variable<T, Container, false>

A typed variable in a store, with hook support.

This class only works for fixed-length variables (see stored::Type::isFixed()). Otherwise, use stored::Variant.

This Variable is very small (it contains two pointers). It is copyable and assignable, so it is fine to pass it by value.

Public Types

typedef Variable<T, Container, false> base
typedef base::type type

The (fixed-length) type of this variable.

Public Functions

inline constexpr Variable() noexcept

Constructor for an invalid Variable.

inline constexpr Variable(Container &container, type &buffer) noexcept

Constructor for a valid Variable.

Parameters:
  • container – the Container this Variable belongs to

  • buffer – the reference to this Variable’s buffer inside container’s buffer

inline Variable(Variable &&v) noexcept

Move-construct.

inline Variable(Variable const &v) noexcept

Copy construct, such that this Variable points to the same buffer the given Variable does.

inline ~Variable() noexcept

Dtor.

template<typename U>
inline U as() const noexcept

Returns the value, like get(), cast to the given type.

Only call this function when it is valid().

inline Container &container() const noexcept

Returns the container this Variable belongs to.

inline void entryRO() const noexcept

Calls the entryRO() hook of the container.

See also

your store’s hookEntryRO()

inline void entryX() const noexcept

Calls the entryX() hook of the container.

See also

your store’s hookEntryX()

inline void exitRO() const noexcept

Calls the exitRO() hook of the container.

See also

your store’s hookExitRO()

inline void exitX(bool changed) const noexcept

Calls the exitX() hook of the container.

See also

your store’s hookExitX()

inline type get() const noexcept

Returns the value.

Only call this function when it is valid().

entryRO()/exitRO() are called around the actual data retrieval.

inline Container::Key key() const noexcept

Returns the key that belongs to this Variable.

See also

your store’s bufferToKey()

inline explicit operator type() const noexcept

Returns the value, which is identical to get().

inline Variable &operator=(type v) noexcept

Sets the value, which is identical to set().

inline Variable &operator=(Variable &&v) noexcept

Move-assign.

inline Variable &operator=(Variable const &v) noexcept

Let this Variable point to the same buffer as the given Variable.

inline void set(type v) noexcept

Sets the value.

Only call this function when it is valid().

entryX()/exitX() are called around the actual data retrieval.

Public Static Functions

static inline constexpr size_t size() noexcept

Returns the size of the data.

stored::Variant

template<typename Container>
class Variant

A untyped interface to an object in a store.

This class works for all variables and functions of all types. However, using stored::Variable or stored::Function is more efficient both in performance and memory. Use those when you can.

A Variant is quite small (only about four words). It is default copyable and assignable, so it is fine to pass it by value.

Public Functions

inline constexpr Variant() noexcept

Constructor for an invalid Variant.

inline Variant(Container &container, Type::type type, unsigned int f, size_t len) noexcept

Constructor for a function.

inline Variant(Container &container, Type::type type, void *buffer, size_t len) noexcept

Constructor for a variable.

template<typename T>
inline explicit constexpr Variant(Function<T, Container> const &f) noexcept

Constructor for a Function.

template<typename T>
inline explicit constexpr Variant(Variable<T, Container> const &v) noexcept

Constructor for a Variable.

inline void *buffer() const noexcept

Returns the buffer.

Only call this function when it is valid().

inline size_t callback(bool set, void *buffer, size_t len) const

Invoke the function callback.

Only works if this variant is a function.

inline Container &container() const noexcept

Returns the container.

Only call this function when it is valid().

template<typename C>
inline void copy(Variant<C> const &other) noexcept

Copies data from a Variant from another Container.

This copies data directly, without type conversion. This may come in handy when data of the same variable of different stores (or between stores with different wrappers) should be copied.

Only use this when:

  • this and other are valid()

  • this and other are not equal

  • this and other have the same type()

  • this and other have the same size()

  • this and other are variables

inline void entryRO() const noexcept

Invokes hookEntryRO() on the container().

inline void entryRO(size_t len) const noexcept

Invokes hookEntryRO() on the container().

inline void entryX() const noexcept

Invokes hookEntryX() on the container().

inline void entryX(size_t len) const noexcept

Invokes hookEntryX() on the container().

inline void exitRO() const noexcept

Invokes hookExitRO() on the container().

inline void exitRO(size_t len) const noexcept

Invokes hookExitRO() on the container().

inline void exitX(bool changed) const noexcept

Invokes hookExitX() on the container().

inline void exitX(bool changed, size_t len) const noexcept

Invokes hookExitX() on the container().

template<typename T>
inline Function<T, Container> function() const noexcept

Returns a stored::Function that corresponds to this Variant.

Only call this function when it isFunction() and the type() matches T.

template<typename T>
inline T get() const

Wrapper for get(void*,size_t) const that converts the type.

This only works for fixed types. Make sure that type() matches T.

inline Vector<char>::type get() const

Gets the value.

inline size_t get(void *dst, size_t len = 0) const

Get the value.

For variables, entryRO()/exitRO() is called.

In case type() is Type::String, only up to the first null byte are copied. If dst is sufficiently large (len > size()), a null terminator is always written after the string.

Only call this function when valid().

Parameters:
  • dst – the buffer to copy to

  • len – the length of dst, when this is a fixed type, 0 implies the normal size

Returns:

the number of bytes written into dst

inline bool isFunction() const noexcept

Checks if the type() is a function.

Only call this function when it is valid().

inline bool isVariable() const noexcept

Checks if the type() is a variable.

Only call this function when it is valid().

inline Container::Key key() const noexcept

Returns the key of this variable.

Only call this function when it isVariable().

See also

your store’s bufferToKey()

inline bool operator!=(Variant const &rhs) const noexcept

Checks if this Variant points to the same object as the given one.

inline bool operator==(Variant const &rhs) const noexcept

Checks if this Variant points to the same object as the given one.

inline void set(char const *data)

Sets a string.

Only works if this variant is a string.

inline void set(QString const &value)

Sets a string.

Only works if this variant is a string.

inline bool set(QVariant const &v)

Set the value, given a QVariant.

Returns:

true upon success

template<typename T>
inline void set(T value)

Wrapper for set(void const*,size_t) that converts the type.

This only works for fixed types. Make sure that type() matches T.

inline void set(Vector<char>::type const &data)

Sets the value.

inline size_t set(void const *src, size_t len = 0)

Set the value.

For variables, entryX()/exitX() is called.

In case type() is Type::String, only up to the first null byte are copied. If there is no null byte in src, it is implicitly appended at the end.

Only call this function when valid().

Parameters:
  • src – the buffer to copy from

  • len – the length of src, when this is a fixed type, 0 implies the normal size

Returns:

the number of bytes read from src

inline size_t size() const noexcept

Returns the size.

In case type() is Type::String, this returns the maximum size of the string, excluding null terminator.

Only call this function when it is valid().

inline QString toQString() const

Convert the value to a QString.

Only works if the type() is String.

inline QVariant toQVariant() const

Convert the value to a QVariant.

inline Type::type type() const noexcept

Returns the type.

Only call this function when it is valid().

inline constexpr bool valid() const noexcept

Checks if this Variant is valid.

template<typename T>
inline Variable<T, Container> variable() const noexcept

Returns a stored::Variable that corresponds to this Variant.

Only call this function when it isVariable() and the type() matches T.

Public Members

void *m_buffer

The buffer for a variable.

uintptr_t m_f

The function ID for a function.

stored::Variant<void>

template<>
class Variant<void>

A store-independent untyped wrapper for an object.

It is not usable, until it is applied to a store. All member functions, except for apply() are there to match the Variant’s interface, but are non-functional, as there is no container.

See also

apply()

Public Functions

inline constexpr Variant() noexcept

Constructor for an invalid Variant.

inline constexpr Variant(Type::type type, uintptr_t buffer_offset_or_f, size_t len) noexcept

Constructor for a variable or function.

template<typename Container>
inline Variant<Container> apply(Container &container) const noexcept

Apply the stored object properties to a container.

inline int &container() const noexcept

Don’t use.

inline void entryRO(size_t len = 0) const noexcept

Don’t use.

inline void entryX(size_t len = 0) const noexcept

Don’t use.

inline void exitRO(size_t len = 0) const noexcept

Don’t use.

inline void exitX(bool changed, size_t len = 0) const noexcept

Don’t use.

template<typename T, typename Container>
inline constexpr FreeFunction<T, Container> function() const noexcept

Get the typed function corresponding to this variant, which is not bound to a specific store yet.

template<typename T, typename Container>
inline Variable<T, Container> function(Container &container) const noexcept

Get the typed function corresponding to this variant.

template<typename T>
inline T get() const noexcept

Don’t use.

inline size_t get(void *dst, size_t len = 0) const noexcept

Don’t use.

inline constexpr bool isFunction() const noexcept

Checks if the type() is a function.

inline constexpr bool isVariable() const noexcept

Checks if the type() is a variable.

inline bool operator!=(Variant const &rhs) const noexcept

Checks if this Variant points to the same object as the given one.

inline bool operator==(Variant const &rhs) const noexcept

Checks if this Variant points to the same object as the given one.

template<typename T>
inline void set(T value) noexcept

Don’t use.

inline size_t set(void const *src, size_t len = 0) noexcept

Don’t use.

inline constexpr size_t size() const noexcept

Returns the size.

inline constexpr Type::type type() const noexcept

Returns the type.

inline constexpr bool valid() const noexcept

Checks if this Variant is valid.

template<typename T, typename Container>
inline constexpr FreeVariable<T, Container> variable() const noexcept

Get the typed variable corresponding to this variant, which is not bound to a specific store yet.

template<typename T, typename Container>
inline Variable<T, Container> variable(Container &container) const noexcept

Get the typed variable corresponding to this variant.