TDLib
Loading...
Searching...
No Matches
TlObject.h File Reference
#include <cstddef>
#include <cstdint>
#include <string>
#include <type_traits>
#include <utility>

Go to the source code of this file.

Classes

class  td::TlObject

Typedefs

template<class Type>
using td::tl_object_ptr = tl::unique_ptr<Type>

Functions

template<class Type, class... Args>
tl_object_ptr< Type > td::make_tl_object (Args &&...args)
template<class ToT, class FromT>
tl_object_ptr< ToT > td::move_tl_object_as (tl_object_ptr< FromT > &from)
template<class ToT, class FromT>
tl_object_ptr< ToT > td::move_tl_object_as (tl_object_ptr< FromT > &&from)

Detailed Description

Contains the declarations of a base class for all TL-objects and some helper methods

Typedef Documentation

◆ tl_object_ptr

template<class Type>
using td::tl_object_ptr = tl::unique_ptr<Type>

A smart wrapper to store a pointer to a TL-object.

Function Documentation

◆ make_tl_object()

template<class Type, class... Args>
tl_object_ptr< Type > td::make_tl_object ( Args &&... args)

A function to create a dynamically allocated TL-object. Can be treated as an analogue of std::make_unique. Usage example:

auto get_me_request = td::make_tl_object<td::td_api::getMe>();
auto message_text = td::make_tl_object<td::td_api::formattedText>("Hello, world!!!",
auto send_message_request = td::make_tl_object<td::td_api::sendMessage>(chat_id, nullptr, nullptr, nullptr, nullptr,
td::make_tl_object<td::td_api::inputMessageText>(std::move(message_text), nullptr, true));
tl_object_ptr< Type > make_tl_object(Args &&...args)
Definition TlObject.h:202
tl::unique_ptr< Type > tl_object_ptr
Definition TlObject.h:184
Template Parameters
TypeType of the TL-object to construct.
Parameters
[in]argsArguments to pass to the object constructor.
Returns
Wrapped pointer to the created TL-object.

◆ move_tl_object_as() [1/2]

template<class ToT, class FromT>
tl_object_ptr< ToT > td::move_tl_object_as ( tl_object_ptr< FromT > && from)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ move_tl_object_as() [2/2]

template<class ToT, class FromT>
tl_object_ptr< ToT > td::move_tl_object_as ( tl_object_ptr< FromT > & from)

A function to downcast a wrapped pointer to a TL-object to a pointer to its subclass. Casting an object to an incorrect type will lead to undefined behaviour. Examples of usage:

switch (call_state->get_id()) {
case td::td_api::callStatePending::ID: {
// use state
break;
}
case td::td_api::callStateExchangingKeys::ID: {
// no additional fields, so cast isn't needed
break;
}
case td::td_api::callStateReady::ID: {
// use state
break;
}
case td::td_api::callStateHangingUp::ID: {
// no additional fields, so cast isn't needed
break;
}
case td::td_api::callStateDiscarded::ID: {
// use state
break;
}
case td::td_api::callStateError::ID: {
// use state
break;
}
default:
assert(false);
}
tl_object_ptr< ToT > move_tl_object_as(tl_object_ptr< FromT > &from)
Definition TlObject.h:251
Template Parameters
ToTType of TL-object to move to.
FromTType of TL-object to move from, this is auto-deduced.
Parameters
[in]fromWrapped pointer to a TL-object.