2021-11-29 01:12:54 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef __TRANSMISSION__
|
|
|
|
#error only libtransmission should #include this header.
|
|
|
|
#endif
|
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
#include <cstddef> // size_t
|
2021-11-29 01:12:54 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
|
|
|
|
#include "bitfield.h"
|
|
|
|
|
|
|
|
struct tr_block_info;
|
|
|
|
|
|
|
|
class tr_file_piece_map
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
struct index_span_t
|
|
|
|
{
|
|
|
|
T begin;
|
|
|
|
T end;
|
|
|
|
};
|
|
|
|
using file_span_t = index_span_t<tr_file_index_t>;
|
|
|
|
using piece_span_t = index_span_t<tr_piece_index_t>;
|
|
|
|
|
2021-12-01 23:11:57 +00:00
|
|
|
explicit tr_file_piece_map(tr_info const& info)
|
2021-11-29 01:12:54 +00:00
|
|
|
{
|
|
|
|
reset(info);
|
|
|
|
}
|
|
|
|
tr_file_piece_map(tr_block_info const& block_info, uint64_t const* file_sizes, size_t n_files)
|
|
|
|
{
|
|
|
|
reset(block_info, file_sizes, n_files);
|
|
|
|
}
|
|
|
|
void reset(tr_block_info const& block_info, uint64_t const* file_sizes, size_t n_files);
|
|
|
|
void reset(tr_info const& info);
|
|
|
|
|
|
|
|
[[nodiscard]] piece_span_t pieceSpan(tr_file_index_t file) const;
|
|
|
|
[[nodiscard]] file_span_t fileSpan(tr_piece_index_t piece) const;
|
|
|
|
[[nodiscard]] size_t size() const
|
|
|
|
{
|
|
|
|
return std::size(files_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<piece_span_t> files_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class tr_file_priorities
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit tr_file_priorities(tr_file_piece_map const* fpm);
|
|
|
|
void reset(tr_file_piece_map const*);
|
|
|
|
void set(tr_file_index_t file, tr_priority_t priority);
|
|
|
|
void set(tr_file_index_t const* files, size_t n, tr_priority_t priority);
|
|
|
|
|
|
|
|
[[nodiscard]] tr_priority_t filePriority(tr_file_index_t file) const;
|
|
|
|
[[nodiscard]] tr_priority_t piecePriority(tr_piece_index_t piece) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
tr_file_piece_map const* fpm_;
|
|
|
|
std::vector<tr_priority_t> priorities_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class tr_files_wanted
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit tr_files_wanted(tr_file_piece_map const* fpm)
|
|
|
|
: wanted_(std::size(*fpm))
|
|
|
|
{
|
|
|
|
reset(fpm);
|
|
|
|
}
|
|
|
|
void reset(tr_file_piece_map const* fpm);
|
|
|
|
|
|
|
|
void set(tr_file_index_t file, bool wanted);
|
|
|
|
void set(tr_file_index_t const* files, size_t n, bool wanted);
|
|
|
|
|
|
|
|
[[nodiscard]] bool fileWanted(tr_file_index_t file) const;
|
|
|
|
[[nodiscard]] bool pieceWanted(tr_piece_index_t piece) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
tr_file_piece_map const* fpm_;
|
|
|
|
tr_bitfield wanted_;
|
|
|
|
};
|