From 0a380017d4dc9ac19adaca9b5ba33306d2fefacf Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 Jun 2019 19:56:59 +0300 Subject: [PATCH] Remove PhotoSizeSource.type field. GitOrigin-RevId: ef13086515430194150728f7ede427b6c87ba175 --- td/telegram/Photo.cpp | 8 ++++---- td/telegram/Photo.h | 19 +++++++++++-------- td/telegram/Photo.hpp | 2 ++ td/telegram/files/FileLocation.h | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index f6fd675e..b3e9beeb 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -55,7 +55,7 @@ tl_object_ptr PhotoSizeSource::DialogPhoto::get_input_p } FileType get_photo_size_source_file_type(const PhotoSizeSource &source) { - switch (source.type) { + switch (source.get_type()) { case PhotoSizeSource::Type::Thumbnail: return source.thumbnail().file_type; case PhotoSizeSource::Type::DialogPhoto: @@ -70,10 +70,10 @@ FileType get_photo_size_source_file_type(const PhotoSizeSource &source) { } bool operator==(const PhotoSizeSource &lhs, const PhotoSizeSource &rhs) { - if (lhs.type != rhs.type) { + if (lhs.get_type() != rhs.get_type()) { return false; } - switch (lhs.type) { + switch (lhs.get_type()) { case PhotoSizeSource::Type::Thumbnail: return lhs.thumbnail().file_type == rhs.thumbnail().file_type && lhs.thumbnail().thumbnail_type == rhs.thumbnail().thumbnail_type; @@ -398,7 +398,7 @@ Variant get_photo_size(FileManager *file_manager, PhotoSizeSo } else { res.type = static_cast(type[0]); } - if (source.type == PhotoSizeSource::Type::Thumbnail) { + if (source.get_type() == PhotoSizeSource::Type::Thumbnail) { source.thumbnail().thumbnail_type = res.type; } diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 4958cd7c..838006bc 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -49,7 +49,6 @@ struct PhotoSize { struct PhotoSizeSource { enum class Type : int32 { Empty, Thumbnail, DialogPhoto, StickerSetThumbnail }; - Type type; // for photos, document thumbnails, encrypted thumbnails struct Thumbnail { @@ -104,18 +103,19 @@ struct PhotoSizeSource { template void parse(ParserT &parser); }; - Variant variant; - PhotoSizeSource() : type(Type::Empty) { - } - PhotoSizeSource(FileType file_type, int32 thumbnail_type) - : type(Type::Thumbnail), variant(Thumbnail(file_type, thumbnail_type)) { + PhotoSizeSource() = default; + PhotoSizeSource(FileType file_type, int32 thumbnail_type) : variant(Thumbnail(file_type, thumbnail_type)) { } PhotoSizeSource(DialogId dialog_id, int64 dialog_access_hash, bool is_big) - : type(Type::DialogPhoto), variant(DialogPhoto(dialog_id, dialog_access_hash, is_big)) { + : variant(DialogPhoto(dialog_id, dialog_access_hash, is_big)) { } PhotoSizeSource(int64 sticker_set_id, int64 sticker_set_access_hash) - : type(Type::StickerSetThumbnail), variant(StickerSetThumbnail(sticker_set_id, sticker_set_access_hash)) { + : variant(StickerSetThumbnail(sticker_set_id, sticker_set_access_hash)) { + } + + Type get_type() const { + return static_cast(variant.get_offset() + 1); } Thumbnail &thumbnail() { @@ -135,6 +135,9 @@ struct PhotoSizeSource { void store(StorerT &storer) const; template void parse(ParserT &parser); + + private: + Variant variant; }; struct Photo { diff --git a/td/telegram/Photo.hpp b/td/telegram/Photo.hpp index ef32ce68..f1e3ac47 100644 --- a/td/telegram/Photo.hpp +++ b/td/telegram/Photo.hpp @@ -74,6 +74,7 @@ void PhotoSizeSource::DialogPhoto::parse(ParserT &parser) { template void PhotoSizeSource::store(StorerT &storer) const { using td::store; + auto type = get_type(); store(type, storer); switch (type) { case Type::Thumbnail: @@ -93,6 +94,7 @@ void PhotoSizeSource::store(StorerT &storer) const { template void PhotoSizeSource::parse(ParserT &parser) { using td::parse; + Type type; parse(type, parser); switch (type) { case Type::Thumbnail: { diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 54fa72af..763c6f81 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -395,7 +395,7 @@ class FullRemoteFileLocation { tl_object_ptr as_input_file_location() const { switch (location_type()) { case LocationType::Photo: { - switch (photo().source_.type) { + switch (photo().source_.get_type()) { case PhotoSizeSource::Type::Empty: return make_tl_object(photo().volume_id_, photo().local_id_, photo().secret_, BufferSlice(file_reference_));