convert file_open_mode to type safe flags
This commit is contained in:
parent
140b8ace8d
commit
78bbd298a5
|
@ -294,6 +294,7 @@ void bind_converters()
|
|||
to_python_converter<lt::peer_flags_t, from_bitfield_flag<lt::peer_flags_t>>();
|
||||
to_python_converter<lt::peer_source_flags_t, from_bitfield_flag<lt::peer_source_flags_t>>();
|
||||
to_python_converter<lt::bandwidth_state_flags_t, from_bitfield_flag<lt::bandwidth_state_flags_t>>();
|
||||
to_python_converter<lt::file_open_mode_t, from_bitfield_flag<lt::file_open_mode_t>>();
|
||||
|
||||
// work-around types
|
||||
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
|
||||
|
@ -340,4 +341,5 @@ void bind_converters()
|
|||
to_bitfield_flag<lt::peer_flags_t>();
|
||||
to_bitfield_flag<lt::peer_source_flags_t>();
|
||||
to_bitfield_flag<lt::bandwidth_state_flags_t>();
|
||||
to_bitfield_flag<lt::file_open_mode_t>();
|
||||
}
|
||||
|
|
|
@ -427,6 +427,8 @@ void add_piece(torrent_handle& th, piece_index_t piece, char const *data, int fl
|
|||
th.add_piece(piece, data, flags);
|
||||
}
|
||||
|
||||
class dummy {};
|
||||
|
||||
using by_value = return_value_policy<return_by_value>;
|
||||
void bind_torrent_handle()
|
||||
{
|
||||
|
@ -578,16 +580,17 @@ void bind_torrent_handle()
|
|||
.def_readonly("open_mode", &open_file_state::open_mode)
|
||||
;
|
||||
|
||||
enum_<file_open_mode>("file_open_mode")
|
||||
.value("read_only", file_open_mode::read_only)
|
||||
.value("write_only", file_open_mode::write_only)
|
||||
.value("read_write", file_open_mode::read_write)
|
||||
.value("rw_mask", file_open_mode::rw_mask)
|
||||
.value("sparse", file_open_mode::sparse)
|
||||
.value("no_atime", file_open_mode::no_atime)
|
||||
.value("random_access", file_open_mode::random_access)
|
||||
.value("locked", file_open_mode::locked)
|
||||
;
|
||||
{
|
||||
scope s = class_<dummy>("file_open_mode");
|
||||
s.attr("read_only") = file_open_mode::read_only;
|
||||
s.attr("write_only") = file_open_mode::write_only;
|
||||
s.attr("read_write") = file_open_mode::read_write;
|
||||
s.attr("rw_mask") = file_open_mode::rw_mask;
|
||||
s.attr("sparse") = file_open_mode::sparse;
|
||||
s.attr("no_atime") = file_open_mode::no_atime;
|
||||
s.attr("random_access") = file_open_mode::random_access;
|
||||
s.attr("locked") = file_open_mode::locked;
|
||||
}
|
||||
|
||||
enum_<torrent_handle::file_progress_flags_t>("file_progress_flags")
|
||||
.value("piece_granularity", torrent_handle::piece_granularity)
|
||||
|
|
|
@ -70,7 +70,6 @@ using lt::total_milliseconds;
|
|||
using lt::alert;
|
||||
using lt::piece_index_t;
|
||||
using lt::file_index_t;
|
||||
using lt::file_open_mode;
|
||||
using lt::torrent_handle;
|
||||
using lt::add_torrent_params;
|
||||
using lt::cache_status;
|
||||
|
@ -1894,12 +1893,12 @@ COLUMN OPTIONS
|
|||
if (f != file_status.end() && f->file_index == i)
|
||||
{
|
||||
title += " [ ";
|
||||
if ((f->open_mode & file_open_mode::rw_mask) == file_open_mode::read_write) title += "read/write ";
|
||||
else if ((f->open_mode & file_open_mode::rw_mask) == file_open_mode::read_only) title += "read ";
|
||||
else if ((f->open_mode & file_open_mode::rw_mask) == file_open_mode::write_only) title += "write ";
|
||||
if (f->open_mode & file_open_mode::random_access) title += "random_access ";
|
||||
if (f->open_mode & file_open_mode::locked) title += "locked ";
|
||||
if (f->open_mode & file_open_mode::sparse) title += "sparse ";
|
||||
if ((f->open_mode & lt::file_open_mode::rw_mask) == lt::file_open_mode::read_write) title += "read/write ";
|
||||
else if ((f->open_mode & lt::file_open_mode::rw_mask) == lt::file_open_mode::read_only) title += "read ";
|
||||
else if ((f->open_mode & lt::file_open_mode::rw_mask) == lt::file_open_mode::write_only) title += "write ";
|
||||
if (f->open_mode & lt::file_open_mode::random_access) title += "random_access ";
|
||||
if (f->open_mode & lt::file_open_mode::locked) title += "locked ";
|
||||
if (f->open_mode & lt::file_open_mode::sparse) title += "sparse ";
|
||||
title += "]";
|
||||
++f;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/storage_defs.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/sha1_hash.hpp"
|
||||
#include "libtorrent/flags.hpp"
|
||||
|
||||
namespace libtorrent {
|
||||
|
||||
|
@ -61,37 +62,40 @@ namespace libtorrent {
|
|||
|
||||
struct storage_holder;
|
||||
|
||||
enum file_open_mode
|
||||
struct file_open_mode_tag;
|
||||
using file_open_mode_t = flags::bitfield_flag<std::uint32_t, file_open_mode_tag>;
|
||||
|
||||
namespace file_open_mode
|
||||
{
|
||||
// open the file for reading only
|
||||
read_only = 0,
|
||||
constexpr file_open_mode_t read_only{0};
|
||||
|
||||
// open the file for writing only
|
||||
write_only = 1,
|
||||
constexpr file_open_mode_t write_only{1};
|
||||
|
||||
// open the file for reading and writing
|
||||
read_write = 2,
|
||||
constexpr file_open_mode_t read_write{2};
|
||||
|
||||
// the mask for the bits determining read or write mode
|
||||
rw_mask = read_only | write_only | read_write,
|
||||
constexpr file_open_mode_t rw_mask = read_only | write_only | read_write;
|
||||
|
||||
// open the file in sparse mode (if supported by the
|
||||
// filesystem).
|
||||
sparse = 0x4,
|
||||
constexpr file_open_mode_t sparse{0x4};
|
||||
|
||||
// don't update the access timestamps on the file (if
|
||||
// supported by the operating system and filesystem).
|
||||
// this generally improves disk performance.
|
||||
no_atime = 0x8,
|
||||
constexpr file_open_mode_t no_atime{0x8};
|
||||
|
||||
// open the file for random access. This disables read-ahead
|
||||
// logic
|
||||
random_access = 0x10,
|
||||
constexpr file_open_mode_t random_access{0x10};
|
||||
|
||||
// prevent the file from being opened by another process
|
||||
// while it's still being held open by this handle
|
||||
locked = 0x20,
|
||||
};
|
||||
constexpr file_open_mode_t locked{0x20};
|
||||
}
|
||||
|
||||
// this contains information about a file that's currently open by the
|
||||
// libtorrent disk I/O subsystem. It's associated with a single torent.
|
||||
|
@ -107,7 +111,7 @@ namespace libtorrent {
|
|||
//
|
||||
// Note that the read/write mode is not a bitmask. The two least significant bits are used
|
||||
// to represent the read/write mode. Those bits can be masked out using the ``rw_mask`` constant.
|
||||
std::uint32_t open_mode;
|
||||
file_open_mode_t open_mode;
|
||||
|
||||
// a (high precision) timestamp of when the file was last used.
|
||||
time_point last_use;
|
||||
|
|
|
@ -182,9 +182,9 @@ namespace libtorrent {
|
|||
|
||||
namespace {
|
||||
|
||||
std::uint32_t to_file_open_mode(open_mode_t const mode)
|
||||
file_open_mode_t to_file_open_mode(open_mode_t const mode)
|
||||
{
|
||||
std::uint32_t ret = 0;
|
||||
file_open_mode_t ret;
|
||||
open_mode_t const rw_mode = mode & open_mode::rw_mask;
|
||||
|
||||
ret = (rw_mode == open_mode::read_only)
|
||||
|
@ -193,7 +193,7 @@ namespace libtorrent {
|
|||
? file_open_mode::write_only
|
||||
: (rw_mode == open_mode::read_write)
|
||||
? file_open_mode::read_write
|
||||
: 0;
|
||||
: file_open_mode_t{};
|
||||
|
||||
if (mode & open_mode::sparse) ret |= file_open_mode::sparse;
|
||||
if (mode & open_mode::no_atime) ret |= file_open_mode::no_atime;
|
||||
|
|
Loading…
Reference in New Issue