mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-09 15:49:20 +00:00
* Added VariableBool.
* Added views for downloads, that can be sorted. * Added options "view_add", "view_sort" and "view_new". git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@671 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -42,9 +42,6 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
VariableAny::~VariableAny() {
|
||||
}
|
||||
|
||||
const torrent::Object&
|
||||
VariableAny::get() {
|
||||
return m_variable;
|
||||
@@ -55,14 +52,6 @@ VariableAny::set(const torrent::Object& arg) {
|
||||
m_variable = arg;
|
||||
}
|
||||
|
||||
VariableValue::~VariableValue() {
|
||||
}
|
||||
|
||||
const torrent::Object&
|
||||
VariableValue::get() {
|
||||
return m_variable;
|
||||
}
|
||||
|
||||
void
|
||||
VariableValue::set(const torrent::Object& arg) {
|
||||
uint64_t value;
|
||||
@@ -93,40 +82,31 @@ VariableValue::set(const torrent::Object& arg) {
|
||||
}
|
||||
}
|
||||
|
||||
VariableBool::~VariableBool() {
|
||||
}
|
||||
|
||||
const torrent::Object&
|
||||
VariableBool::get() {
|
||||
return m_variable;
|
||||
}
|
||||
|
||||
void
|
||||
VariableBool::set(const torrent::Object& arg) {
|
||||
if (arg.is_value()) {
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
m_variable = arg.as_value() ? (int64_t)1 : (int64_t)0;
|
||||
break;
|
||||
|
||||
} else if (arg.is_string()) {
|
||||
|
||||
if (arg.as_string() == "yes" ||
|
||||
arg.as_string() == "true")
|
||||
case torrent::Object::TYPE_STRING:
|
||||
// Move the checks into some is_true, is_false think in Variable.
|
||||
if (arg.as_string() == "yes" || arg.as_string() == "true")
|
||||
m_variable = (int64_t)1;
|
||||
|
||||
else if (arg.as_string() == "no" ||
|
||||
arg.as_string() == "false")
|
||||
else if (arg.as_string() == "no" || arg.as_string() == "false")
|
||||
m_variable = (int64_t)0;
|
||||
|
||||
else
|
||||
throw torrent::input_error("String does not parse as a boolean.");
|
||||
|
||||
} else {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw torrent::input_error("Input is not a boolean.");
|
||||
}
|
||||
}
|
||||
|
||||
VariableObject::~VariableObject() {
|
||||
}
|
||||
|
||||
const torrent::Object&
|
||||
VariableObject::get() {
|
||||
if (m_root.empty())
|
||||
|
||||
@@ -56,38 +56,26 @@ class VariableAny : public Variable {
|
||||
public:
|
||||
VariableAny(const torrent::Object& v = torrent::Object()) :
|
||||
m_variable(v) {}
|
||||
virtual ~VariableAny();
|
||||
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
private:
|
||||
protected:
|
||||
torrent::Object m_variable;
|
||||
};
|
||||
|
||||
class VariableValue : public Variable {
|
||||
class VariableValue : public VariableAny {
|
||||
public:
|
||||
VariableValue(int64_t v) : m_variable(v) {}
|
||||
virtual ~VariableValue();
|
||||
VariableValue(int64_t v) { m_variable = v; }
|
||||
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
private:
|
||||
torrent::Object m_variable;
|
||||
};
|
||||
|
||||
class VariableBool : public Variable {
|
||||
public:
|
||||
VariableBool(bool state) : m_variable(state ? (int64_t)1 : (int64_t)0) {}
|
||||
VariableBool(const torrent::Object& v = torrent::Object((int64_t)0)) { set(v); }
|
||||
virtual ~VariableBool();
|
||||
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
};
|
||||
|
||||
private:
|
||||
torrent::Object m_variable;
|
||||
class VariableBool : public VariableAny {
|
||||
public:
|
||||
VariableBool(bool state = false) { m_variable = state ? (int64_t)1 : (int64_t)0; }
|
||||
|
||||
virtual void set(const torrent::Object& arg);
|
||||
};
|
||||
|
||||
class VariableObject : public Variable {
|
||||
@@ -99,13 +87,12 @@ public:
|
||||
const std::string& key,
|
||||
Type t = torrent::Object::TYPE_NONE) :
|
||||
m_bencode(b), m_root(root), m_key(key), m_type(t) {}
|
||||
virtual ~VariableObject();
|
||||
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
private:
|
||||
torrent::Object* m_bencode;
|
||||
torrent::Object* m_bencode;
|
||||
std::string m_root;
|
||||
std::string m_key;
|
||||
Type m_type;
|
||||
|
||||
@@ -65,8 +65,8 @@ VariableMap::insert(const std::string& key, Variable* v) {
|
||||
}
|
||||
|
||||
const VariableMap::mapped_type&
|
||||
VariableMap::get(const std::string& key) {
|
||||
iterator itr = base_type::find(key);
|
||||
VariableMap::get(const std::string& key) const {
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
throw torrent::input_error("Variable \"" + key + "\" does not exist.");
|
||||
|
||||
@@ -50,6 +50,7 @@ class VariableMap : public std::map<std::string, Variable*> {
|
||||
public:
|
||||
typedef std::map<std::string, Variable*> base_type;
|
||||
typedef torrent::Object mapped_type;
|
||||
typedef mapped_type::value_type mapped_value_type;
|
||||
|
||||
static const int max_size_key = 128;
|
||||
static const int max_size_opt = 1024;
|
||||
@@ -65,8 +66,9 @@ public:
|
||||
|
||||
// Consider taking char* start and finish instead of std::string to
|
||||
// avoid copying. Or make a view class.
|
||||
const mapped_type& get(const std::string& key);
|
||||
const std::string& get_string(const std::string& key) { return get(key).as_string(); }
|
||||
const mapped_type& get(const std::string& key) const;
|
||||
const std::string& get_string(const std::string& key) const { return get(key).as_string(); }
|
||||
mapped_value_type get_value(const std::string& key) const { return get(key).as_value(); }
|
||||
|
||||
void set(const std::string& key, const mapped_type& arg);
|
||||
void set_string(const std::string& key, const std::string& arg) { set(key, mapped_type(arg)); }
|
||||
|
||||
Reference in New Issue
Block a user