lazy bdecoder additions and fixes
This commit is contained in:
parent
b452020404
commit
72176a9256
|
@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "libtorrent/assert.hpp"
|
#include "libtorrent/assert.hpp"
|
||||||
#include <boost/cstdint.hpp>
|
#include "libtorrent/size_type.hpp"
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
|
@ -71,7 +71,7 @@ namespace libtorrent
|
||||||
m_end = start + length + 1; // include 'e'
|
m_end = start + length + 1; // include 'e'
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::int64_t int_value() const;
|
size_type int_value() const;
|
||||||
|
|
||||||
// string functions
|
// string functions
|
||||||
// ================
|
// ================
|
||||||
|
@ -119,6 +119,12 @@ namespace libtorrent
|
||||||
lazy_entry* dict_find(char const* name);
|
lazy_entry* dict_find(char const* name);
|
||||||
lazy_entry const* dict_find(char const* name) const
|
lazy_entry const* dict_find(char const* name) const
|
||||||
{ return const_cast<lazy_entry*>(this)->dict_find(name); }
|
{ return const_cast<lazy_entry*>(this)->dict_find(name); }
|
||||||
|
|
||||||
|
std::string dict_find_string_value(char const* name) const;
|
||||||
|
size_type dict_find_int_value(char const* name, size_type default_val = 0) const;
|
||||||
|
lazy_entry const* dict_find_dict(char const* name) const;
|
||||||
|
lazy_entry const* dict_find_list(char const* name) const;
|
||||||
|
|
||||||
std::pair<char const*, lazy_entry const*> dict_at(int i) const
|
std::pair<char const*, lazy_entry const*> dict_at(int i) const
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_type == dict_t);
|
TORRENT_ASSERT(m_type == dict_t);
|
||||||
|
@ -154,6 +160,9 @@ namespace libtorrent
|
||||||
lazy_entry const* list_at(int i) const
|
lazy_entry const* list_at(int i) const
|
||||||
{ return const_cast<lazy_entry*>(this)->list_at(i); }
|
{ return const_cast<lazy_entry*>(this)->list_at(i); }
|
||||||
|
|
||||||
|
std::string list_string_value_at(int i) const;
|
||||||
|
size_type list_int_value_at(int i, size_type default_val = 0) const;
|
||||||
|
|
||||||
int list_size() const
|
int list_size() const
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_type == list_t);
|
TORRENT_ASSERT(m_type == list_t);
|
||||||
|
|
|
@ -158,7 +158,7 @@ namespace libtorrent
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::int64_t lazy_entry::int_value() const
|
size_type lazy_entry::int_value() const
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_type == int_t);
|
TORRENT_ASSERT(m_type == int_t);
|
||||||
boost::int64_t val = 0;
|
boost::int64_t val = 0;
|
||||||
|
@ -241,6 +241,34 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lazy_entry::dict_find_string_value(char const* name) const
|
||||||
|
{
|
||||||
|
lazy_entry const* e = dict_find(name);
|
||||||
|
if (e == 0 || e->type() != lazy_entry::string_t) return std::string();
|
||||||
|
return e->string_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_type lazy_entry::dict_find_int_value(char const* name, size_type default_val) const
|
||||||
|
{
|
||||||
|
lazy_entry const* e = dict_find(name);
|
||||||
|
if (e == 0 || e->type() != lazy_entry::int_t) return default_val;
|
||||||
|
return e->int_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_entry const* lazy_entry::dict_find_dict(char const* name) const
|
||||||
|
{
|
||||||
|
lazy_entry const* e = dict_find(name);
|
||||||
|
if (e == 0 || e->type() != lazy_entry::dict_t) return 0;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_entry const* lazy_entry::dict_find_list(char const* name) const
|
||||||
|
{
|
||||||
|
lazy_entry const* e = dict_find(name);
|
||||||
|
if (e == 0 || e->type() != lazy_entry::list_t) return 0;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
lazy_entry* lazy_entry::dict_find(char const* name)
|
lazy_entry* lazy_entry::dict_find(char const* name)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(m_type == dict_t);
|
TORRENT_ASSERT(m_type == dict_t);
|
||||||
|
@ -279,6 +307,20 @@ namespace libtorrent
|
||||||
return m_data.list + (m_size++);
|
return m_data.list + (m_size++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lazy_entry::list_string_value_at(int i) const
|
||||||
|
{
|
||||||
|
lazy_entry const* e = list_at(i);
|
||||||
|
if (e == 0 || e->type() != lazy_entry::string_t) return std::string();
|
||||||
|
return e->string_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_type lazy_entry::list_int_value_at(int i, size_type default_val) const
|
||||||
|
{
|
||||||
|
lazy_entry const* e = list_at(i);
|
||||||
|
if (e == 0 || e->type() != lazy_entry::int_t) return default_val;
|
||||||
|
return e->int_value();
|
||||||
|
}
|
||||||
|
|
||||||
void lazy_entry::clear()
|
void lazy_entry::clear()
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
|
|
Loading…
Reference in New Issue