diff options
| author | levlam <levlam@telegram.org> | 2026-07-09 16:14:29 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2026-07-09 16:14:29 +0300 |
| commit | bcd45af2440fd85bb2442f9189824016751f578c (patch) | |
| tree | 2ab0680e9190c57400731d1d2b28bc9b788dc6e4 /td | |
| parent | 4747f37423c63c439ffd6876339aa89790ddabe0 (diff) | |
Add CommunityId.
Diffstat (limited to 'td')
| -rw-r--r-- | td/telegram/CommunityId.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/td/telegram/CommunityId.h b/td/telegram/CommunityId.h new file mode 100644 index 000000000..3cf2df1a2 --- /dev/null +++ b/td/telegram/CommunityId.h @@ -0,0 +1,65 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026 +// +// 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/utils/common.h" +#include "td/utils/HashTableUtils.h" +#include "td/utils/StringBuilder.h" + +#include <type_traits> + +namespace td { + +class CommunityId { + int64 id = 0; + + public: + CommunityId() = default; + + explicit constexpr CommunityId(int64 community_id) : id(community_id) { + } + template <class T, typename = std::enable_if_t<std::is_convertible<T, int64>::value>> + CommunityId(T community_id) = delete; + + bool is_valid() const { + return id > 0; + } + + int64 get() const { + return id; + } + + bool operator==(const CommunityId &other) const { + return id == other.id; + } + + bool operator!=(const CommunityId &other) const { + return id != other.id; + } + + template <class StorerT> + void store(StorerT &storer) const { + storer.store_long(id); + } + + template <class ParserT> + void parse(ParserT &parser) { + id = parser.fetch_long(); + } +}; + +struct CommunityIdHash { + uint32 operator()(CommunityId community_id) const { + return Hash<int64>()(community_id.get()); + } +}; + +inline StringBuilder &operator<<(StringBuilder &string_builder, CommunityId community_id) { + return string_builder << "community " << community_id.get(); +} + +} // namespace td |
