morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
records.hpp File Reference
#include <cassert>
#include <cstddef>
#include <glaze/glaze.hpp>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
#include <typeindex>
#include <utility>
#include <vector>
#include "../detail/reflected_member.hpp"
#include "model_key.hpp"
#include "registry.hpp"

Go to the source code of this file.

Classes

struct  morph::record::key< Member >
 Option for BRIDGE_REGISTER_RECORD: the record's key is the named member instead of id. More...
struct  morph::record::keyless
 Option for BRIDGE_REGISTER_RECORD: the record has no key. More...
struct  morph::record::derivedFrom< S >
 Option for BRIDGE_REGISTER_RECORD: a change to any of S is a change to this record type. More...
struct  morph::record::privateKeys
 Option for BRIDGE_REGISTER_RECORD: the record's keys must not reach other principals. More...
struct  morph::record::RecordInfo
 What one BRIDGE_REGISTER_RECORD declared. More...
struct  morph::record::detail::KeyOption< T >
 Detects a key<> option and exposes its member pointer. More...
struct  morph::record::detail::IsDerivedFrom< T >
 Detects a derivedFrom<> option. More...

Macros

#define BRIDGE_REGISTER_RECORD(T, NAME, ...)
 Registers a record type under a wire name, with optional key, derivation and privacy options.

Functions

template<typename K>
constexpr bool morph::record::detail::keyTypeIsString ()
 Whether a key member's raw type is std::string, looking through a wrapped strong id.
template<typename Class, typename Member>
std::string morph::record::detail::memberKeyName (Member Class::*member)
 The reflected name of a data member, found by its address in a value-initialised object.
template<typename T>
constexpr std::size_t morph::record::detail::idIndex ()
 The index of the reflected member named id, or size when there is none.
template<typename T, typename... Opts>
void morph::record::detail::applyKey (RecordInfo &info)
 Fills the key fields of info from the options.
std::vector< RecordInfo > & morph::record::detail::mutableRecordRegistry ()
 The process-level record list, appended to by static registrars.
std::vector< RecordInfo > const & morph::record::detail::recordRegistry ()
 The records declared so far, raw and unvalidated.
template<typename T, typename... Opts>
bool morph::record::detail::registerRecordOnce (std::string_view name) noexcept
 Static-init helper for BRIDGE_REGISTER_RECORD.

Detailed Description

The registry of record types: the rows a server can push changes about.

A record is a plain reflected struct identified by a key member. Registration is a static registrar, like an action's, so it is checked by the same registration-phase latch. The registry stores what was declared; cross-entry validation (duplicate names, derivation cycles, keyless records that an effect names) happens when the registry is read for matching, not here.

Definition in file records.hpp.

Macro Definition Documentation

◆ BRIDGE_REGISTER_RECORD

#define BRIDGE_REGISTER_RECORD ( T,
NAME,
... )
Value:
namespace { \
[[maybe_unused]] const bool BRIDGE_DETAIL_CAT(bridge_record_reg_, __COUNTER__) = \
morph::record::detail::registerRecordOnce<T __VA_OPT__(, ) __VA_ARGS__>(NAME); \
}

Registers a record type under a wire name, with optional key, derivation and privacy options.

The key defaults to the member reflected as id. Options are morph::record::key<&T::m>, morph::record::keyless, morph::record::derivedFrom<S...> and morph::record::privateKeys. Expands to nothing under MORPH_CLIENT_ONLY.

Parameters
TThe record type.
NAMEThe record's wire name.
...The options.

Definition at line 239 of file records.hpp.

Function Documentation

◆ keyTypeIsString()

template<typename K>
bool morph::record::detail::keyTypeIsString ( )
constexpr

Whether a key member's raw type is std::string, looking through a wrapped strong id.

Template Parameters
KThe key member's type.
Returns
True when the raw key type is std::string.

Definition at line 100 of file records.hpp.

◆ memberKeyName()

template<typename Class, typename Member>
std::string morph::record::detail::memberKeyName ( Member Class::* member)
nodiscard

The reflected name of a data member, found by its address in a value-initialised object.

Template Parameters
ClassThe record type.
MemberThe member's type.
Parameters
memberThe member.
Returns
The glaze JSON key of the member, or empty when glaze does not reflect it.

Definition at line 115 of file records.hpp.

◆ idIndex()

template<typename T>
std::size_t morph::record::detail::idIndex ( )
constexpr

The index of the reflected member named id, or size when there is none.

Template Parameters
TThe record type.
Returns
The index, or glz::reflect<T>::keys.size() when no member is named id.

Definition at line 137 of file records.hpp.

◆ applyKey()

template<typename T, typename... Opts>
void morph::record::detail::applyKey ( RecordInfo & info)

Fills the key fields of info from the options.

Template Parameters
TThe record type.
OptsThe options.
Parameters
infoThe entry being built.

Definition at line 152 of file records.hpp.

◆ mutableRecordRegistry()

std::vector< RecordInfo > & morph::record::detail::mutableRecordRegistry ( )
inline

The process-level record list, appended to by static registrars.

Returns
The mutable list.

Definition at line 184 of file records.hpp.

◆ recordRegistry()

std::vector< RecordInfo > const & morph::record::detail::recordRegistry ( )
inline

The records declared so far, raw and unvalidated.

Returns
The entries in registration order.

Definition at line 191 of file records.hpp.

◆ registerRecordOnce()

template<typename T, typename... Opts>
bool morph::record::detail::registerRecordOnce ( std::string_view name)
inlinenoexcept

Static-init helper for BRIDGE_REGISTER_RECORD.

Template Parameters
TThe record type.
OptsAny of key<>, keyless, derivedFrom<>, privateKeys.
Parameters
nameThe record's wire name.
Returns
Always true, so the result can initialise a namespace-scope variable.

Definition at line 199 of file records.hpp.