mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 22:29:23 +00:00
* Changed command_base stored in CommandMap from a pointer to an instance.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1169 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+9
-4
@@ -160,7 +160,9 @@ public:
|
||||
};
|
||||
|
||||
command_base() { new (&_pod<base_function>()) base_function(); }
|
||||
virtual ~command_base() { _pod<base_function>().~base_function(); }
|
||||
command_base(const command_base& src) { new (&_pod<base_function>()) base_function(src._pod<base_function>()); }
|
||||
|
||||
~command_base() { _pod<base_function>().~base_function(); }
|
||||
|
||||
static torrent::Object* argument(unsigned int index) { return current_stack.begin() + index; }
|
||||
static torrent::Object& argument_ref(unsigned int index) { return *(current_stack.begin() + index); }
|
||||
@@ -188,14 +190,17 @@ public:
|
||||
// template types, yet what the C++0x standard will say about this I
|
||||
// have no idea atm.
|
||||
template <typename tmpl> tmpl& _pod() { return reinterpret_cast<tmpl&>(t_pod); }
|
||||
template <typename tmpl> const tmpl& _pod() const { return reinterpret_cast<const tmpl&>(t_pod); }
|
||||
|
||||
template <typename Func, typename T, typename Args>
|
||||
static const torrent::Object _call(command_base* cmd, target_type target, Args args);
|
||||
|
||||
protected:
|
||||
command_base(const command_base&);
|
||||
void operator = (const command_base&);
|
||||
command_base& operator = (const command_base& src) {
|
||||
_pod<base_function>() = src._pod<base_function>();
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
// For use by functions that need to use placeholders to arguments
|
||||
// within commands. E.d. callable command strings where one of the
|
||||
// arguments within the command needs to be supplied by the caller.
|
||||
|
||||
+21
-63
@@ -61,8 +61,8 @@ CommandMap::~CommandMap() {
|
||||
std::vector<const char*> keys;
|
||||
|
||||
for (iterator itr = base_type::begin(), last = base_type::end(); itr != last; itr++) {
|
||||
if (!(itr->second.m_flags & flag_dont_delete))
|
||||
delete itr->second.m_variable;
|
||||
// if (!(itr->second.m_flags & flag_dont_delete))
|
||||
// delete itr->second.m_variable;
|
||||
|
||||
if (itr->second.m_flags & flag_delete_key)
|
||||
keys.push_back(itr->first);
|
||||
@@ -73,7 +73,7 @@ CommandMap::~CommandMap() {
|
||||
}
|
||||
|
||||
CommandMap::iterator
|
||||
CommandMap::insert(key_type key, command_base* variable, int flags, const char* parm, const char* doc) {
|
||||
CommandMap::insert(key_type key, int flags, const char* parm, const char* doc) {
|
||||
iterator itr = base_type::find(key);
|
||||
|
||||
if (itr != base_type::end())
|
||||
@@ -82,21 +82,21 @@ CommandMap::insert(key_type key, command_base* variable, int flags, const char*
|
||||
if (rpc::xmlrpc.is_valid())
|
||||
rpc::xmlrpc.insert_command(key, parm, doc);
|
||||
|
||||
return base_type::insert(itr, value_type(key, command_map_data_type(variable, flags, parm, doc)));
|
||||
return base_type::insert(itr, value_type(key, command_map_data_type(flags, parm, doc)));
|
||||
}
|
||||
|
||||
void
|
||||
CommandMap::insert(key_type key, const command_map_data_type src) {
|
||||
iterator itr = base_type::find(key);
|
||||
// void
|
||||
// CommandMap::insert(key_type key, const command_map_data_type src) {
|
||||
// iterator itr = base_type::find(key);
|
||||
|
||||
if (itr != base_type::end())
|
||||
throw torrent::internal_error("CommandMap::insert(...) tried to insert an already existing key.");
|
||||
// if (itr != base_type::end())
|
||||
// throw torrent::internal_error("CommandMap::insert(...) tried to insert an already existing key.");
|
||||
|
||||
itr = base_type::insert(itr, value_type(key, command_map_data_type(src.m_variable, src.m_flags | flag_dont_delete, src.m_parm, src.m_doc)));
|
||||
// itr = base_type::insert(itr, value_type(key, command_map_data_type(src.m_variable, src.m_flags | flag_dont_delete, src.m_parm, src.m_doc)));
|
||||
|
||||
// We can assume all the slots are the same size.
|
||||
itr->second.m_anySlot = src.m_anySlot;
|
||||
}
|
||||
// // We can assume all the slots are the same size.
|
||||
// itr->second.m_anySlot = src.m_anySlot;
|
||||
// }
|
||||
|
||||
void
|
||||
CommandMap::erase(iterator itr) {
|
||||
@@ -107,8 +107,8 @@ CommandMap::erase(iterator itr) {
|
||||
if (itr->second.m_flags & flag_has_redirects)
|
||||
throw torrent::input_error("Can't erase a command that has redirects.");
|
||||
|
||||
if (!(itr->second.m_flags & flag_dont_delete))
|
||||
delete itr->second.m_variable;
|
||||
// if (!(itr->second.m_flags & flag_dont_delete))
|
||||
// delete itr->second.m_variable;
|
||||
|
||||
const char* key = itr->second.m_flags & flag_delete_key ? itr->first : NULL;
|
||||
|
||||
@@ -137,12 +137,12 @@ CommandMap::create_redirect(key_type key_new, key_type key_dest, int flags) {
|
||||
flags |= dest_itr->second.m_flags & ~(flag_delete_key | flag_has_redirects);
|
||||
|
||||
iterator itr = base_type::insert(base_type::end(),
|
||||
value_type(key_new, command_map_data_type(dest_itr->second.m_variable,
|
||||
flags,
|
||||
value_type(key_new, command_map_data_type(flags,
|
||||
dest_itr->second.m_parm,
|
||||
dest_itr->second.m_doc)));
|
||||
|
||||
// We can assume all the slots are the same size.
|
||||
itr->second.m_variable = dest_itr->second.m_variable;
|
||||
itr->second.m_anySlot = dest_itr->second.m_anySlot;
|
||||
}
|
||||
|
||||
@@ -158,59 +158,17 @@ CommandMap::call_catch(key_type key, target_type target, const mapped_type& args
|
||||
|
||||
const CommandMap::mapped_type
|
||||
CommandMap::call_command(key_type key, const mapped_type& arg, target_type target) {
|
||||
const_iterator itr = base_type::find(key);
|
||||
iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
throw torrent::input_error("Command \"" + std::string(key) + "\" does not exist.");
|
||||
|
||||
// if (target.first != Command::target_generic && target.second == NULL) {
|
||||
// // We received a target that is NULL, so throw an exception unless
|
||||
// // we can convert it to a void target.
|
||||
// if (itr->second.m_target > Command::target_any)
|
||||
// throw torrent::input_error("Command type mis-match.");
|
||||
|
||||
// target.first = Command::target_generic;
|
||||
// }
|
||||
|
||||
// if (itr->second.m_target != target.first && itr->second.m_target > Command::target_any) {
|
||||
// // Mismatch between the target and command type. If it is not
|
||||
// // possible to convert, then throw an input error.
|
||||
// if (target.first == Command::target_file_itr && itr->second.m_target == Command::target_file)
|
||||
// target = target_type((int)Command::target_file, static_cast<torrent::FileListIterator*>(target.second)->file());
|
||||
// else
|
||||
// throw torrent::input_error("Command type mis-match.");
|
||||
// }
|
||||
|
||||
// This _should_ be optimized int just two calls.
|
||||
// switch (itr->second.m_target) {
|
||||
// case Command::target_any: return itr->second.m_anySlot(itr->second.m_variable, target, arg);
|
||||
// default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target.");
|
||||
// }
|
||||
|
||||
return itr->second.m_anySlot(itr->second.m_variable, target, arg);
|
||||
return itr->second.m_anySlot(&itr->second.m_variable, target, arg);
|
||||
}
|
||||
|
||||
const CommandMap::mapped_type
|
||||
CommandMap::call_command(const_iterator itr, const mapped_type& arg, target_type target) {
|
||||
// if (target.first != Command::target_generic && target.second == NULL) {
|
||||
// // We received a target that is NULL, so throw an exception unless
|
||||
// // we can convert it to a void target.
|
||||
// if (itr->second.m_target > Command::target_any)
|
||||
// throw torrent::input_error("Command type mis-match.");
|
||||
|
||||
// target.first = Command::target_generic;
|
||||
// }
|
||||
|
||||
// if (itr->second.m_target != target.first && itr->second.m_target > Command::target_any)
|
||||
// throw torrent::input_error("Command type mis-match.");
|
||||
|
||||
// // This _should_ be optimized int just two calls.
|
||||
// switch (itr->second.m_target) {
|
||||
// case Command::target_any: return itr->second.m_anySlot(itr->second.m_variable, target, arg);
|
||||
// default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target.");
|
||||
// }
|
||||
|
||||
return itr->second.m_anySlot(itr->second.m_variable, target, arg);
|
||||
CommandMap::call_command(iterator itr, const mapped_type& arg, target_type target) {
|
||||
return itr->second.m_anySlot(&itr->second.m_variable, target, arg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+15
-9
@@ -57,10 +57,14 @@ struct command_map_data_type {
|
||||
//
|
||||
// The any_slot should perhaps replace generic_slot?
|
||||
|
||||
command_map_data_type(command_base* variable, int flags, const char* parm, const char* doc) :
|
||||
m_variable(variable), m_flags(flags), m_parm(parm), m_doc(doc) {}
|
||||
command_map_data_type(int flags, const char* parm, const char* doc) :
|
||||
m_flags(flags), m_parm(parm), m_doc(doc) {}
|
||||
|
||||
command_base* m_variable;
|
||||
command_map_data_type(const command_map_data_type& src) :
|
||||
m_variable(src.m_variable), m_anySlot(src.m_anySlot),
|
||||
m_flags(src.m_flags), m_parm(src.m_parm), m_doc(src.m_doc) {}
|
||||
|
||||
command_base m_variable;
|
||||
command_base::any_slot m_anySlot;
|
||||
|
||||
int m_flags;
|
||||
@@ -104,15 +108,17 @@ public:
|
||||
|
||||
bool is_modifiable(const_iterator itr) { return itr != end() && (itr->second.m_flags & flag_modifiable); }
|
||||
|
||||
iterator insert(key_type key, command_base* variable, int flags, const char* parm, const char* doc);
|
||||
iterator insert(key_type key, int flags, const char* parm, const char* doc);
|
||||
|
||||
// Make this a wrapper call to insert without extra fluff.
|
||||
void insert_type(key_type key, command_base* variable, command_base::any_slot targetSlot, int flags, const char* parm, const char* doc) {
|
||||
iterator itr = insert(key, variable, flags, parm, doc);
|
||||
template <typename T, typename Slot>
|
||||
void
|
||||
insert_slot(key_type key, Slot variable, command_base::any_slot targetSlot, int flags, const char* parm, const char* doc) {
|
||||
iterator itr = insert(key, flags, parm, doc);
|
||||
itr->second.m_variable.set_function<T>(variable);
|
||||
itr->second.m_anySlot = targetSlot;
|
||||
}
|
||||
|
||||
void insert(key_type key, const command_map_data_type src);
|
||||
// void insert(key_type key, const command_map_data_type src);
|
||||
void erase(iterator itr);
|
||||
|
||||
void create_redirect(key_type key_new, key_type key_dest, int flags);
|
||||
@@ -122,7 +128,7 @@ public:
|
||||
const mapped_type call_catch(key_type key, target_type target, const mapped_type& args = mapped_type(), const char* err = "Command failed: ");
|
||||
|
||||
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)command_base::target_generic, NULL));
|
||||
const mapped_type call_command (const_iterator itr, const mapped_type& arg, target_type target = target_type((int)command_base::target_generic, NULL));
|
||||
const mapped_type call_command (iterator itr, const mapped_type& arg, target_type target = target_type((int)command_base::target_generic, NULL));
|
||||
|
||||
const mapped_type call_command_d(key_type key, core::Download* download, const mapped_type& arg) { return call_command(key, arg, target_type((int)command_base::target_download, download)); }
|
||||
const mapped_type call_command_p(key_type key, torrent::Peer* peer, const mapped_type& arg) { return call_command(key, arg, target_type((int)command_base::target_peer, peer)); }
|
||||
|
||||
+1
-1
@@ -432,7 +432,7 @@ object_to_xmlrpc(xmlrpc_env* env, const torrent::Object& object) {
|
||||
|
||||
xmlrpc_value*
|
||||
xmlrpc_call_command(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo) {
|
||||
CommandMap::const_iterator itr = commands.find((const char*)voidServerInfo);
|
||||
CommandMap::iterator itr = commands.find((const char*)voidServerInfo);
|
||||
|
||||
if (itr == commands.end()) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, ("Command \"" + std::string((const char*)voidServerInfo) + "\" does not exist.").c_str());
|
||||
|
||||
Reference in New Issue
Block a user