libQuotient
A Qt library for building matrix clients
Quotient::Event Class Reference

#include <event.h>

Inheritance diagram for Quotient::Event:
Collaboration diagram for Quotient::Event:

Public Member Functions

virtual const AbstractEventMetaTypemetaType () const
 
 Event (Event &&) noexcept=default
 
Eventoperator= (Event &&)=delete
 
virtual ~Event ()
 
QString matrixType () const
 Exact Matrix type stored in JSON. More...
 
template<EventClass EventT>
bool is () const
 
template<typename... VisitorTs>
auto switchOnType (VisitorTs &&... visitors) const
 Apply one of the visitors based on the actual event type. More...
 
const QJsonObject & fullJson () const
 
const QJsonObject contentJson () const
 
template<typename T , typename KeyT >
const T contentPart (KeyT &&key) const
 Get a part of the content object, assuming a given type. More...
 
const QJsonObject unsignedJson () const
 
template<typename T , typename KeyT >
const T unsignedPart (KeyT &&key) const
 Get a part of the unsigned object, assuming a given type. More...
 
bool isStateEvent () const
 

Static Public Member Functions

static QJsonObject basicJson (const QString &matrixType, const QJsonObject &content)
 Make a minimal correct Matrix event JSON. More...
 

Static Public Attributes

static EventMetaType< EventBaseMetaType { "Event" }
 

Protected Member Functions

 Event (const QJsonObject &json)
 
QJsonObject & editJson ()
 
virtual void dumpTo (QDebug dbg) const
 

Friends

class EventMetaType< Event >
 
QUOTIENT_API QDebug operator<< (QDebug dbg, const Event &e)
 

Detailed Description

Definition at line 231 of file event.h.

Constructor & Destructor Documentation

◆ Event() [1/2]

Quotient::Event::Event ( Event &&  )
defaultnoexcept

◆ ~Event()

virtual Quotient::Event::~Event ( )
virtual

◆ Event() [2/2]

Quotient::Event::Event ( const QJsonObject &  json)
explicitprotected

Member Function Documentation

◆ basicJson()

static QJsonObject Quotient::Event::basicJson ( const QString &  matrixType,
const QJsonObject &  content 
)
inlinestatic

Make a minimal correct Matrix event JSON.

Definition at line 245 of file event.h.

◆ contentJson()

const QJsonObject Quotient::Event::contentJson ( ) const

◆ contentPart()

template<typename T , typename KeyT >
const T Quotient::Event::contentPart ( KeyT &&  key) const
inline

Get a part of the content object, assuming a given type.

This retrieves the value under content.<key> from the event JSON and then converts it to T using fromJson().

See also
contentJson, fromJson

Definition at line 308 of file event.h.

◆ dumpTo()

virtual void Quotient::Event::dumpTo ( QDebug  dbg) const
protectedvirtual

Reimplemented in Quotient::StateEvent, and Quotient::RoomEvent.

◆ editJson()

QJsonObject& Quotient::Event::editJson ( )
inlineprotected

Definition at line 344 of file event.h.

◆ fullJson()

const QJsonObject& Quotient::Event::fullJson ( ) const
inline

Definition at line 291 of file event.h.

◆ is()

template<EventClass EventT>
bool Quotient::Event::is ( ) const
inline

Definition at line 255 of file event.h.

◆ isStateEvent()

bool Quotient::Event::isStateEvent ( ) const

◆ matrixType()

QString Quotient::Event::matrixType ( ) const

Exact Matrix type stored in JSON.

◆ metaType()

virtual const AbstractEventMetaType& Quotient::Event::metaType ( ) const
inlinevirtual

Definition at line 234 of file event.h.

◆ operator=()

Event& Quotient::Event::operator= ( Event &&  )
delete

◆ switchOnType()

template<typename... VisitorTs>
auto Quotient::Event::switchOnType ( VisitorTs &&...  visitors) const
inline

Apply one of the visitors based on the actual event type.

This function uses function_traits template and is() to find the first of the passed visitor invocables that can be called with this event object, downcasting *this in a type-safe way to the most specific type accepted by the visitor. Without this function, you can still write a stack of, for example, (else) if (const auto* evtPtr = eventCast<...>(baseEvtPtr)) blocks but switchType() provides a more concise and isolating syntax: there's no else or trailing return/break to forget, for one. The visitors have to all return the same type (possibly void). Here's how you might use this function:

RoomEventPtr eptr = /* get the event pointer from somewhere */;
const auto result = eptr->switchOnType(
[](const RoomMemberEvent& memberEvent) {
// Do what's needed if eptr points to a RoomMemberEvent
return 1;
},
[](const CallEvent& callEvent) {
// Do what's needed if eptr points to a CallEvent or any
// class derived from it
return 2;
},
3); /* the default value to return if nothing above matched */
event_ptr_tt< RoomEvent > RoomEventPtr
Definition: roomevent.h:92

As the example shows, the last parameter can optionally be a plain returned value instead of a visitor.

Definition at line 579 of file event.h.

◆ unsignedJson()

const QJsonObject Quotient::Event::unsignedJson ( ) const

◆ unsignedPart()

template<typename T , typename KeyT >
const T Quotient::Event::unsignedPart ( KeyT &&  key) const
inline

Get a part of the unsigned object, assuming a given type.

This retrieves the value under unsigned.<key> from the event JSON and then converts it to T using fromJson().

See also
unsignedJson, fromJson

Definition at line 321 of file event.h.

Friends And Related Function Documentation

◆ EventMetaType< Event >

friend class EventMetaType< Event >
friend

Definition at line 336 of file event.h.

◆ operator<<

QUOTIENT_API QDebug operator<< ( QDebug  dbg,
const Event e 
)
friend

Definition at line 326 of file event.h.

Member Data Documentation

◆ BaseMetaType

EventMetaType<Event> Quotient::Event::BaseMetaType { "Event" }
inlinestatic

Definition at line 233 of file event.h.


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