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/utils/common.h" 10 #include "td/utils/StringBuilder.h" 11 12 #include <functional> 13 #include <type_traits> 14 15 namespace td { 16 17 class FolderId { 18 int32 id = 0; 19 20 public: 21 FolderId() = default; 22 FolderId(int32 folder_id)23 explicit FolderId(int32 folder_id) : id(folder_id) { 24 } 25 template <class T, typename = std::enable_if_t<std::is_convertible<T, int32>::value>> 26 FolderId(T folder_id) = delete; 27 get()28 int32 get() const { 29 return id; 30 } 31 32 bool operator==(const FolderId &other) const { 33 return id == other.id; 34 } 35 36 bool operator!=(const FolderId &other) const { 37 return id != other.id; 38 } 39 40 template <class StorerT> store(StorerT & storer)41 void store(StorerT &storer) const { 42 storer.store_int(id); 43 } 44 45 template <class ParserT> parse(ParserT & parser)46 void parse(ParserT &parser) { 47 id = parser.fetch_int(); 48 } 49 main()50 static FolderId main() { 51 return FolderId(); 52 } archive()53 static FolderId archive() { 54 return FolderId(1); 55 } 56 }; 57 58 struct FolderIdHash { operatorFolderIdHash59 std::size_t operator()(FolderId folder_id) const { 60 return std::hash<int32>()(folder_id.get()); 61 } 62 }; 63 64 inline StringBuilder &operator<<(StringBuilder &string_builder, FolderId folder_id) { 65 return string_builder << "folder " << folder_id.get(); 66 } 67 68 } // namespace td 69