* Fixed a leaking rak::address_info in TrackerUdp. Patch by Josef

Drexler.

* Finished converting the variables in core::Download to use the new
get/set_d(core::Download, ...) functions.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@848 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-01-20 12:42:14 +00:00
parent e59b5bf7b6
commit b301faf3ca
3 changed files with 186 additions and 104 deletions
+58 -47
View File
@@ -42,15 +42,8 @@
namespace utils {
const torrent::Object&
VariableAny::get() {
return m_variable;
}
void
VariableAny::set(const torrent::Object& arg) {
m_variable = arg;
}
const torrent::Object& VariableAny::get() { return m_variable; }
void VariableAny::set(const torrent::Object& arg) { m_variable = arg; }
void
VariableValue::set(const torrent::Object& arg) {
@@ -145,6 +138,11 @@ VariableObject::set_d(core::Download* download, const torrent::Object& arg) {
}
}
const torrent::Object& VariableDownload::get() { return m_global->get(); }
const torrent::Object& VariableDownload::get_d(core::Download* download) { return m_download->get_d(download); }
void VariableDownload::set(const torrent::Object& arg) { m_global->set(arg); }
void VariableDownload::set_d(core::Download* download, const torrent::Object& arg) { m_download->set_d(download, arg); }
//
// New and prettified.
//
@@ -165,7 +163,7 @@ VariableVoidSlot::set(const torrent::Object& arg) {
const torrent::Object&
VariableValueSlot::get() {
if (!m_slotGet.is_valid())
return m_cache;
return m_cache = torrent::Object();
m_cache = m_slotGet() / m_unit;
@@ -197,6 +195,40 @@ VariableValueSlot::set(const torrent::Object& arg) {
}
}
const torrent::Object&
VariableDownloadValueSlot::get_d(core::Download* download) {
// Should clear the cache.
if (!m_slotGetDownload.is_valid())
return m_cache = torrent::Object();
return m_cache = m_slotGetDownload(download) / m_unit;
}
void
VariableDownloadValueSlot::set_d(core::Download* download, const torrent::Object& arg) {
if (!m_slotSetDownload.is_valid())
return;
value_type value;
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
string_to_value_unit(arg.as_string().c_str(), &value, m_base, m_unit);
// Check if we hit the end of the input.
m_slotSetDownload(download, value);
break;
case torrent::Object::TYPE_VALUE:
m_slotSetDownload(download, arg.as_value());
break;
default:
throw torrent::input_error("Not a value");
}
}
const torrent::Object&
VariableStringSlot::get() {
if (!m_slotGet.is_valid())
@@ -225,49 +257,28 @@ VariableStringSlot::set(const torrent::Object& arg) {
}
const torrent::Object&
VariableStringSlot::get_d(core::Download* download) {
VariableDownloadStringSlot::get_d(core::Download* download) {
// Should clear the cache.
if (!m_slotGetDownload.is_valid()) {
if (!m_slotGet.is_valid())
return m_cache = torrent::Object();
if (!m_slotGetDownload.is_valid())
return m_cache = torrent::Object();
m_cache = m_slotGet();
} else {
m_cache = m_slotGetDownload(download);
}
return m_cache;
return m_cache = m_slotGetDownload(download);
}
void
VariableStringSlot::set_d(core::Download* download, const torrent::Object& arg) {
if (!m_slotSetDownload.is_valid()) {
if (!m_slotSet.is_valid())
return;
VariableDownloadStringSlot::set_d(core::Download* download, const torrent::Object& arg) {
if (!m_slotSetDownload.is_valid())
return;
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
m_slotSet(arg.as_string());
break;
case torrent::Object::TYPE_NONE:
m_slotSet(std::string());
break;
default:
throw torrent::input_error("Not a string.");
}
} else {
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
m_slotSetDownload(download, arg.as_string());
break;
case torrent::Object::TYPE_NONE:
m_slotSetDownload(download, std::string());
break;
default:
throw torrent::input_error("Not a string.");
}
switch (arg.type()) {
case torrent::Object::TYPE_STRING:
m_slotSetDownload(download, arg.as_string());
break;
case torrent::Object::TYPE_NONE:
m_slotSetDownload(download, std::string());
break;
default:
throw torrent::input_error("Not a string.");
}
}
+92 -36
View File
@@ -79,6 +79,22 @@ public:
virtual void set(const torrent::Object& arg);
};
class VariableDownload : public Variable {
public:
VariableDownload(Variable* varGlobal, Variable* varDownload) :
m_global(varGlobal), m_download(varDownload) {}
virtual const torrent::Object& get();
virtual void set(const torrent::Object& arg);
virtual const torrent::Object& get_d(core::Download* download);
virtual void set_d(core::Download* download, const torrent::Object& arg);
protected:
Variable* m_global;
Variable* m_download;
};
class VariableObject : public Variable {
public:
typedef torrent::Object::type_type Type;
@@ -121,8 +137,9 @@ private:
class VariableValueSlot : public Variable {
public:
typedef rak::function0<value_type> slot_get_type;
typedef rak::function1<void, value_type> slot_set_type;
typedef rak::function0<value_type> slot_get_type;
typedef rak::function1<void, value_type> slot_set_type;
typedef std::pair<value_type, value_type> range_type;
template <typename SlotGet, typename SlotSet>
@@ -164,54 +181,93 @@ private:
torrent::Object m_cache;
};
class VariableStringSlot : public Variable {
class VariableDownloadValueSlot : public Variable {
public:
typedef rak::function0<string_type> slot_get_type;
typedef rak::function1<string_type, core::Download*> slot_get_d_type;
typedef rak::function1<void, const string_type&> slot_set_type;
typedef rak::function2<void, core::Download*, const string_type&> slot_set_d_type;
typedef rak::function1<value_type, core::Download*> slot_get_d_type;
typedef rak::function2<void, core::Download*, value_type> slot_set_d_type;
template <typename SlotGet, typename SlotSet>
VariableStringSlot(SlotGet* slotGet, SlotSet* slotSet) {
m_slotGet.set(rak::convert_fn<string_type>(slotGet));
m_slotSet.set(rak::convert_fn<void, const string_type&>(slotSet));
m_slotGetDownload.set(NULL);
m_slotSetDownload.set(NULL);
typedef std::pair<value_type, value_type> range_type;
template <typename SlotGetDownload, typename SlotSetDownload>
VariableDownloadValueSlot(SlotGetDownload* slotGetDownload, SlotSetDownload* slotSetDownload,
unsigned int base = 0, unsigned int unit = 1,
range_type range = range_type(std::numeric_limits<value_type>::min(), std::numeric_limits<value_type>::max())) :
m_base(base),
m_unit(unit),
m_range(range) {
m_slotGetDownload.set(rak::convert_fn<value_type, core::Download*>(slotGetDownload));
m_slotSetDownload.set(rak::convert_fn<void, core::Download*, value_type>(slotSetDownload));
}
template <typename SlotGetDownload>
VariableStringSlot(void* slotGet, void* slotSet, SlotGetDownload* slotGetDownload, void* slotSetDownload) {
m_slotGet.set(NULL);
m_slotSet.set(NULL);
m_slotGetDownload.set(rak::convert_fn<string_type, core::Download*>(slotGetDownload));
VariableDownloadValueSlot(SlotGetDownload* slotGetDownload, void* slotSetDownload,
unsigned int base = 0, unsigned int unit = 1,
range_type range = range_type(std::numeric_limits<value_type>::min(), std::numeric_limits<value_type>::max())) :
m_base(base),
m_unit(unit),
m_range(range) {
m_slotGetDownload.set(rak::convert_fn<value_type, core::Download*>(slotGetDownload));
m_slotSetDownload.set(NULL);
}
template <typename SlotGetDownload, typename SlotSetDownload>
VariableStringSlot(void* slotGet, void* slotSet, SlotGetDownload* slotGetDownload, SlotSetDownload* slotSetDownload) {
m_slotGet.set(NULL);
m_slotSet.set(NULL);
m_slotGetDownload.set(rak::convert_fn<string_type, core::Download*>(slotGetDownload));
m_slotSetDownload.set(rak::convert_fn<void, core::Download*, const string_type&>(slotSetDownload));
}
// template <typename SlotGet, typename SlotSet, typename SlotGetDownload, typename SlotSetDownload>
// VariableStringSlot(SlotGet* slotGet, SlotSet* slotSet, SlotGetDownload* slotGetDownload, SlotSetDownload* slotSetDownload) {
// m_slotGet.set(slotGet != NULL ? rak::convert_fn<string_type>(slotGet) : NULL);
// m_slotSet.set(slotSet != NULL ? rak::convert_fn<void, const string_type&>(slotSet) : NULL);
// m_slotGetDownload.set(slotGetDownload != NULL ? rak::convert_fn<string_type, core::Download*>(slotGetDownload) : NULL);
// m_slotSetDownload.set(slotSetDownload != NULL ? rak::convert_fn<void, core::Download*, const string_type&>(slotSetDownload) : NULL);
// }
virtual const torrent::Object& get();
virtual void set(const torrent::Object& arg);
virtual const torrent::Object& get_d(core::Download* download);
virtual void set_d(core::Download* download, const torrent::Object& arg);
private:
slot_get_d_type m_slotGetDownload;
slot_set_d_type m_slotSetDownload;
unsigned int m_base;
unsigned int m_unit;
range_type m_range;
// Store the cache here to avoid unnessesary copying and such. This
// should not result in any unresonable memory usage since few
// strings will be very large.
torrent::Object m_cache;
};
class VariableStringSlot : public Variable {
public:
typedef rak::function0<string_type> slot_get_type;
typedef rak::function1<void, const string_type&> slot_set_type;
template <typename SlotGet, typename SlotSet>
VariableStringSlot(SlotGet* slotGet, SlotSet* slotSet) {
m_slotGet.set(rak::convert_fn<string_type>(slotGet));
m_slotSet.set(rak::convert_fn<void, const string_type&>(slotSet));
}
virtual const torrent::Object& get();
virtual void set(const torrent::Object& arg);
private:
slot_get_type m_slotGet;
slot_set_type m_slotSet;
// Store the cache here to avoid unnessesary copying and such. This
// should not result in any unresonable memory usage since few
// strings will be very large.
torrent::Object m_cache;
};
class VariableDownloadStringSlot : public Variable {
public:
typedef rak::function1<string_type, core::Download*> slot_get_d_type;
typedef rak::function2<void, core::Download*, const string_type&> slot_set_d_type;
template <typename SlotGetDownload, typename SlotSetDownload>
VariableDownloadStringSlot(SlotGetDownload* slotGetDownload, SlotSetDownload* slotSetDownload) {
m_slotGetDownload.set(rak::convert_fn<string_type, core::Download*>(slotGetDownload));
m_slotSetDownload.set(rak::convert_fn<void, core::Download*, const string_type&>(slotSetDownload));
}
virtual const torrent::Object& get_d(core::Download* download);
virtual void set_d(core::Download* download, const torrent::Object& arg);
private:
slot_get_d_type m_slotGetDownload;
slot_set_d_type m_slotSetDownload;