tdlib-obf API
Reference documentation for the public tdlib-obf API, generated from TDLib schemas and public headers
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

Definition in file TlObject.h.

Typedef Documentation

◆ tl_object_ptr

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

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

Definition at line 184 of file TlObject.h.

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::unique_ptr< Type > tl_object_ptr
Definition TlObject.h:184
std::vector< Type > array
Definition td_api.h:47
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.

Definition at line 202 of file TlObject.h.

202 {
203 return tl_object_ptr<Type>(new Type(std::forward<Args>(args)...));
204}

◆ 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.

Definition at line 259 of file TlObject.h.

259 {
260 return tl_object_ptr<ToT>(static_cast<ToT *>(from.release()));
261}

◆ 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()) {
auto state = td::move_tl_object_as<td::td_api::callStatePending>(call_state);
// use state
break;
}
// no additional fields, so cast isn't needed
break;
}
auto state = td::move_tl_object_as<td::td_api::callStateReady>(call_state);
// use state
break;
}
// no additional fields, so cast isn't needed
break;
}
auto state = td::move_tl_object_as<td::td_api::callStateDiscarded>(call_state);
// use state
break;
}
auto state = td::move_tl_object_as<td::td_api::callStateError>(call_state);
// use state
break;
}
default:
assert(false);
}
static const std::int32_t ID
Identifier uniquely determining a type of the object.
Definition td_api.h:7780
static const std::int32_t ID
Identifier uniquely determining a type of the object.
Definition td_api.h:7819
static const std::int32_t ID
Identifier uniquely determining a type of the object.
Definition td_api.h:7642
static const std::int32_t ID
Identifier uniquely determining a type of the object.
Definition td_api.h:7732
static const std::int32_t ID
Identifier uniquely determining a type of the object.
Definition td_api.h:7612
static const std::int32_t ID
Identifier uniquely determining a type of the object.
Definition td_api.h:7702
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.

Definition at line 251 of file TlObject.h.

251 {
252 return tl_object_ptr<ToT>(static_cast<ToT *>(from.release()));
253}