* Last of the old commands moved.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@903 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-05-18 20:34:31 +00:00
parent 7d1bb524ba
commit d33d283293
14 changed files with 163 additions and 284 deletions
+62 -61
View File
@@ -86,9 +86,9 @@ private:
// function calls.
template <typename Func, typename Result = typename Func::result_type>
class object_d_void_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
class object_void_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_d_void_fn_t(Func func) : m_func(func) {}
object_void_d_fn_t(Func func) : m_func(func) {}
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) { return torrent::Object(m_func(download)); }
@@ -96,80 +96,72 @@ private:
Func m_func;
};
// template <typename Func>
// class object_void_fn_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
// public:
// object_void_fn_t(Func func) : m_func(func) {}
template <typename Func>
class object_void_d_fn_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_void_d_fn_t(Func func) : m_func(func) {}
// virtual torrent::Object operator () (const torrent::Object& arg1) {
// m_func();
// return torrent::Object();
// }
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
m_func(download);
return torrent::Object();
}
// private:
// Func m_func;
// };
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) {}
template <typename Func, typename Result = typename Func::result_type>
class object_value_d_fn1_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_value_d_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())); }
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
return torrent::Object((int64_t)m_func(download, arg1.as_value()));
}
// private:
// Func m_func;
// };
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) {}
template <typename Func>
class object_value_d_fn1_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_value_d_fn1_t(Func func) : m_func(func) {}
// virtual torrent::Object operator () (const torrent::Object& arg1) {
// m_func(arg1.as_value());
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
m_func(download, arg1.as_value());
return torrent::Object();
}
// return torrent::Object();
// }
private:
Func m_func;
};
// 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:
// object_string_fn1_t(Func func) : m_func(func) {}
template <typename Func, typename Result = typename Func::result_type>
class object_string_d_fn1_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_string_d_fn1_t(Func func) : m_func(func) {}
// virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object(m_func(arg1.as_string())); }
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) { return torrent::Object(m_func(download, arg1.as_string())); }
// private:
// Func m_func;
// };
private:
Func m_func;
};
// template <typename Func>
// class object_string_fn1_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
// public:
// object_string_fn1_t(Func func) : m_func(func) {}
template <typename Func>
class object_string_d_fn1_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
object_string_d_fn1_t(Func func) : m_func(func) {}
// virtual torrent::Object operator () (const torrent::Object& arg1) {
// m_func(arg1.as_string());
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
m_func(download, arg1.as_string());
// return torrent::Object();
// }
return torrent::Object();
}
// private:
// Func m_func;
// };
template <typename Return> object_d_void_fn_t<Return (*)(core::Download*), Return>*
object_d_fn(Return (*func)(core::Download*)) {
return new object_d_void_fn_t<Return (*)(core::Download*), 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); }
private:
Func m_func;
};
class set_variable_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
public:
@@ -193,6 +185,15 @@ private:
const char* m_secondKey;
};
template <typename Return> object_void_d_fn_t<Return (*)(core::Download*), Return>*
object_d_fn(Return (*func)(core::Download*)) {
return new object_void_d_fn_t<Return (*)(core::Download*), Return>(func);
}
template <typename Func> object_void_d_fn_t<Func>* object_void_d_fn(Func func) { return new object_void_d_fn_t<Func>(func); }
template <typename Func> object_value_d_fn1_t<Func>* object_value_d_fn(Func func) { return new object_value_d_fn1_t<Func>(func); }
template <typename Func> object_string_d_fn1_t<Func>* object_string_d_fn(Func func) { return new object_string_d_fn1_t<Func>(func); }
inline set_variable_d_fn_t*
set_variable_d_fn(const char* firstKey, const char* secondKey) { return new set_variable_d_fn_t(firstKey, secondKey); }
inline get_variable_d_fn_t*
+11
View File
@@ -72,6 +72,17 @@ VariableMap::insert(key_type key, Variable* variable, generic_slot genericSlot,
base_type::insert(itr, value_type(key, variable_map_data_type(variable, genericSlot, downloadSlot, flags, parm, doc)));
}
void
VariableMap::insert(key_type key, const variable_map_data_type src) {
iterator itr = base_type::find(key);
if (itr != base_type::end())
throw torrent::internal_error("VariableMap::insert(...) tried to insert an already existing key.");
base_type::insert(itr, value_type(key, variable_map_data_type(src.m_variable, src.m_genericSlot, src.m_downloadSlot,
src.m_flags | flag_dont_delete, src.m_parm, src.m_doc)));
}
const VariableMap::mapped_type
VariableMap::get_d(core::Download* download, key_type key) const {
const_iterator itr = base_type::find(key);
+3
View File
@@ -96,6 +96,7 @@ public:
using base_type::begin;
using base_type::end;
using base_type::find;
static const int max_size_key = 128;
static const int max_size_opt = 1024;
@@ -115,6 +116,8 @@ public:
void insert(key_type key, Variable* variable, generic_slot genericSlot = NULL, download_slot downloadSlot = NULL, int flags = 0,
const char* parm = "", const char* doc = "");
void insert(key_type key, const variable_map_data_type src);
// Consider uninlining the helper functions.
const mapped_type get_d(core::Download* download, key_type key) const;
const std::string get_d_string(core::Download* download, key_type key) const { return get_d(download, key).as_string(); }