Explicitly specify enum underlying type.

GitOrigin-RevId: 65a7cc4df6b07fe095e898c06ad53deb5e188df3
This commit is contained in:
levlam 2018-04-19 16:08:30 +03:00
parent 8524a99faa
commit d80148afae
35 changed files with 85 additions and 82 deletions

View File

@ -8,6 +8,6 @@
namespace td {
enum class AccessRights { Read, Edit, Write };
enum class AccessRights : int32 { Read, Edit, Write };
} // namespace td

View File

@ -96,7 +96,7 @@ class SendCodeHelper {
class PhoneNumberManager : public NetActor {
public:
enum class Type { ChangePhone, VerifyPhone, ConfirmPhone };
enum class Type : int32 { ChangePhone, VerifyPhone, ConfirmPhone };
PhoneNumberManager(Type type, ActorShared<> parent);
void get_state(uint64 query_id);
@ -108,8 +108,8 @@ class PhoneNumberManager : public NetActor {
private:
Type type_;
enum class State { Ok, WaitCode } state_ = State::Ok;
enum class NetQueryType { None, SendCode, CheckCode };
enum class State : int32 { Ok, WaitCode } state_ = State::Ok;
enum class NetQueryType : int32 { None, SendCode, CheckCode };
ActorShared<> parent_;
uint64 query_id_ = 0;
@ -173,7 +173,7 @@ class AuthManager : public NetActor {
LoggingOut,
Closing
} state_ = State::None;
enum class NetQueryType {
enum class NetQueryType : int32 {
None,
SignIn,
SignUp,

View File

@ -51,7 +51,7 @@ struct CallConnection {
};
struct CallState {
enum class Type { Empty, Pending, ExchangingKey, Ready, HangingUp, Discarded, Error } type{Type::Empty};
enum class Type : int32 { Empty, Pending, ExchangingKey, Ready, HangingUp, Discarded, Error } type{Type::Empty};
CallProtocol protocol;
std::vector<CallConnection> connections;
@ -97,7 +97,7 @@ class CallActor : public NetQueryCallback {
int32 duration_{0};
int64 connection_id_{0};
enum class State {
enum class State : int32 {
Empty,
SendRequestQuery,
WaitRequestResult,

View File

@ -51,9 +51,9 @@ struct BotData {
bool need_location;
};
enum class ChannelType { Broadcast, Megagroup, Unknown };
enum class ChannelType : uint8 { Broadcast, Megagroup, Unknown };
enum class CheckDialogUsernameResult { Ok, Invalid, Occupied, PublicDialogsTooMuch, PublicGroupsUnavailable };
enum class CheckDialogUsernameResult : uint8 { Ok, Invalid, Occupied, PublicDialogsTooMuch, PublicGroupsUnavailable };
class ContactsManager : public Actor {
public:

View File

@ -47,7 +47,7 @@ class DeviceTokenManager : public NetQueryCallback {
SIZE
};
struct TokenInfo {
enum class State { Sync, Unregister, Register };
enum class State : int32 { Sync, Unregister, Register };
State state = State::Sync;
string token;
uint64 net_query_id = 0;

View File

@ -21,7 +21,7 @@
namespace td {
enum class DialogType { None, User, Chat, Channel, SecretChat };
enum class DialogType : int32 { None, User, Chat, Channel, SecretChat };
class DialogId {
static constexpr int64 MIN_SECRET_ID = -2002147483648ll;

View File

@ -374,17 +374,17 @@ DialogParticipantStatus get_dialog_participant_status(
tl_object_ptr<telegram_api::ChannelParticipantsFilter>
ChannelParticipantsFilter::get_input_channel_participants_filter() const {
switch (type) {
case Recent:
case Type::Recent:
return make_tl_object<telegram_api::channelParticipantsRecent>();
case Administrators:
case Type::Administrators:
return make_tl_object<telegram_api::channelParticipantsAdmins>();
case Search:
case Type::Search:
return make_tl_object<telegram_api::channelParticipantsSearch>(query);
case Restricted:
case Type::Restricted:
return make_tl_object<telegram_api::channelParticipantsBanned>(query);
case Banned:
case Type::Banned:
return make_tl_object<telegram_api::channelParticipantsKicked>(query);
case Bots:
case Type::Bots:
return make_tl_object<telegram_api::channelParticipantsBots>();
default:
UNREACHABLE();
@ -394,34 +394,34 @@ ChannelParticipantsFilter::get_input_channel_participants_filter() const {
ChannelParticipantsFilter::ChannelParticipantsFilter(const tl_object_ptr<td_api::SupergroupMembersFilter> &filter) {
if (filter == nullptr) {
type = Recent;
type = Type::Recent;
return;
}
switch (filter->get_id()) {
case td_api::supergroupMembersFilterRecent::ID:
type = Recent;
type = Type::Recent;
return;
case td_api::supergroupMembersFilterAdministrators::ID:
type = Administrators;
type = Type::Administrators;
return;
case td_api::supergroupMembersFilterSearch::ID:
type = Search;
type = Type::Search;
query = static_cast<const td_api::supergroupMembersFilterSearch *>(filter.get())->query_;
return;
case td_api::supergroupMembersFilterRestricted::ID:
type = Restricted;
type = Type::Restricted;
query = static_cast<const td_api::supergroupMembersFilterRestricted *>(filter.get())->query_;
return;
case td_api::supergroupMembersFilterBanned::ID:
type = Banned;
type = Type::Banned;
query = static_cast<const td_api::supergroupMembersFilterBanned *>(filter.get())->query_;
return;
case td_api::supergroupMembersFilterBots::ID:
type = Bots;
type = Type::Bots;
return;
default:
UNREACHABLE();
type = Recent;
type = Type::Recent;
}
}

View File

@ -52,7 +52,7 @@ class DialogParticipantStatus {
CAN_SEND_ANIMATIONS | CAN_SEND_GAMES | CAN_USE_INLINE_BOTS |
CAN_ADD_WEB_PAGE_PREVIEWS;
enum class Type { Creator, Administrator, Member, Restricted, Left, Banned };
enum class Type : int32 { Creator, Administrator, Member, Restricted, Left, Banned };
// all fields are logically const, but should be updated in update_restrictions()
mutable Type type_;
mutable uint32 flags_;
@ -239,7 +239,7 @@ struct DialogParticipant {
};
class ChannelParticipantsFilter {
enum { Recent, Administrators, Search, Restricted, Banned, Bots } type;
enum class Type : int32 { Recent, Administrators, Search, Restricted, Banned, Bots } type;
string query;
public:
@ -248,7 +248,7 @@ class ChannelParticipantsFilter {
tl_object_ptr<telegram_api::ChannelParticipantsFilter> get_input_channel_participants_filter() const;
bool is_administrators() const {
return type == Administrators;
return type == Type::Administrators;
}
};

View File

@ -32,7 +32,7 @@ class DocumentsManager {
public:
explicit DocumentsManager(Td *td);
enum class DocumentType { Unknown, Animation, Audio, General, Sticker, Video, VideoNote, VoiceNote };
enum class DocumentType : int32 { Unknown, Animation, Audio, General, Sticker, Video, VideoNote, VoiceNote };
class RemoteDocument {
public:

View File

@ -22,7 +22,7 @@
namespace td {
// append only before Size
enum class SearchMessagesFilter {
enum class SearchMessagesFilter : int32 {
Empty,
Animation,
Audio,

View File

@ -705,7 +705,7 @@ class DialogNotificationSettings {
}
};
enum class NotificationSettingsScope { Private, Group };
enum class NotificationSettingsScope : int32 { Private, Group };
class ScopeNotificationSettings {
public:
@ -2663,7 +2663,7 @@ class MessagesManager : public Actor {
KHeap<double> ttl_heap_;
Slot ttl_slot_;
enum YieldType { None, Ttl, TtlDb }; // None must be first
enum YieldType : int32 { None, Ttl, TtlDb }; // None must be first
int32 ttl_db_expire_from_;
int32 ttl_db_expire_till_;
bool ttl_db_has_query_;

View File

@ -67,7 +67,7 @@ class PrivacyManager : public NetQueryCallback {
}
private:
enum class Type {
enum class Type : int32 {
AllowContacts,
AllowAll,
AllowUsers,

View File

@ -136,8 +136,8 @@ class SecretChatActor : public NetQueryCallback {
void binlog_replay_finish();
private:
enum class State { Empty, SendRequest, SendAccept, WaitRequestResponse, WaitAcceptResponse, Ready, Closed };
enum { MAX_RESEND_COUNT = 1000 };
enum class State : int32 { Empty, SendRequest, SendAccept, WaitRequestResponse, WaitAcceptResponse, Ready, Closed };
static constexpr int32 MAX_RESEND_COUNT = 1000;
// We have git state that should be shynchronized with db.
// It is splitted into several parts because:
@ -198,7 +198,7 @@ class SecretChatActor : public NetQueryCallback {
ttl = parser.fetch_int();
bool has_flags = (his_layer & HAS_FLAGS) != 0;
if (has_flags) {
his_layer &= ~HAS_FLAGS;
his_layer &= static_cast<int32>(~HAS_FLAGS);
my_layer = parser.fetch_int();
// for future usage
BEGIN_PARSE_FLAGS();
@ -206,7 +206,7 @@ class SecretChatActor : public NetQueryCallback {
}
}
enum { HAS_FLAGS = 1 << 31 };
static constexpr uint32 HAS_FLAGS = 1u << 31;
};
// PfsAction
@ -576,7 +576,7 @@ class SecretChatActor : public NetQueryCallback {
int32 last_read_history_date_ = -1;
Promise<Unit> read_history_promise_;
enum SendFlag {
enum SendFlag : int32 {
None = 0,
External = 1,
Push = 2,

View File

@ -91,7 +91,7 @@ class SetSecureValue : public NetQueryCallback {
class UploadCallback;
std::shared_ptr<UploadCallback> upload_callback_;
enum class State { WaitSecret, WaitSetValue } state_ = State::WaitSecret;
enum class State : int32 { WaitSecret, WaitSetValue } state_ = State::WaitSecret;
class UploadCallback : public FileManager::UploadCallback {
public:

View File

@ -30,7 +30,7 @@ class SequenceDispatcher : public NetQueryCallback {
void close_silent();
private:
enum class State { Start, Wait, Finish, Dummy };
enum class State : int32 { Start, Wait, Finish, Dummy };
struct Data {
State state_;
NetQueryRef net_query_ref_;

View File

@ -58,12 +58,12 @@ void StateManager::do_on_network(NetType new_network_type, bool inc_generation)
if (inc_generation) {
network_generation_++;
}
notify_flags(NetworkFlag);
notify_flag(Flag::Network);
}
void StateManager::on_online(bool is_online) {
online_flag_ = is_online;
notify_flags(OnlineFlag);
notify_flag(Flag::Online);
}
void StateManager::on_proxy(bool use_proxy) {
@ -105,18 +105,21 @@ StateManager::State StateManager::get_real_state() const {
return State::Ready;
}
void StateManager::notify_flags(int32 flags) {
void StateManager::notify_flag(Flag flag) {
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
bool ok = true;
if (flags & OnlineFlag) {
ok &= (*it)->on_online(online_flag_);
}
if (flags & StateFlag) {
ok &= (*it)->on_state(flush_state_);
}
if (flags & NetworkFlag) {
ok &= (*it)->on_network(network_type_, network_generation_);
}
bool ok = [&] {
switch (flag) {
case Flag::Online:
return (*it)->on_online(online_flag_);
case Flag::State:
return (*it)->on_state(flush_state_);
case Flag::Network:
return (*it)->on_network(network_type_, network_generation_);
default:
UNREACHABLE();
return true;
}
}();
if (ok) {
++it;
} else {
@ -165,7 +168,7 @@ void StateManager::loop() {
if (now >= pending_timestamp_ + delay) {
has_timestamp_ = false;
flush_state_ = pending_state_;
notify_flags(StateFlag);
notify_flag(Flag::State);
} else {
set_timeout_at(pending_timestamp_ + delay);
}

View File

@ -114,8 +114,8 @@ class StateManager final : public Actor {
void inc_connect();
void dec_connect();
enum Flags { OnlineFlag = 1, StateFlag = 2, NetworkFlag = 4 };
void notify_flags(int32 flags);
enum class Flag : int32 { Online, State, Network };
void notify_flag(Flag flag);
void start_up() override;
void loop() override;

View File

@ -230,7 +230,7 @@ class Td final : public NetQueryCallback {
bool destroy_flag_ = false;
int close_flag_ = 0;
enum class State { WaitParameters, Decrypt, Run, Close } state_ = State::WaitParameters;
enum class State : int32 { WaitParameters, Decrypt, Run, Close } state_ = State::WaitParameters;
EncryptionInfo encryption_info_;
vector<std::pair<uint64, std::shared_ptr<ResultHandler>>> result_handlers_;

View File

@ -23,7 +23,7 @@
#include <utility>
namespace td {
enum class TopDialogCategory { Correspondent, BotPM, BotInline, Group, Channel, Call, Size };
enum class TopDialogCategory : int32 { Correspondent, BotPM, BotInline, Group, Channel, Call, Size };
inline TopDialogCategory top_dialog_category_from_td_api(const td_api::TopChatCategory &category) {
switch (category.get_id()) {
@ -65,7 +65,7 @@ class TopDialogManager : public NetQueryCallback {
bool is_active_{false};
bool was_first_sync_{false};
enum class SyncState { None, Pending, Ok };
enum class SyncState : int32 { None, Pending, Ok };
SyncState db_sync_state_ = SyncState::None;
Timestamp first_unsync_change_;
SyncState server_sync_state_ = SyncState::None;

View File

@ -112,7 +112,7 @@ class UpdatesManager : public Actor {
class State {
public:
enum class Type {
enum class Type : int32 {
General,
RunningGetUpdatesState,
RunningGetDifference,

View File

@ -56,10 +56,10 @@ void FileHashUploader::loop() {
}
Status FileHashUploader::loop_impl() {
if (state_ == CalcSha) {
if (state_ == State::CalcSha) {
TRY_STATUS(loop_sha());
}
if (state_ == NetRequest) {
if (state_ == State::NetRequest) {
// messages.getDocumentByHash#338e2464 sha256:bytes size:int mime_type:string = Document;
auto hash = BufferSlice(32);
sha256_final(&sha256_state_, hash.as_slice());
@ -69,7 +69,7 @@ Status FileHashUploader::loop_impl() {
LOG(INFO) << "Send getDocumentByHash request: " << to_string(query);
auto ptr = G()->net_query_creator().create(create_storer(query));
G()->net_query_dispatcher().dispatch_with_callback(std::move(ptr), actor_shared(this));
state_ = WaitNetResult;
state_ = State::WaitNetResult;
}
return Status::OK();
}
@ -102,7 +102,7 @@ Status FileHashUploader::loop_sha() {
size_left_ -= narrow_cast<int64>(read_size);
CHECK(size_left_ >= 0);
if (size_left_ == 0) {
state_ = NetRequest;
state_ = State::NetRequest;
return Status::OK();
}
return Status::OK();

View File

@ -60,7 +60,7 @@ class FileHashUploader : public FileLoaderActor {
ActorShared<ResourceManager> resource_manager_;
enum { CalcSha, NetRequest, WaitNetResult } state_ = CalcSha;
enum class State : int32 { CalcSha, NetRequest, WaitNetResult } state_ = State::CalcSha;
bool stop_flag_ = false;
Sha256State sha256_state_;

View File

@ -123,7 +123,7 @@ Status FileLoader::do_loop() {
}
for (auto &query : check_info.queries) {
G()->net_query_dispatcher().dispatch_with_callback(
std::move(query), actor_shared(this, UniqueId::next(UniqueId::Type::Default, CommonQueryKey)));
std::move(query), actor_shared(this, UniqueId::next(UniqueId::Type::Default, COMMON_QUERY_KEY)));
}
if (check_info.need_check) {
parts_manager_.set_need_check();
@ -209,7 +209,7 @@ void FileLoader::on_result(NetQueryPtr query) {
if (id == blocking_id_) {
blocking_id_ = 0;
}
if (UniqueId::extract_key(id) == CommonQueryKey) {
if (UniqueId::extract_key(id) == COMMON_QUERY_KEY) {
on_common_query(std::move(query));
return loop();
}

View File

@ -95,7 +95,7 @@ class FileLoader : public FileLoaderActor {
}
private:
enum { CommonQueryKey = 2 };
static constexpr uint8 COMMON_QUERY_KEY = 2;
bool stop_flag_ = false;
ActorShared<ResourceManager> resource_manager_;
ResourceState resource_state_;

View File

@ -157,7 +157,7 @@ constexpr int32 file_type_size = static_cast<int32>(FileType::Size);
extern const char *file_type_name[file_type_size];
struct FileEncryptionKey {
enum class Type { None, Secret, Secure };
enum class Type : int32 { None, Secret, Secure };
FileEncryptionKey() = default;
FileEncryptionKey(Slice key, Slice iv) : key_iv_(key.size() + iv.size(), '\0'), type_(Type::Secret) {
if (key.size() != 32 || iv.size() != 32) {
@ -459,7 +459,7 @@ class FullRemoteFileLocation {
static constexpr int32 WEB_LOCATION_FLAG = 1 << 24;
bool web_location_flag_{false};
DcId dc_id_;
enum class LocationType { Web, Photo, Common, None };
enum class LocationType : int32 { Web, Photo, Common, None };
Variant<WebRemoteFileLocation, PhotoRemoteFileLocation, CommonRemoteFileLocation> variant_;
LocationType location_type() const {

View File

@ -368,7 +368,7 @@ class FileManager : public FileLoadManager::Callback {
class Query {
public:
FileId file_id_;
enum Type { UploadByHash, Upload, Download, SetContent, Generate } type_;
enum Type : int32 { UploadByHash, Upload, Download, SetContent, Generate } type_;
};
struct FileIdInfo {
FileNodeId node_id_{0};

View File

@ -49,7 +49,7 @@ class PartsManager {
static constexpr int MAX_PART_SIZE = 512 * (1 << 10);
static constexpr int64 MAX_FILE_SIZE = MAX_PART_SIZE * MAX_PART_COUNT;
enum class PartStatus { Empty, Pending, Ready };
enum class PartStatus : int32 { Empty, Pending, Ready };
bool need_check_{false};
int64 checked_prefix_size_{0};

View File

@ -20,7 +20,7 @@
namespace td {
class ResourceManager : public Actor {
public:
enum class Mode { Baseline, Greedy };
enum class Mode : int32 { Baseline, Greedy };
explicit ResourceManager(Mode mode) : mode_(mode) {
}
// use through ActorShared

View File

@ -98,7 +98,7 @@ class Proxy {
return password_;
}
enum class Type { None, Socks5 };
enum class Type : int32 { None, Socks5 };
Type type() const {
return type_;
}

View File

@ -31,7 +31,7 @@ class DcAuthManager : public NetQueryCallback {
std::shared_ptr<AuthDataShared> shared_auth_data;
AuthState auth_state;
enum class State { Waiting, Export, Import, BeforeOk, Ok };
enum class State : int32 { Waiting, Export, Import, BeforeOk, Ok };
State state = State::Waiting;
uint64 wait_id;
int32 export_id;

View File

@ -71,7 +71,7 @@ class DcId {
}
private:
enum { Empty = 0, MainDc = -1, Invalid = -2 };
enum : int32 { Empty = 0, MainDc = -1, Invalid = -2 };
int32 dc_id_{Empty};
bool is_external_{false};

View File

@ -21,7 +21,7 @@
namespace td {
class DcOption {
// do not forget to update PrintFlags
enum Flags { IPv6 = 1, MediaOnly = 2, ObfuscatedTcpOnly = 4, Cdn = 8, Static = 16 };
enum Flags : int32 { IPv6 = 1, MediaOnly = 2, ObfuscatedTcpOnly = 4, Cdn = 8, Static = 16 };
int32 flags = 0;
DcId dc_id;

View File

@ -26,7 +26,7 @@ class DcOptionsSet {
double ok_at{-1000};
double error_at{-1001};
double check_at{-1002};
enum State { Ok, Error, Checking };
enum State : int32 { Ok, Error, Checking };
void on_ok() {
ok_at = Time::now_cached();
@ -63,7 +63,7 @@ class DcOptionsSet {
void reset();
private:
enum class State { Error, Ok, Checking };
enum class State : int32 { Error, Ok, Checking };
struct OptionStat {
Stat tcp_stat;

View File

@ -47,7 +47,7 @@ class NetQuery : public ListNode {
NetQuery() = default;
enum class State : int8 { Empty, Query, OK, Error };
enum class Type { Common, Upload, Download, DownloadSmall };
enum class Type : int8 { Common, Upload, Download, DownloadSmall };
enum class AuthFlag : int8 { Off, On };
enum class GzipFlag : int8 { Off, On };
enum Error : int32 { Resend = 202, Cancelled = 203, ResendInvokeAfter = 204 };

View File

@ -94,7 +94,7 @@ class Session final
// Just re-ask answer_id each time we get information about it.
// Thought mtproto::Connection must ensure delivery of such query
enum class Mode { Tcp, Http } mode_ = Mode::Tcp;
enum class Mode : int8 { Tcp, Http } mode_ = Mode::Tcp;
bool is_main_;
bool is_cdn_;
bool was_on_network_ = false;
@ -120,7 +120,7 @@ class Session final
struct ConnectionInfo {
int8 connection_id;
Mode mode;
enum class State { Empty, Connecting, Ready } state = State::Empty;
enum class State : int8 { Empty, Connecting, Ready } state = State::Empty;
mtproto::AuthKeyHandshake handshake;
mtproto::AuthKeyHandshake tmp_handshake;
unique_ptr<mtproto::SessionConnection> connection;