Seperated out my template algorithms and stuff.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@334 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-03-08 18:25:34 +00:00
parent f379abb200
commit a4dbdffcb8
16 changed files with 40 additions and 38 deletions
-2
View File
@@ -1,10 +1,8 @@
noinst_LIBRARIES = libsub_utils.a
libsub_utils_a_SOURCES = \
algorithm.h \
directory.cc \
directory.h \
functional.h \
parse.cc \
parse.h \
task.h \
-58
View File
@@ -1,58 +0,0 @@
#ifndef RTORRENT_UTILS_ALGORITHM_H
#define RTORRENT_UTILS_ALGORITHM_H
#include <algorithm>
namespace utils {
template <typename _InputIter, typename _Function>
_Function
for_each_pre(_InputIter __first, _InputIter __last, _Function __f) {
_InputIter __tmp;
while (__first != __last) {
__tmp = __first++;
__f(*__tmp);
}
return __f;
}
// Return a range with a distance of no more than __distance and
// between __first and __last, centered on __middle1.
template <typename _InputIter, typename _Distance>
std::pair<_InputIter, _InputIter>
advance_bidirectional(_InputIter __first, _InputIter __middle1, _InputIter __last, _Distance __distance) {
_InputIter __middle2 = __middle1;
do {
if (!__distance)
break;
if (__middle1 != __first) {
--__middle1;
--__distance;
} else if (__middle2 == __last) {
break;
}
if (!__distance)
break;
if (__middle2 != __last) {
++__middle2;
--__distance;
} else if (__middle1 == __first) {
break;
}
} while (true);
return std::make_pair(__middle1, __middle2);
}
}
#endif
-1
View File
@@ -5,7 +5,6 @@
#include <stdexcept>
#include <dirent.h>
#include "functional.h"
#include "directory.h"
namespace utils {
-109
View File
@@ -1,109 +0,0 @@
#ifndef RTORRENT_UTILS_FUNCTIONAL_H
#define RTORRENT_UTILS_FUNCTIONAL_H
#include <functional>
namespace utils {
template <typename Type, typename Ftor>
struct _accumulate {
_accumulate(Type& t, Ftor f) : m_t(t), m_f(f) {}
template <typename Arg>
void operator () (Arg& a) { m_t += m_f(a); }
Type& m_t;
Ftor m_f;
};
template <typename Type, typename Ftor>
inline _accumulate<Type, Ftor>
accumulate(Type& t, Ftor f) {
return _accumulate<Type, Ftor>(t, f);
}
template <typename Type, typename Ftor>
struct _equal {
_equal(Type t, Ftor f) : m_t(t), m_f(f) {}
template <typename Arg>
bool operator () (Arg& a) {
return m_t == m_f(a);
}
Type m_t;
Ftor m_f;
};
template <typename Type, typename Ftor>
inline _equal<Type, Ftor>
equal(Type t, Ftor f) {
return _equal<Type, Ftor>(t, f);
}
template <typename Src, typename Dest>
struct _on : public std::unary_function<typename Src::argument_type, typename Dest::result_type> {
_on(Src s, Dest d) : m_dest(d), m_src(s) {}
typename Dest::result_type operator () (typename Src::argument_type arg) {
return m_dest(m_src(arg));
}
Dest m_dest;
Src m_src;
};
template <typename Src, typename Dest>
inline _on<Src, Dest>
on(Src s, Dest d) {
return _on<Src, Dest>(s, d);
}
// Creates a functor for accessing a member.
template <typename Class, typename Member>
struct _mem_ptr_ref : public std::unary_function<Class&, Member&> {
_mem_ptr_ref(Member Class::*m) : m_member(m) {}
Member& operator () (Class& c) {
return c.*m_member;
}
Member Class::*m_member;
};
template <typename Class, typename Member>
inline _mem_ptr_ref<Class, Member>
mem_ptr_ref(Member Class::*m) {
return _mem_ptr_ref<Class, Member>(m);
}
template <typename Cond, typename Then>
struct _if_then {
_if_then(Cond c, Then t) : m_cond(c), m_then(t) {}
template <typename Arg>
void operator () (Arg& a) {
if (m_cond(a))
m_then(a);
}
Cond m_cond;
Then m_then;
};
template <typename Cond, typename Then>
inline _if_then<Cond, Then>
if_then(Cond c, Then t) {
return _if_then<Cond, Then>(c, t);
}
template <typename T>
struct call_delete : public std::unary_function<T*, void> {
void operator () (T* t) {
delete t;
}
};
}
#endif