fixing sign-conversion warnings, part 3 (#1537)

fixing sign-conversion warnings, part 3. making aux::vector index type default to int
This commit is contained in:
Alden Torres 2017-01-13 01:55:29 -05:00 committed by Arvid Norberg
parent 77de1e1b43
commit a31ba7972d
11 changed files with 28 additions and 22 deletions

View File

@ -289,7 +289,7 @@ namespace libtorrent
void async_resolve(std::string const& host, int flags
, callback_t const& h) override;
std::vector<torrent*>& torrent_list(int i) override
aux::vector<torrent*>& torrent_list(int i) override
{
TORRENT_ASSERT(i >= 0);
TORRENT_ASSERT(i < session_interface::num_torrent_lists);
@ -724,7 +724,7 @@ namespace libtorrent
// negative, return INT_MAX
int get_int_setting(int n) const;
std::vector<torrent*> m_torrent_lists[num_torrent_lists];
aux::vector<torrent*> m_torrent_lists[num_torrent_lists];
peer_class_pool m_classes;

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/time.hpp"
#include "libtorrent/disk_buffer_holder.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/aux_/vector.hpp"
#include <functional>
#include <memory>
@ -286,7 +287,7 @@ namespace libtorrent { namespace aux
num_torrent_lists
};
virtual std::vector<torrent*>& torrent_list(int i) = 0;
virtual aux::vector<torrent*>& torrent_list(int i) = 0;
virtual bool has_lsd() const = 0;
virtual void announce_lsd(sha1_hash const& ih, int port, bool broadcast = false) = 0;

View File

@ -47,7 +47,7 @@ namespace libtorrent { namespace aux {
template <typename U, typename Tag>
struct underlying_index_t<aux::strong_typedef<U, Tag>> { using type = U; };
template <typename T, typename IndexType>
template <typename T, typename IndexType = int>
struct vector : std::vector<T>
{
using base = std::vector<T>;
@ -94,13 +94,13 @@ namespace libtorrent { namespace aux {
void resize(std::size_t s)
{
TORRENT_ASSERT(s <= std::size_t(std::numeric_limits<underlying_index>::max()));
TORRENT_ASSERT(s <= std::size_t((std::numeric_limits<underlying_index>::max)()));
this->base::resize(s);
}
void resize(std::size_t s, T const& v)
{
TORRENT_ASSERT(s <= std::size_t(std::numeric_limits<underlying_index>::max()));
TORRENT_ASSERT(s <= std::size_t((std::numeric_limits<underlying_index>::max)()));
this->base::resize(s, v);
}
};

View File

@ -315,7 +315,7 @@ namespace libtorrent
// if we're generating a merkle torrent, this is the
// merkle tree we got. This should be saved in fast-resume
// in order to start seeding the torrent
mutable aux::vector<sha1_hash, int> m_merkle_tree;
mutable aux::vector<sha1_hash> m_merkle_tree;
// dht nodes to add to the routing table/bootstrap from
std::vector<std::pair<std::string, int>> m_nodes;

View File

@ -623,7 +623,7 @@ namespace libtorrent
// name for multi-file torrents. The m_name field need to be
// prepended to these paths, and the filename of a specific file
// entry appended, to form full file paths
aux::vector<std::string, int> m_paths;
aux::vector<std::string> m_paths;
// name of torrent. For multi-file torrents
// this is always the root directory

View File

@ -83,12 +83,13 @@ namespace detail
Addr tmp(a);
for (int i = int(tmp.size()) - 1; i >= 0; --i)
{
if (tmp[i] < (std::numeric_limits<typename Addr::value_type>::max)())
auto& t = tmp[std::size_t(i)];
if (t < (std::numeric_limits<typename Addr::value_type>::max)())
{
tmp[i] += 1;
t += 1;
break;
}
tmp[i] = 0;
t = 0;
}
return tmp;
}
@ -101,12 +102,13 @@ namespace detail
Addr tmp(a);
for (int i = int(tmp.size()) - 1; i >= 0; --i)
{
if (tmp[i] > 0)
auto& t = tmp[std::size_t(i)];
if (t > 0)
{
tmp[i] -= 1;
t -= 1;
break;
}
tmp[i] = (std::numeric_limits<typename Addr::value_type>::max)();
t = (std::numeric_limits<typename Addr::value_type>::max)();
}
return tmp;
}

View File

@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_LINK_HPP_INCLUDED
#define TORRENT_LINK_HPP_INCLUDED
#include "libtorrent/aux_/vector.hpp"
namespace libtorrent
{
struct link
@ -48,7 +50,7 @@ namespace libtorrent
void clear() { index = -1; }
template <class T>
void unlink(std::vector<T*>& list, int link_index)
void unlink(aux::vector<T*>& list, int link_index)
{
if (index == -1) return;
TORRENT_ASSERT(index >= 0 && index < int(list.size()));
@ -63,7 +65,7 @@ namespace libtorrent
}
template <class T>
void insert(std::vector<T*>& list, T* self)
void insert(aux::vector<T*>& list, T* self)
{
if (index >= 0) return;
TORRENT_ASSERT(index == -1);

View File

@ -116,7 +116,7 @@ private:
aux::portmap_callback& m_callback;
aux::vector<mapping_t, int> m_mappings;
aux::vector<mapping_t> m_mappings;
// the endpoint to the nat router
udp::endpoint m_nat_endpoint;

View File

@ -1197,7 +1197,7 @@ namespace libtorrent
// us.
aux::suggest_piece m_suggest_pieces;
std::vector<announce_entry> m_trackers;
aux::vector<announce_entry> m_trackers;
// this list is sorted by time_critical_piece::deadline
std::vector<time_critical_piece> m_time_critical_pieces;

View File

@ -349,7 +349,7 @@ private:
std::set<rootdevice> devices;
};
aux::vector<global_mapping_t, int> m_mappings;
aux::vector<global_mapping_t> m_mappings;
std::string m_user_agent;

View File

@ -283,7 +283,8 @@ namespace libtorrent
// if override trackers flag is set, don't load trackers from torrent file
if ((p.flags & add_torrent_params::flag_override_trackers) == 0)
{
m_trackers = m_torrent_file->trackers();
auto const& trackers = m_torrent_file->trackers();
m_trackers = {trackers.begin(), trackers.end()};
}
int tier = 0;
@ -7115,7 +7116,7 @@ namespace libtorrent
void torrent::update_list(int list, bool in)
{
link& l = m_links[list];
std::vector<torrent*>& v = m_ses.torrent_list(list);
aux::vector<torrent*>& v = m_ses.torrent_list(list);
if (in)
{
@ -10464,7 +10465,7 @@ namespace libtorrent
// we're not subscribing to this torrent, don't add it
if (!m_state_subscription) return;
std::vector<torrent*>& list = m_ses.torrent_list(aux::session_interface::torrent_state_updates);
aux::vector<torrent*>& list = m_ses.torrent_list(aux::session_interface::torrent_state_updates);
// if it has already been updated this round, no need to
// add it to the list twice