diff options
| author | levlam <levlam@telegram.org> | 2023-08-25 02:04:44 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2023-08-25 02:04:44 +0300 |
| commit | 4455255d9b884ef6ec0cc5ce0c47ca3d154793f1 (patch) | |
| tree | a578a97cc0d1ecd90c190dfb56638b3b60fba147 /td/telegram/NotificationObjectId.h | |
| parent | c770f6058c013175f5d0bb7de6f32b65dab2b424 (diff) | |
Add class NotificationObjectId.
Diffstat (limited to 'td/telegram/NotificationObjectId.h')
| -rw-r--r-- | td/telegram/NotificationObjectId.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/td/telegram/NotificationObjectId.h b/td/telegram/NotificationObjectId.h new file mode 100644 index 000000000..7f38727de --- /dev/null +++ b/td/telegram/NotificationObjectId.h @@ -0,0 +1,71 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/MessageId.h" + +#include "td/utils/common.h" + +namespace td { + +class NotificationObjectId { + int64 id = 0; + + public: + NotificationObjectId() = default; + + NotificationObjectId(MessageId message_id) : id(message_id.get()) { + } + + static NotificationObjectId max() { + return NotificationObjectId(MessageId::max()); + } + + int64 get() const { + return id; + } + + bool is_valid() const { + return id > 0; + } + + bool operator==(const NotificationObjectId &other) const { + return id == other.id; + } + + bool operator!=(const NotificationObjectId &other) const { + return id != other.id; + } + + friend bool operator<(const NotificationObjectId &lhs, const NotificationObjectId &rhs) { + return lhs.id < rhs.id; + } + + friend bool operator>(const NotificationObjectId &lhs, const NotificationObjectId &rhs) { + return lhs.id > rhs.id; + } + + friend bool operator<=(const NotificationObjectId &lhs, const NotificationObjectId &rhs) { + return lhs.id <= rhs.id; + } + + friend bool operator>=(const NotificationObjectId &lhs, const NotificationObjectId &rhs) { + return lhs.id >= rhs.id; + } +}; + +struct NotificationObjectIdHash { + uint32 operator()(NotificationObjectId notification_object_id) const { + return Hash<int64>()(notification_object_id.get()); + } +}; + +inline StringBuilder &operator<<(StringBuilder &string_builder, NotificationObjectId notification_object_id) { + return string_builder << "notification object " << notification_object_id.get(); +} + +} // namespace td |
