libQuotient
A Qt library for building matrix clients
Quotient::EventTemplate< EventT, BaseEventT, ContentT > Class Template Reference

A template base class to derive your event type from. More...

#include <event.h>

Inheritance diagram for Quotient::EventTemplate< EventT, BaseEventT, ContentT >:
Collaboration diagram for Quotient::EventTemplate< EventT, BaseEventT, ContentT >:

Public Types

using content_type = ContentT
 

Public Member Functions

 EventTemplate (const QJsonObject &json)
 
 EventTemplate (const ContentT &c)
 
ContentT content () const
 

Detailed Description

template<typename EventT, EventClass BaseEventT, typename ContentT = void>
class Quotient::EventTemplate< EventT, BaseEventT, ContentT >

A template base class to derive your event type from.

This simple class template generates commonly used event constructor signatures and the content() method with the appropriate return type. The generic version here is only used with non-trivial ContentT (if you don't need to create an event from its content structure, just go and derive straight from the respective EventBaseT instead of using EventTemplate); specialisations may override that and provide useful semantics even without ContentT (see EventTemplate<CallEvent>, e.g.).

The template uses CRTP to pick the event type id from the actual class; it will fail to compile if EventT doesn't provide TypeId. It also uses the base event type's basicJson(); if you need extra keys to be inserted you may want to bypass this template as writing the code to that effect in your class will likely be clearer and more concise.

See also
https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
DEFINE_SIMPLE_EVENT

Definition at line 379 of file event.h.

Member Typedef Documentation

◆ content_type

template<typename EventT , EventClass BaseEventT, typename ContentT = void>
using Quotient::EventTemplate< EventT, BaseEventT, ContentT >::content_type = ContentT

Definition at line 390 of file event.h.

Constructor & Destructor Documentation

◆ EventTemplate() [1/2]

template<typename EventT , EventClass BaseEventT, typename ContentT = void>
Quotient::EventTemplate< EventT, BaseEventT, ContentT >::EventTemplate ( const QJsonObject &  json)
inlineexplicit

Definition at line 392 of file event.h.

◆ EventTemplate() [2/2]

template<typename EventT , EventClass BaseEventT, typename ContentT = void>
Quotient::EventTemplate< EventT, BaseEventT, ContentT >::EventTemplate ( const ContentT &  c)
inlineexplicit

Definition at line 395 of file event.h.

Member Function Documentation

◆ content()

template<typename EventT , EventClass BaseEventT, typename ContentT = void>
ContentT Quotient::EventTemplate< EventT, BaseEventT, ContentT >::content ( ) const
inline

Definition at line 399 of file event.h.


The documentation for this class was generated from the following file: