mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-15 06:32:31 +00:00
* More commands moved to the new system.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@897 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "utils/parse.h"
|
||||
|
||||
#include "command_slot.h"
|
||||
|
||||
namespace utils {
|
||||
@@ -87,6 +89,30 @@ CommandSlot::call_list(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_value_base(Variable* rawVariable, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
return command->m_slot(arg);
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
torrent::Object argValue(torrent::Object::TYPE_VALUE);
|
||||
|
||||
if (!utils::parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
|
||||
throw torrent::input_error("Not a value.");
|
||||
|
||||
return command->m_slot(argValue);
|
||||
}
|
||||
default:
|
||||
throw torrent::input_error("Not a value.");
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_string(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
@@ -74,6 +74,14 @@ public:
|
||||
static const torrent::Object call_list(Variable* rawVariable, const torrent::Object& args);
|
||||
static const torrent::Object call_string(Variable* rawVariable, const torrent::Object& args);
|
||||
|
||||
static const torrent::Object call_value_base(Variable* rawVariable, const torrent::Object& args, int base, int unit);
|
||||
|
||||
static const torrent::Object call_value(Variable* rawVariable, const torrent::Object& args) { return call_value_base(rawVariable, args, 0, 1); }
|
||||
static const torrent::Object call_value_kb(Variable* rawVariable, const torrent::Object& args) { return call_value_base(rawVariable, args, 0, 1 << 10); }
|
||||
|
||||
template <int base, int unit>
|
||||
static const torrent::Object call_value(Variable* rawVariable, const torrent::Object& args) { return call_value_base(rawVariable, args, base, unit); }
|
||||
|
||||
// static const torrent::Object& get_list(Variable* rawVariable, const torrent::Object& args);
|
||||
|
||||
private:
|
||||
@@ -108,6 +116,32 @@ private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_value_fn1_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_value_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object((int64_t)m_func(arg1.as_value())); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_value_fn1_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_value_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) {
|
||||
m_func(arg1.as_value());
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_string_fn1_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
@@ -137,6 +171,7 @@ private:
|
||||
template <typename Return> object_void_fn_t<Return (*)(void), Return>* object_fn(Return (*func)(void)) { return new object_void_fn_t<Return (*)(void), Return>(func); }
|
||||
|
||||
template <typename Func> object_void_fn_t<Func>* object_void_fn(Func func) { return new object_void_fn_t<Func>(func); }
|
||||
template <typename Func> object_value_fn1_t<Func>* object_value_fn(Func func) { return new object_value_fn1_t<Func>(func); }
|
||||
template <typename Func> object_string_fn1_t<Func>* object_string_fn(Func func) { return new object_string_fn1_t<Func>(func); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user