diff --git a/Makefile.am b/Makefile.am index 2a6c3ef8..a37aa7bf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,6 +7,7 @@ EXTRA_DIST= \ rak/algorithm.h \ rak/error_number.h \ rak/functional.h \ + rak/string_manip.h \ rak/unordered_vector.h \ scripts/checks.m4 \ scripts/common.m4 diff --git a/configure.ac b/configure.ac index d9e4b9b2..ca00157a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.3.5, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.3.6, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) @@ -22,7 +22,7 @@ TORRENT_OTFD() TORRENT_WITHOUT_VARIABLE_FDSET() -PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.7.5, +PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.7.6, CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS $CURL_CFLAGS"; LIBS="$LIBS $STUFF_LIBS $CURL_LIBS") diff --git a/rak/functional.h b/rak/functional.h index 57b87853..31c09c0a 100644 --- a/rak/functional.h +++ b/rak/functional.h @@ -339,17 +339,11 @@ bind2nd(const Operation& op, const Type& val) { } // Lightweight callback function including pointer to object. Should -// be replaced by TR1 stuff later. - -template -class function0 { -public: - virtual bool is_valid() const = 0; - virtual Ret operator () () = 0; -}; +// be replaced by TR1 stuff later. Requires an object to bind, instead +// of using a seperate functor for that. template -class mem_fn0 : public function0 { +class mem_fn0 { public: typedef Ret (Object::*Function)(); @@ -365,6 +359,23 @@ private: Function m_function; }; +template +class const_mem_fn0 { +public: + typedef Ret (Object::*Function)() const; + + const_mem_fn0() : m_object(NULL) {} + const_mem_fn0(Object* o, Function f) : m_object(o), m_function(f) {} + + bool is_valid() const { return m_object; } + + Ret operator () () { return (m_object->*m_function)(); } + +private: + Object* m_object; + Function m_function; +}; + template class mem_fn1 { public: @@ -382,18 +393,70 @@ private: Function m_function; }; +template +class mem_fn2 { +public: + typedef Ret (Object::*Function)(Arg1, Arg2); + + mem_fn2() : m_object(NULL) {} + mem_fn2(Object* o, Function f) : m_object(o), m_function(f) {} + + bool is_valid() const { return m_object; } + + Ret operator () (Arg1 a1, Arg2 a2) { return (m_object->*m_function)(a1, a2); } + +private: + Object* m_object; + Function m_function; +}; + +template +class mem_fn3 { +public: + typedef Ret (Object::*Function)(Arg1, Arg2, Arg3); + + mem_fn3() : m_object(NULL) {} + mem_fn3(Object* o, Function f) : m_object(o), m_function(f) {} + + bool is_valid() const { return m_object; } + + Ret operator () (Arg1 a1, Arg2 a2, Arg3 a3) { return (m_object->*m_function)(a1, a2, a3); } + +private: + Object* m_object; + Function m_function; +}; + template inline mem_fn0 make_mem_fn(Object* o, Ret (Object::*f)()) { return mem_fn0(o, f); } +template +inline const_mem_fn0 +make_mem_fn(Object* o, Ret (Object::*f)() const) { + return const_mem_fn0(o, f); +} + template inline mem_fn1 make_mem_fn(Object* o, Ret (Object::*f)(Arg1)) { return mem_fn1(o, f); } +template +inline mem_fn2 +make_mem_fn(Object* o, Ret (Object::*f)(Arg1, Arg2)) { + return mem_fn2(o, f); +} + +template +inline mem_fn3 +make_mem_fn(Object* o, Ret (Object::*f)(Arg1, Arg2, Arg3)) { + return mem_fn3(o, f); +} + } #endif diff --git a/rak/string_manip.h b/rak/string_manip.h new file mode 100644 index 00000000..fcd98844 --- /dev/null +++ b/rak/string_manip.h @@ -0,0 +1,79 @@ +// rak - Rakshasa's toolbox +// Copyright (C) 2005, Jari Sundell +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// In addition, as a special exception, the copyright holders give +// permission to link the code of portions of this program with the +// OpenSSL library under certain conditions as described in each +// individual source file, and distribute linked combinations +// including the two. +// +// You must obey the GNU General Public License in all respects for +// all of the code used other than OpenSSL. If you modify file(s) +// with this exception, you may extend this exception to your version +// of the file(s), but you are not obligated to do so. If you do not +// wish to do so, delete this exception statement from your version. +// If you delete this exception statement from all source files in the +// program, then also delete it here. +// +// Contact: Jari Sundell +// +// Skomakerveien 33 +// 3185 Skoppum, NORWAY + +#ifndef RAK_STRING_MANIP_H +#define RAK_STRING_MANIP_H + +#include + +namespace rak { + +// Use these trim functions until n1872 is widely supported. + +template +Sequence trim_begin(const Sequence& seq) { + if (seq.empty() || !std::isspace(*seq.begin())) + return seq; + + typename Sequence::size_type pos = 0; + + while (pos != seq.length() && std::isspace(seq[pos])) + pos++; + + return seq.substr(pos, seq.length() - pos); +} + +template +Sequence trim_end(const Sequence& seq) { + if (seq.empty() || !std::isspace(*(--seq.end()))) + return seq; + + typename Sequence::size_type pos = seq.size(); + + while (pos != 0 && std::isspace(seq[pos - 1])) + pos--; + + return seq.substr(0, pos); +} + +template +Sequence trim(const Sequence& seq) { + return trim_begin(trim_end(seq)); +} + +} + +#endif diff --git a/src/display/utils.cc b/src/display/utils.cc index 74be7688..40ab09f9 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -129,7 +129,7 @@ print_ddmmyyyy(time_t t) { str.fill('0'); str << std::setw(2) << u->tm_mday << '/' - << std::setw(2) << u->tm_mon << '/' + << std::setw(2) << (u->tm_mon + 1) << '/' << std::setw(4) << (1900 + u->tm_year); return str.str();