Working option file, doesn't yet load from a sane place.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@449 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-06-01 13:33:44 +00:00
parent 74930f86b3
commit 0206ee066d
8 changed files with 178 additions and 33 deletions
+23 -13
View File
@@ -23,25 +23,35 @@
#ifndef RTORRENT_OPTION_HANDLER_RULES_H
#define RTORRENT_OPTION_HANDLER_RULES_H
#include "core/download_slot_map.h"
#include <cstdio>
#include <stdexcept>
#include <sigc++/bind.h>
#include "option_handler.h"
#include "core/download_slot_map.h"
class OptionHandlerDownloadMinPeers : public OptionHandlerBase {
bool validate_download_peers(int arg);
void apply_download_min_peers(core::Download* d, int arg);
void apply_download_max_peers(core::Download* d, int arg);
void apply_download_max_uploads(core::Download* d, int arg);
template <void (*Apply)(core::Download*, int), bool (*Validate)(int)>
class OptionHandlerDownloadInt : public OptionHandlerBase {
public:
OptionHandlerDownloadMinPeers(core::DownloadSlotMap* m) : m_map(m) {}
~OptionHandlerDownloadMinPeers();
virtual void process(const std::string& key, const std::string& arg);
private:
// Move these somewhere else? A seperate file with lots of different
// setting appliers. Those would perform the nessesary checks
// themselves.
static void apply(core::Download* d, int arg) {
d->get_download().set_peers_min(arg);
OptionHandlerDownloadInt(core::DownloadSlotMap* m) : m_map(m) {}
virtual void process(const std::string& key, const std::string& arg) {
int a;
if (std::sscanf(arg.c_str(), "%i", &a) != 1 ||
!Validate(a))
throw std::runtime_error("Invalid argument for \"" + key + "\": \"" + arg + "\"");
(*m_map)[key] = sigc::bind(sigc::ptr_fun(Apply), a);
}
private:
core::DownloadSlotMap* m_map;
};