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 FileSourceId {
18   int32 id = 0;
19 
20  public:
21   FileSourceId() = default;
22 
FileSourceId(int32 file_source_id)23   explicit FileSourceId(int32 file_source_id) : id(file_source_id) {
24   }
25   template <class T1, typename = std::enable_if_t<std::is_convertible<T1, int32>::value>>
26   FileSourceId(T1 file_source_id) = delete;
27 
is_valid()28   bool is_valid() const {
29     return id > 0;
30   }
31 
get()32   int32 get() const {
33     return id;
34   }
35 
36   bool operator<(const FileSourceId &other) const {
37     return id < other.id;
38   }
39 
40   bool operator==(const FileSourceId &other) const {
41     return id == other.id;
42   }
43 
44   bool operator!=(const FileSourceId &other) const {
45     return id != other.id;
46   }
47 };
48 
49 struct FileSourceIdHash {
operatorFileSourceIdHash50   std::size_t operator()(FileSourceId file_source_id) const {
51     return std::hash<int32>()(file_source_id.get());
52   }
53 };
54 
55 inline StringBuilder &operator<<(StringBuilder &string_builder, FileSourceId file_source_id) {
56   return string_builder << "FileSourceId(" << file_source_id.get() << ")";
57 }
58 
59 }  // namespace td
60