1 // 2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 #pragma once 8 9 #include "td/telegram/td_api.h" 10 11 #include "td/utils/common.h" 12 #include "td/utils/StringBuilder.h" 13 14 #include <functional> 15 #include <type_traits> 16 17 namespace td { 18 19 class CallId { 20 public: 21 CallId() = default; 22 CallId(int32 call_id)23 explicit CallId(int32 call_id) : id(call_id) { 24 } 25 26 template <class T, typename = std::enable_if_t<std::is_convertible<T, int32>::value>> 27 CallId(T call_id) = delete; 28 is_valid()29 bool is_valid() const { 30 return id != 0; 31 } 32 get()33 int32 get() const { 34 return id; 35 } 36 get_call_id_object()37 auto get_call_id_object() const { 38 return td_api::make_object<td_api::callId>(id); 39 } 40 41 bool operator==(const CallId &other) const { 42 return id == other.id; 43 } 44 45 private: 46 int32 id{0}; 47 }; 48 49 struct CallIdHash { operatorCallIdHash50 std::size_t operator()(CallId call_id) const { 51 return std::hash<int32>()(call_id.get()); 52 } 53 }; 54 55 inline StringBuilder &operator<<(StringBuilder &sb, const CallId call_id) { 56 return sb << "call " << call_id.get(); 57 } 58 59 } // namespace td 60