Classes | Typedefs | Functions
TlObject.h File Reference

Description

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

Go to the source code of this file.

Classes

class  TlObject
 

Typedefs

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

Functions

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

Typedef Documentation

◆ tl_object_ptr

using tl_object_ptr = tl::unique_ptr<Type>

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

Function Documentation

◆ make_tl_object()

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, 0, nullptr, nullptr, nullptr,
td::make_tl_object<td::td_api::inputMessageText>(std::move(message_text), nullptr, true));
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]

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);
}
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.

◆ move_tl_object_as() [2/2]

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.