From f08c0180b4b2d6fe6a1a1d73c892a3fbc4e481eb Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 21 Sep 2018 20:52:22 +0300 Subject: [PATCH] Const-correct tl::unique_ptr. GitOrigin-RevId: b72a92a7169973c2d95e410cfbfed668a412e7e7 --- td/telegram/InlineQueriesManager.cpp | 2 +- td/telegram/MessageEntity.cpp | 2 +- td/telegram/MessageEntity.h | 2 +- td/telegram/MessagesManager.cpp | 10 +++++----- td/telegram/Td.cpp | 9 ++++++--- td/telegram/WebPagesManager.cpp | 2 +- td/telegram/net/DcAuthManager.cpp | 11 ++++++----- td/tl/TlObject.h | 15 ++++++++++++--- 8 files changed, 33 insertions(+), 20 deletions(-) diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 378c1b34..5d852b0b 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1155,7 +1155,7 @@ tl_object_ptr copy(const td_api::inlineQuery static tl_object_ptr copy_result(const tl_object_ptr &obj_ptr) { tl_object_ptr result; - downcast_call(*obj_ptr, [&result](const auto &obj) { result = copy(obj); }); + downcast_call(const_cast(*obj_ptr), [&result](const auto &obj) { result = copy(obj); }); return result; } diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index bbc69047..f18f235c 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -1720,7 +1720,7 @@ vector> get_input_secret_message_entiti } Result> get_message_entities(const ContactsManager *contacts_manager, - const vector> &input_entities) { + vector> &&input_entities) { vector entities; for (auto &entity : input_entities) { if (entity == nullptr || entity->type_ == nullptr) { diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index 29c7f5d1..f0af48cc 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -106,7 +106,7 @@ inline bool operator!=(const FormattedText &lhs, const FormattedText &rhs) { const std::unordered_set &get_valid_short_usernames(); Result> get_message_entities(const ContactsManager *contacts_manager, - const vector> &input_entities); + vector> &&input_entities); vector> get_text_entities_object(const vector &entities); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 1c9951c6..39e418f4 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -21140,7 +21140,7 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, const tl_object_ptr send_action = make_tl_object(); break; case td_api::chatActionUploadingVideo::ID: { - auto progress = static_cast(*action).progress_; + auto progress = static_cast(*action).progress_; send_action = make_tl_object(progress); break; } @@ -21148,17 +21148,17 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, const tl_object_ptr send_action = make_tl_object(); break; case td_api::chatActionUploadingVoiceNote::ID: { - auto progress = static_cast(*action).progress_; + auto progress = static_cast(*action).progress_; send_action = make_tl_object(progress); break; } case td_api::chatActionUploadingPhoto::ID: { - auto progress = static_cast(*action).progress_; + auto progress = static_cast(*action).progress_; send_action = make_tl_object(progress); break; } case td_api::chatActionUploadingDocument::ID: { - auto progress = static_cast(*action).progress_; + auto progress = static_cast(*action).progress_; send_action = make_tl_object(progress); break; } @@ -21175,7 +21175,7 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, const tl_object_ptr send_action = make_tl_object(); break; case td_api::chatActionUploadingVideoNote::ID: { - auto progress = static_cast(*action).progress_; + auto progress = static_cast(*action).progress_; send_action = make_tl_object(progress); break; } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d86c801d..82026cfd 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -143,7 +143,8 @@ class GetNearestDcQuery : public Td::ResultHandler { return on_error(id, result_ptr.move_as_error()); } - promise_.set_value(std::move(result_ptr.ok()->country_)); + auto result = result_ptr.move_as_ok(); + promise_.set_value(std::move(result->country_)); } void on_error(uint64 id, Status status) override { @@ -319,7 +320,8 @@ class SendCustomRequestQuery : public Td::ResultHandler { return on_error(id, result_ptr.move_as_error()); } - promise_.set_value(std::move(result_ptr.ok()->data_)); + auto result = result_ptr.move_as_ok(); + promise_.set_value(std::move(result->data_)); } void on_error(uint64 id, Status status) override { @@ -428,7 +430,8 @@ class GetInviteTextQuery : public Td::ResultHandler { return on_error(id, result_ptr.move_as_error()); } - promise_.set_value(std::move(result_ptr.ok()->message_)); + auto result = result_ptr.move_as_ok(); + promise_.set_value(std::move(result->message_)); } void on_error(uint64 id, Status status) override { diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 777a036a..ba2aa353 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1688,7 +1688,7 @@ int64 WebPagesManager::get_web_page_preview(td_api::object_ptrcontacts_manager_.get(), text->entities_); + auto r_entities = get_message_entities(td_->contacts_manager_.get(), std::move(text->entities_)); if (r_entities.is_error()) { promise.set_error(r_entities.move_as_error()); return 0; diff --git a/td/telegram/net/DcAuthManager.cpp b/td/telegram/net/DcAuthManager.cpp index dd3776a4..0443adb7 100644 --- a/td/telegram/net/DcAuthManager.cpp +++ b/td/telegram/net/DcAuthManager.cpp @@ -109,14 +109,15 @@ void DcAuthManager::on_result(NetQueryPtr result) { dc.state = DcInfo::State::Export; break; } - auto result_auth_exported = fetch_result(result->ok()); - if (result_auth_exported.is_error()) { - LOG(WARNING) << "Failed to parse result to auth_exportAuthorization: " << result_auth_exported.error(); + auto r_result_auth_exported = fetch_result(result->ok()); + if (r_result_auth_exported.is_error()) { + LOG(WARNING) << "Failed to parse result to auth_exportAuthorization: " << r_result_auth_exported.error(); dc.state = DcInfo::State::Export; break; } - dc.export_id = result_auth_exported.ok()->id_; - dc.export_bytes = std::move(result_auth_exported.ok()->bytes_); + auto result_auth_exported = r_result_auth_exported.move_as_ok(); + dc.export_id = result_auth_exported->id_; + dc.export_bytes = std::move(result_auth_exported->bytes_); break; } case DcInfo::State::BeforeOk: { diff --git a/td/tl/TlObject.h b/td/tl/TlObject.h index bc8d48a3..e53181db 100644 --- a/td/tl/TlObject.h +++ b/td/tl/TlObject.h @@ -130,13 +130,22 @@ class unique_ptr { ptr_ = nullptr; return res; } - T *get() const noexcept { + T *get() noexcept { return ptr_; } - T *operator->() const noexcept { + const T *get() const noexcept { return ptr_; } - T &operator*() const noexcept { + T *operator->() noexcept { + return ptr_; + } + const T *operator->() const noexcept { + return ptr_; + } + T &operator*() noexcept { + return *ptr_; + } + const T &operator*() const noexcept { return *ptr_; } explicit operator bool() const noexcept {