mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 21:52:30 +00:00
* Moved Bencode stream functions to object_stream.h and the Bencode
class to object.h. * torrent::download_add(...) now takes an torrent::Object*. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@653 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace torrent {
|
||||
class Bencode;
|
||||
class Object;
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
@@ -50,8 +50,8 @@ public:
|
||||
Variable() {}
|
||||
virtual ~Variable() {}
|
||||
|
||||
virtual const torrent::Bencode& get() = 0;
|
||||
virtual void set(const torrent::Bencode& arg) = 0;
|
||||
virtual const torrent::Object& get() = 0;
|
||||
virtual void set(const torrent::Object& arg) = 0;
|
||||
|
||||
protected:
|
||||
Variable(const Variable&);
|
||||
|
||||
@@ -45,40 +45,40 @@ namespace utils {
|
||||
VariableAny::~VariableAny() {
|
||||
}
|
||||
|
||||
const torrent::Bencode&
|
||||
const torrent::Object&
|
||||
VariableAny::get() {
|
||||
return m_variable;
|
||||
}
|
||||
|
||||
void
|
||||
VariableAny::set(const torrent::Bencode& arg) {
|
||||
VariableAny::set(const torrent::Object& arg) {
|
||||
m_variable = arg;
|
||||
}
|
||||
|
||||
VariableValue::~VariableValue() {
|
||||
}
|
||||
|
||||
const torrent::Bencode&
|
||||
const torrent::Object&
|
||||
VariableValue::get() {
|
||||
return m_variable;
|
||||
}
|
||||
|
||||
void
|
||||
VariableValue::set(const torrent::Bencode& arg) {
|
||||
VariableValue::set(const torrent::Object& arg) {
|
||||
uint64_t value;
|
||||
const char* first;
|
||||
char* last;
|
||||
|
||||
switch (arg.get_type()) {
|
||||
case torrent::Bencode::TYPE_NONE:
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_NONE:
|
||||
m_variable = (int64_t)0;
|
||||
break;
|
||||
|
||||
case torrent::Bencode::TYPE_VALUE:
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
m_variable = arg;
|
||||
break;
|
||||
|
||||
case torrent::Bencode::TYPE_STRING:
|
||||
case torrent::Object::TYPE_STRING:
|
||||
first = arg.as_string().c_str();
|
||||
value = strtoll(first, &last, 0);
|
||||
|
||||
@@ -96,13 +96,13 @@ VariableValue::set(const torrent::Bencode& arg) {
|
||||
VariableBool::~VariableBool() {
|
||||
}
|
||||
|
||||
const torrent::Bencode&
|
||||
const torrent::Object&
|
||||
VariableBool::get() {
|
||||
return m_variable;
|
||||
}
|
||||
|
||||
void
|
||||
VariableBool::set(const torrent::Bencode& arg) {
|
||||
VariableBool::set(const torrent::Object& arg) {
|
||||
if (arg.is_value()) {
|
||||
m_variable = arg.as_value() ? (int64_t)1 : (int64_t)0;
|
||||
|
||||
@@ -124,11 +124,11 @@ VariableBool::set(const torrent::Bencode& arg) {
|
||||
}
|
||||
}
|
||||
|
||||
VariableBencode::~VariableBencode() {
|
||||
VariableObject::~VariableObject() {
|
||||
}
|
||||
|
||||
const torrent::Bencode&
|
||||
VariableBencode::get() {
|
||||
const torrent::Object&
|
||||
VariableObject::get() {
|
||||
if (m_root.empty())
|
||||
return m_bencode->get_key(m_key);
|
||||
else
|
||||
@@ -136,9 +136,9 @@ VariableBencode::get() {
|
||||
}
|
||||
|
||||
void
|
||||
VariableBencode::set(const torrent::Bencode& arg) {
|
||||
VariableObject::set(const torrent::Object& arg) {
|
||||
// Consider removing if TYPE_NONE.
|
||||
torrent::Bencode* root;
|
||||
torrent::Object* root;
|
||||
|
||||
if (m_root.empty())
|
||||
root = m_bencode;
|
||||
@@ -146,20 +146,20 @@ VariableBencode::set(const torrent::Bencode& arg) {
|
||||
root = &m_bencode->get_key(m_root);
|
||||
|
||||
switch (m_type) {
|
||||
case torrent::Bencode::TYPE_NONE:
|
||||
case torrent::Object::TYPE_NONE:
|
||||
root->insert_key(m_key, arg);
|
||||
break;
|
||||
|
||||
case torrent::Bencode::TYPE_STRING:
|
||||
if (arg.get_type() == torrent::Bencode::TYPE_STRING)
|
||||
case torrent::Object::TYPE_STRING:
|
||||
if (arg.type() == torrent::Object::TYPE_STRING)
|
||||
root->insert_key(m_key, arg);
|
||||
else
|
||||
throw torrent::input_error("VariableBencode could not convert to string.");
|
||||
throw torrent::input_error("VariableObject could not convert to string.");
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw torrent::input_error("VariableBencode unsupported type restriction.");
|
||||
throw torrent::input_error("VariableObject unsupported type restriction.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
// Parts of this seems ugly in an attempt to avoid copying
|
||||
// data. Propably need to rewrite torrent::Bencode.
|
||||
// data. Propably need to rewrite torrent::Object.
|
||||
|
||||
#ifndef RTORRENT_UTILS_VARIABLE_GENERIC_H
|
||||
#define RTORRENT_UTILS_VARIABLE_GENERIC_H
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <rak/functional_fun.h>
|
||||
#include <torrent/bencode.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "variable.h"
|
||||
@@ -54,15 +54,15 @@ namespace utils {
|
||||
|
||||
class VariableAny : public Variable {
|
||||
public:
|
||||
VariableAny(const torrent::Bencode& v = torrent::Bencode()) :
|
||||
VariableAny(const torrent::Object& v = torrent::Object()) :
|
||||
m_variable(v) {}
|
||||
virtual ~VariableAny();
|
||||
|
||||
virtual const torrent::Bencode& get();
|
||||
virtual void set(const torrent::Bencode& arg);
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
private:
|
||||
torrent::Bencode m_variable;
|
||||
torrent::Object m_variable;
|
||||
};
|
||||
|
||||
class VariableValue : public Variable {
|
||||
@@ -70,42 +70,42 @@ public:
|
||||
VariableValue(int64_t v) : m_variable(v) {}
|
||||
virtual ~VariableValue();
|
||||
|
||||
virtual const torrent::Bencode& get();
|
||||
virtual void set(const torrent::Bencode& arg);
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
private:
|
||||
torrent::Bencode m_variable;
|
||||
torrent::Object m_variable;
|
||||
};
|
||||
|
||||
class VariableBool : public Variable {
|
||||
public:
|
||||
VariableBool(bool state) : m_variable(state ? (int64_t)1 : (int64_t)0) {}
|
||||
VariableBool(const torrent::Bencode& v = torrent::Bencode((int64_t)0)) { set(v); }
|
||||
VariableBool(const torrent::Object& v = torrent::Object((int64_t)0)) { set(v); }
|
||||
virtual ~VariableBool();
|
||||
|
||||
virtual const torrent::Bencode& get();
|
||||
virtual void set(const torrent::Bencode& arg);
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
private:
|
||||
torrent::Bencode m_variable;
|
||||
torrent::Object m_variable;
|
||||
};
|
||||
|
||||
class VariableBencode : public Variable {
|
||||
class VariableObject : public Variable {
|
||||
public:
|
||||
typedef torrent::Bencode::Type Type;
|
||||
typedef torrent::Object::type_type Type;
|
||||
|
||||
VariableBencode(torrent::Bencode* b,
|
||||
VariableObject(torrent::Object* b,
|
||||
const std::string& root,
|
||||
const std::string& key,
|
||||
Type t = torrent::Bencode::TYPE_NONE) :
|
||||
Type t = torrent::Object::TYPE_NONE) :
|
||||
m_bencode(b), m_root(root), m_key(key), m_type(t) {}
|
||||
virtual ~VariableBencode();
|
||||
virtual ~VariableObject();
|
||||
|
||||
virtual const torrent::Bencode& get();
|
||||
virtual void set(const torrent::Bencode& arg);
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
private:
|
||||
torrent::Bencode* m_bencode;
|
||||
torrent::Object* m_bencode;
|
||||
std::string m_root;
|
||||
std::string m_key;
|
||||
Type m_type;
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
|
||||
virtual ~VariableSlotString() {}
|
||||
|
||||
virtual const torrent::Bencode& get() {
|
||||
virtual const torrent::Object& get() {
|
||||
m_cache = m_slotGet();
|
||||
|
||||
if (!m_cache.is_string())
|
||||
@@ -133,12 +133,12 @@ public:
|
||||
return m_cache;
|
||||
}
|
||||
|
||||
virtual void set(const torrent::Bencode& arg) {
|
||||
switch (arg.get_type()) {
|
||||
case torrent::Bencode::TYPE_STRING:
|
||||
virtual void set(const torrent::Object& arg) {
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_STRING:
|
||||
m_slotSet(arg.as_string());
|
||||
break;
|
||||
case torrent::Bencode::TYPE_NONE:
|
||||
case torrent::Object::TYPE_NONE:
|
||||
m_slotSet("");
|
||||
break;
|
||||
default:
|
||||
@@ -153,7 +153,7 @@ private:
|
||||
// Store the cache here to avoid unnessesary copying and such. This
|
||||
// should not result in any unresonable memory usage since few
|
||||
// strings will be very large.
|
||||
torrent::Bencode m_cache;
|
||||
torrent::Object m_cache;
|
||||
};
|
||||
|
||||
template <typename Get, typename Set>
|
||||
@@ -176,7 +176,7 @@ public:
|
||||
|
||||
virtual ~VariableSlotValue() {}
|
||||
|
||||
virtual const torrent::Bencode& get() {
|
||||
virtual const torrent::Object& get() {
|
||||
m_cache = m_slotGet();
|
||||
|
||||
// Need this?
|
||||
@@ -186,7 +186,7 @@ public:
|
||||
return m_cache;
|
||||
}
|
||||
|
||||
virtual void set(const torrent::Bencode& arg) {
|
||||
virtual void set(const torrent::Object& arg) {
|
||||
if (arg.is_string()) {
|
||||
Set v;
|
||||
|
||||
@@ -213,7 +213,7 @@ private:
|
||||
// Store the cache here to avoid unnessesary copying and such. This
|
||||
// should not result in any unresonable memory usage since few
|
||||
// strings will be very large.
|
||||
torrent::Bencode m_cache;
|
||||
torrent::Object m_cache;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include <rak/functional.h>
|
||||
#include <rak/path.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/bencode.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "variable.h"
|
||||
#include "variable_map.h"
|
||||
@@ -126,7 +126,7 @@ parse_unknown(std::string::const_iterator first, std::string::const_iterator las
|
||||
}
|
||||
|
||||
std::string::const_iterator
|
||||
parse_args(std::string::const_iterator first, std::string::const_iterator last, VariableMap::mapped_type::List* dest) {
|
||||
parse_args(std::string::const_iterator first, std::string::const_iterator last, VariableMap::mapped_type::list_type* dest) {
|
||||
first = std::find_if(first, last, std::not1(variable_map_is_space()));
|
||||
|
||||
while (first != last) {
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
#include <torrent/bencode.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
namespace utils {
|
||||
|
||||
@@ -49,7 +49,7 @@ class Variable;
|
||||
class VariableMap : public std::map<std::string, Variable*> {
|
||||
public:
|
||||
typedef std::map<std::string, Variable*> base_type;
|
||||
typedef torrent::Bencode mapped_type;
|
||||
typedef torrent::Object mapped_type;
|
||||
|
||||
static const int max_size_key = 128;
|
||||
static const int max_size_opt = 1024;
|
||||
|
||||
Reference in New Issue
Block a user