convert enum values that are just used as constants, to actual constants with the correct type

This commit is contained in:
arvidn 2017-08-03 03:57:15 -07:00 committed by Arvid Norberg
parent a8a5986046
commit 6b1037eff5
15 changed files with 46 additions and 48 deletions

View File

@ -2687,7 +2687,7 @@ namespace libtorrent {
#undef TORRENT_DEFINE_ALERT
#undef TORRENT_DEFINE_ALERT_PRIO
enum { num_alert_types = 95 }; // this enum represents "max_alert_index" + 1
constexpr int num_alert_types = 95; // this constant represents "max_alert_index" + 1
}
#endif

View File

@ -240,7 +240,8 @@ namespace aux {
, std::enable_shared_from_this<session_impl>
{
// the size of each allocation that is chained in the send buffer
enum { send_buffer_size_impl = 128 };
static constexpr int send_buffer_size_impl = 128;
// plugin feature-index key map
enum
{

View File

@ -129,7 +129,7 @@ namespace aux {
char* buf;
enum { max_refcount = (1 << 29) - 1 };
static constexpr int max_refcount = (1 << 29) - 1;
// the number of references to this buffer. These references
// might be in outstanding asynchronous requests or in peer

View File

@ -76,7 +76,7 @@ namespace libtorrent { namespace dht {
int count;
};
enum { num_ban_nodes = 20 };
static constexpr int num_ban_nodes = 20;
// the max number of packets we can receive per second from a node before
// we block it.

View File

@ -99,7 +99,7 @@ namespace aux {
piece_block block;
enum { not_in_buffer = 0x1fffffff };
static constexpr std::uint32_t not_in_buffer = 0x1fffffff;
// the number of bytes into the send buffer this request is. Every time
// some portion of the send buffer is transmitted, this offset is

View File

@ -577,15 +577,13 @@ namespace libtorrent {
// index is set to this to indicate that we have the
// piece. There is no entry for the piece in the
// buckets if this is the case.
constexpr static prio_index_t we_have_index{-1};
static constexpr prio_index_t we_have_index{-1};
enum : std::uint32_t
{
// the priority value that means the piece is filtered
filter_priority = 0,
// the max number the peer count can hold
max_peer_count = 0xffff
};
// the priority value that means the piece is filtered
static constexpr std::uint32_t filter_priority = 0;
// the max number the peer count can hold
static constexpr std::uint32_t max_peer_count = 0xffff;
bool have() const { return index == we_have_index; }
void set_have() { index = we_have_index; TORRENT_ASSERT(have()); }

View File

@ -67,7 +67,7 @@ namespace aux {
class digest32
{
static_assert(N % 32 == 0, "N must be a multiple of 32");
enum { number_size = N / 32 };
static constexpr int number_size = N / 32;
public:
// the size of the hash in bytes
@ -143,14 +143,14 @@ namespace aux {
// shift left ``n`` bits.
digest32& operator<<=(int n)
{
aux::bits_shift_left({m_number, number_size}, n);
aux::bits_shift_left({m_number, std::size_t(number_size)}, n);
return *this;
}
// shift right ``n`` bits.
digest32& operator>>=(int n)
{
aux::bits_shift_right({m_number, number_size}, n);
aux::bits_shift_right({m_number, std::size_t(number_size)}, n);
return *this;
}
@ -177,7 +177,7 @@ namespace aux {
int count_leading_zeroes() const
{
return aux::count_leading_zeros({m_number, number_size});
return aux::count_leading_zeros({m_number, std::size_t(number_size)});
}
// returns a bit-wise negated copy of the digest

View File

@ -133,46 +133,46 @@ namespace libtorrent {
template <class S>
struct socket_type_int_impl
{ enum { value = 0 }; };
{ static constexpr int value = 0; };
template <>
struct socket_type_int_impl<tcp::socket>
{ enum { value = 1 }; };
{ static constexpr int value = 1; };
template <>
struct socket_type_int_impl<socks5_stream>
{ enum { value = 2 }; };
{ static constexpr int value = 2; };
template <>
struct socket_type_int_impl<http_stream>
{ enum { value = 3 }; };
{ static constexpr int value = 3; };
template <>
struct socket_type_int_impl<utp_stream>
{ enum { value = 4 }; };
{ static constexpr int value = 4; };
#if TORRENT_USE_I2P
template <>
struct socket_type_int_impl<i2p_stream>
{ enum { value = 5 }; };
{ static constexpr int value = 5; };
#endif
#ifdef TORRENT_USE_OPENSSL
template <>
struct socket_type_int_impl<ssl_stream<tcp::socket>>
{ enum { value = 6 }; };
{ static constexpr int value = 6; };
template <>
struct socket_type_int_impl<ssl_stream<socks5_stream>>
{ enum { value = 7 }; };
{ static constexpr int value = 7; };
template <>
struct socket_type_int_impl<ssl_stream<http_stream>>
{ enum { value = 8 }; };
{ static constexpr int value = 8; };
template <>
struct socket_type_int_impl<ssl_stream<utp_stream>>
{ enum { value = 9 }; };
{ static constexpr int value = 9; };
#endif
struct TORRENT_EXTRA_EXPORT socket_type

View File

@ -44,7 +44,7 @@ namespace libtorrent {
// seen in the last 20 minutes
struct TORRENT_EXTRA_EXPORT timestamp_history
{
enum { history_size = 20 };
static constexpr int history_size = 20;
timestamp_history() : m_base(0), m_index(0), m_num_samples(not_initialized) {}
bool initialized() const { return m_num_samples != not_initialized; }
@ -68,7 +68,7 @@ private:
// in the circular buffer
std::uint16_t m_index;
enum { not_initialized = 0xffff };
static constexpr std::uint16_t not_initialized = 0xffff;
// this is the number of samples since the
// last time we stepped one minute. If we

View File

@ -1135,7 +1135,7 @@ namespace libtorrent {
}
void add_suggest_piece(piece_index_t index);
enum { no_gauge_state = 0xf };
static constexpr int no_gauge_state = 0xf;
private:

View File

@ -202,12 +202,6 @@ private:
static address_v4 upnp_multicast_address;
static udp::endpoint upnp_multicast_endpoint;
// there are routers that's don't support timed
// port maps, without returning error 725. It seems
// safer to always assume that we have to ask for
// permanent leases
enum { default_lease_time = 0 };
void resend_request(error_code const& e);
void on_reply(udp::endpoint const& from, char* buffer
, std::size_t bytes_transferred);
@ -294,7 +288,11 @@ private:
std::string path;
address external_ip;
int lease_duration = default_lease_time;
// there are routers that's don't support timed
// port maps, without returning error 725. It seems
// safer to always assume that we have to ask for
// permanent leases
int lease_duration = 0;
// true if the device supports specifying a
// specific external port, false if it doesn't

View File

@ -100,7 +100,8 @@ const unsigned long siocgifmtu = SIOCGIFMTU;
#define IF_NAMESIZE IFNAMSIZ
#endif
namespace libtorrent {namespace {
namespace libtorrent {
namespace {
#if !defined TORRENT_BUILD_SIMULATOR
@ -201,7 +202,7 @@ namespace libtorrent {namespace {
return msg_len;
}
enum { NL_BUFSIZE = 8192 };
constexpr int NL_BUFSIZE = 8192;
int nl_dump_request(int sock, std::uint16_t type, std::uint32_t seq, char family, span<char> msg, std::size_t msg_len)
{
@ -495,9 +496,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
}
#endif
}} // <anonymous>
namespace libtorrent {
} // <anonymous>
// return (a1 & mask) == (a2 & mask)
bool match_addr_mask(address const& a1, address const& a2, address const& mask)

View File

@ -78,7 +78,7 @@ namespace {
};
// TODO: 2 make this configurable in dht_settings
enum { announce_interval = 30 };
constexpr time_duration announce_interval = minutes(30);
struct dht_immutable_item
{
@ -552,7 +552,7 @@ namespace {
auto new_end = std::remove_if(peers.begin(), peers.end()
, [=](peer_entry const& e)
{
return e.added + minutes(int(announce_interval * 3 / 2)) < now;
return e.added + announce_interval * 3 / 2 < now;
});
m_counters.peers -= std::int32_t(std::distance(new_end, peers.end()));

View File

@ -210,7 +210,7 @@ namespace libtorrent {
, m_ssl_torrent(false)
, m_deleted(false)
, m_auto_managed(p.flags & torrent_flags::auto_managed)
, m_current_gauge_state(no_gauge_state)
, m_current_gauge_state(static_cast<std::uint32_t>(no_gauge_state))
, m_moving_storage(false)
, m_inactive(false)
, m_downloaded(0xffffff)
@ -534,7 +534,9 @@ namespace libtorrent {
if (new_gauge_state != no_gauge_state)
inc_stats_counter(new_gauge_state + counters::num_checking_torrents, 1);
m_current_gauge_state = aux::numeric_cast<std::uint8_t>(new_gauge_state);
TORRENT_ASSERT(new_gauge_state >= 0);
TORRENT_ASSERT(new_gauge_state <= no_gauge_state);
m_current_gauge_state = static_cast<std::uint32_t>(new_gauge_state);
}
void torrent::leave_seed_mode(bool skip_checking)
@ -9345,7 +9347,7 @@ namespace libtorrent {
{
// this is a silly optimization
// to avoid copying of strings
enum { num_strings = 200 };
int const num_strings = 200;
static char buf[num_strings][20];
static int round_robin = 0;
char* ret = buf[round_robin];

View File

@ -1377,7 +1377,7 @@ void upnp::on_upnp_map_response(error_code const& e
if (s.error_code == 725)
{
// only permanent leases supported
// The gateway only supports permanent leases
d.lease_duration = 0;
m.act = portmap_action::add;
++m.failcount;