Add FileSourceId.h.

GitOrigin-RevId: 98707d3c9248fb4873ccb8b1e890bb0926bfed73
This commit is contained in:
levlam 2019-01-19 05:44:31 +03:00
parent 7ff1b83a24
commit 3bc0d8eb9a
6 changed files with 60 additions and 45 deletions

View File

@ -500,6 +500,7 @@ set(TDLIB_SOURCE
td/telegram/files/FileLoadManager.h
td/telegram/files/FileLocation.h
td/telegram/files/FileManager.h
td/telegram/files/FileSourceId.h
td/telegram/files/FileStats.h
td/telegram/files/FileStatsWorker.h
td/telegram/files/FileUploader.h

View File

@ -11,7 +11,9 @@
#include "td/telegram/ChatId.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/SetWithPosition.h"
#include "td/telegram/UserId.h"

View File

@ -17,6 +17,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageEntity.h"

View File

@ -14,51 +14,6 @@
namespace td {
class FileSourceId {
int32 id = 0;
public:
FileSourceId() = default;
explicit FileSourceId(int32 file_id) : id(file_id) {
}
template <class T1, typename = std::enable_if_t<std::is_convertible<T1, int32>::value>>
FileSourceId(T1 file_id) = delete;
bool empty() const {
return id <= 0;
}
bool is_valid() const {
return id > 0;
}
int32 get() const {
return id;
}
bool operator<(const FileSourceId &other) const {
return id < other.id;
}
bool operator==(const FileSourceId &other) const {
return id == other.id;
}
bool operator!=(const FileSourceId &other) const {
return id != other.id;
}
};
struct FileSourceIdHash {
std::size_t operator()(FileSourceId file_id) const {
return std::hash<int32>()(file_id.get());
}
};
inline StringBuilder &operator<<(StringBuilder &string_builder, FileSourceId file_id) {
return string_builder << "FileSourceId(" << file_id.get() << ")";
}
class FileId {
int32 id = 0;
int32 remote_id = 0;

View File

@ -16,6 +16,7 @@
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileLoadManager.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/files/FileStats.h"
#include "td/telegram/Location.h"

View File

@ -0,0 +1,55 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
//
// 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/StringBuilder.h"
#include <functional>
#include <type_traits>
namespace td {
class FileSourceId {
int32 id = 0;
public:
FileSourceId() = default;
explicit FileSourceId(int32 file_source_id) : id(file_source_id) {
}
template <class T1, typename = std::enable_if_t<std::is_convertible<T1, int32>::value>>
FileSourceId(T1 file_source_id) = delete;
bool is_valid() const {
return id > 0;
}
int32 get() const {
return id;
}
bool operator==(const FileSourceId &other) const {
return id == other.id;
}
bool operator!=(const FileSourceId &other) const {
return id != other.id;
}
};
struct FileSourceIdHash {
std::size_t operator()(FileSourceId file_source_id) const {
return std::hash<int32>()(file_source_id.get());
}
};
inline StringBuilder &operator<<(StringBuilder &string_builder, FileSourceId file_source_id) {
return string_builder << "FileSourceId(" << file_source_id.get() << ")";
}
} // namespace td