libQuotient
A Qt library for building matrix clients
|
#include "single_key_value.h"
#include <Quotient/converters.h>
#include <Quotient/function_traits.h>
#include <span>
Go to the source code of this file.
Classes | |
class | Quotient::AbstractEventMetaType |
The base class for event metatypes. More... | |
class | Quotient::EventMetaType< EventT > |
A family of event meta-types to load and match events. More... | |
class | Quotient::Event |
class | Quotient::EventTemplate< EventT, BaseEventT, ContentT > |
A template base class to derive your event type from. More... | |
Namespaces | |
Quotient | |
Macros | |
#define | QUO_BASE_EVENT(CppType_, BaseCppType_, ...) |
Supply event metatype information in base event types. More... | |
#define | QUO_EVENT(CppType_, MatrixType_) |
Supply event metatype information in (specific) event types. More... | |
#define | QUO_CONTENT_GETTER_X(PartType_, PartName_, JsonKey_) |
#define | QUO_CONTENT_GETTER(PartType_, PartName_) QUO_CONTENT_GETTER_X(PartType_, PartName_, toSnakeCase(#PartName_##_L1)) |
Define an inline method obtaining a content part. More... | |
#define | DEFINE_SIMPLE_EVENT(Name_, Base_, TypeId_, ValueType_, GetterName_, JsonKey_) |
Define a new event class with a single key-value pair in the content. More... | |
Typedefs | |
template<typename EventT > | |
using | Quotient::event_ptr_tt = std::unique_ptr< EventT > |
using | Quotient::event_type_t = QLatin1String |
using | Quotient::EventPtr = event_ptr_tt< Event > |
template<EventClass EventT> | |
using | Quotient::EventsArray = std::vector< event_ptr_tt< EventT > > |
using | Quotient::Events = EventsArray< Event > |
Functions | |
template<EventClass EventT> | |
bool | Quotient::is (const Event &e) |
bool | Quotient::operator== (const AbstractEventMetaType &lhs, const AbstractEventMetaType &rhs) |
template<EventClass EventT, typename... ArgTs> | |
event_ptr_tt< EventT > | Quotient::makeEvent (ArgTs &&... args) |
Create an event of arbitrary type from its arguments. More... | |
template<EventClass EventT> | |
constexpr const auto & | Quotient::mostSpecificMetaType () |
template<EventClass EventT> | |
event_ptr_tt< EventT > | Quotient::loadEvent (const QJsonObject &fullJson) |
Create an event with proper type from a JSON object. More... | |
template<EventClass EventT> | |
event_ptr_tt< EventT > | Quotient::loadEvent (const QString &matrixType, const auto &... otherBasicJsonParams) |
Create an event from a type string and content JSON. More... | |
template<EventClass EventT, typename BasePtrT > | |
auto | Quotient::eventCast (const BasePtrT &eptr) -> decltype(static_cast< EventT * >(std::to_address(eptr))) |
Cast the event pointer down in a type-safe way. More... | |
template<EventClass EventT, typename BaseEventT > | |
auto | Quotient::eventCast (event_ptr_tt< BaseEventT > &&eptr) |
Cast the event pointer down in a type-safe way, with moving. More... | |
template<EventClass BaseT, typename TailT > | |
auto | Quotient::switchOnType (const BaseT &event, TailT &&tail) |
template<typename FnT1 , typename... FnTs> | |
auto | Quotient::switchOnType (const EventClass auto &event, FnT1 &&fn1, FnTs &&... fns) |
Variables | |
constexpr auto | Quotient::TypeKey = "type"_L1 |
constexpr auto | Quotient::ContentKey = "content"_L1 |
constexpr auto | Quotient::SenderKey = "sender"_L1 |
constexpr auto | Quotient::UnsignedKey = "unsigned"_L1 |
template<typename EventT , typename BaseEventT = Event> | |
concept | Quotient::EventClass = std::derived_from<EventT, BaseEventT> |
#define DEFINE_SIMPLE_EVENT | ( | Name_, | |
Base_, | |||
TypeId_, | |||
ValueType_, | |||
GetterName_, | |||
JsonKey_ | |||
) |
Define a new event class with a single key-value pair in the content.
This macro defines a new event class Name_
derived from Base_
, with Matrix event type TypeId_
, providing a getter named GetterName_
for a single value of type ValueType_
inside the event content. To retrieve the value the getter uses a JSON key name that corresponds to its own (getter's) name but written in snake_case. GetterName_
must be in camelCase, no quotes (an identifier, not a literal).
#define QUO_BASE_EVENT | ( | CppType_, | |
BaseCppType_, | |||
... | |||
) |
Supply event metatype information in base event types.
Use this macro in a public section of your base event class to provide type identity and enable dynamic loading of generic events of that type. Do not add this macro if your class is an intermediate wrapper and is not supposed to be instantiated on its own. Provides BaseMetaType static field initialised by parameters passed to the macro, and a metaType() override pointing to that BaseMetaType.
#define QUO_CONTENT_GETTER | ( | PartType_, | |
PartName_ | |||
) | QUO_CONTENT_GETTER_X(PartType_, PartName_, toSnakeCase(#PartName_##_L1)) |
Define an inline method obtaining a content part.
This macro adds a const method that extracts a JSON value at the key toSnakeCase(PartName_)
(sic) and converts it to the type PartType_
. Effectively, the generated method is an equivalent of
#define QUO_CONTENT_GETTER_X | ( | PartType_, | |
PartName_, | |||
JsonKey_ | |||
) |
#define QUO_EVENT | ( | CppType_, | |
MatrixType_ | |||
) |
Supply event metatype information in (specific) event types.
Use this macro in a public section of your event class to provide type identity and enable dynamic loading of generic events of that type. Do not use this macro if your class is an intermediate wrapper and is not supposed to be instantiated on its own. Provides MetaType static field initialised as described below; a metaType() override pointing to it; and the TypeId static field that is equal to MetaType.matrixId.
The first two macro parameters are used as the first two EventMetaType constructor parameters; the third EventMetaType parameter is always BaseMetaType; and additional base types can be passed in extra macro parameters if you need to include the same event type in more than one event factory hierarchy (e.g., EncryptedEvent).