lazy bdecoder additions and fixes

This commit is contained in:
Arvid Norberg 2008-04-19 03:00:07 +00:00
parent b452020404
commit 72176a9256
2 changed files with 54 additions and 3 deletions

View File

@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <utility>
#include <vector>
#include "libtorrent/assert.hpp"
#include <boost/cstdint.hpp>
#include "libtorrent/size_type.hpp"
#include <iosfwd>
namespace libtorrent
@ -71,7 +71,7 @@ namespace libtorrent
m_end = start + length + 1; // include 'e'
}
boost::int64_t int_value() const;
size_type int_value() const;
// string functions
// ================
@ -119,6 +119,12 @@ namespace libtorrent
lazy_entry* dict_find(char const* name);
lazy_entry const* dict_find(char const* name) const
{ 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
{
TORRENT_ASSERT(m_type == dict_t);
@ -154,6 +160,9 @@ namespace libtorrent
lazy_entry const* list_at(int i) const
{ 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
{
TORRENT_ASSERT(m_type == list_t);

View File

@ -158,7 +158,7 @@ namespace libtorrent
return 0;
}
boost::int64_t lazy_entry::int_value() const
size_type lazy_entry::int_value() const
{
TORRENT_ASSERT(m_type == int_t);
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)
{
TORRENT_ASSERT(m_type == dict_t);
@ -279,6 +307,20 @@ namespace libtorrent
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()
{
switch (m_type)