mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-07 18:52:30 +00:00
rtorrent: Working on display.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@237 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
#ifndef ALGO_COMMON_H
|
||||
#define ALGO_COMMON_H
|
||||
|
||||
namespace algo {
|
||||
|
||||
struct _nil {
|
||||
};
|
||||
|
||||
struct _one {
|
||||
char c[1];
|
||||
};
|
||||
|
||||
struct _two {
|
||||
char c[2];
|
||||
};
|
||||
|
||||
template <bool C, typename Then, typename Else>
|
||||
struct tmpl_if;
|
||||
|
||||
template <typename Then, typename Else>
|
||||
struct tmpl_if<true, Then, Else> {
|
||||
typedef Then result;
|
||||
};
|
||||
|
||||
template <typename Then, typename Else>
|
||||
struct tmpl_if<false, Then, Else> {
|
||||
typedef Else result;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct traits {
|
||||
enum {
|
||||
REF = false,
|
||||
CONST = false
|
||||
};
|
||||
|
||||
typedef T orig_t;
|
||||
typedef T type_t;
|
||||
typedef T& ref_t;
|
||||
|
||||
typedef T b_orig_t;
|
||||
typedef T b_type_t;
|
||||
typedef T& b_ref_t;
|
||||
|
||||
typedef const T c_orig_t;
|
||||
typedef const T c_type_t;
|
||||
typedef const T& c_ref_t;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct traits<T&> {
|
||||
enum {
|
||||
REF = true,
|
||||
CONST = false
|
||||
};
|
||||
|
||||
typedef T& orig_t;
|
||||
typedef T type_t;
|
||||
typedef T& ref_t;
|
||||
|
||||
typedef T& b_orig_t;
|
||||
typedef T b_type_t;
|
||||
typedef T& b_ref_t;
|
||||
|
||||
typedef const T& c_orig_t;
|
||||
typedef const T c_type_t;
|
||||
typedef const T& c_ref_t;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct traits<const T> {
|
||||
enum {
|
||||
REF = false,
|
||||
CONST = true
|
||||
};
|
||||
|
||||
typedef const T orig_t;
|
||||
typedef const T type_t;
|
||||
typedef const T& ref_t;
|
||||
|
||||
typedef T b_orig_t;
|
||||
typedef T b_type_t;
|
||||
typedef T& b_ref_t;
|
||||
|
||||
typedef const T c_orig_t;
|
||||
typedef const T c_type_t;
|
||||
typedef const T& c_ref_t;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct traits<const T&> {
|
||||
enum {
|
||||
REF = true,
|
||||
CONST = true
|
||||
};
|
||||
|
||||
typedef const T& orig_t;
|
||||
typedef const T type_t;
|
||||
typedef const T& ref_t;
|
||||
|
||||
typedef T& b_orig_t;
|
||||
typedef T b_type_t;
|
||||
typedef T& b_ref_t;
|
||||
|
||||
typedef const T& c_orig_t;
|
||||
typedef const T c_type_t;
|
||||
typedef const T& c_ref_t;
|
||||
};
|
||||
|
||||
// Helper function used to generate an instantated type for typeof
|
||||
// calls.
|
||||
template <typename T>
|
||||
T _makeT();
|
||||
|
||||
template <typename Ftor1, typename Ftor2>
|
||||
struct _op_assign;
|
||||
|
||||
// This class acts like a wrapper identifying classes that
|
||||
// are compatible with the algo structure.
|
||||
template <typename Ftor>
|
||||
struct _wrapper {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef typeof(_makeT<Ftor>()(_makeT<Arg0>())) return_t;
|
||||
};
|
||||
|
||||
_wrapper(Ftor ftor) : m_ftor(ftor) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0 = _nil()) {
|
||||
return m_ftor(arg0);
|
||||
}
|
||||
|
||||
// template <typename Arg0>
|
||||
// typename _<Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
// return m_ftor(arg0);
|
||||
// }
|
||||
|
||||
template <typename Ftor2>
|
||||
inline _wrapper<_op_assign<Ftor, Ftor2> >
|
||||
operator = (_wrapper<Ftor2> w) {
|
||||
return make_wrapper(_op_assign<Ftor, Ftor2>(m_ftor, w.m_ftor));
|
||||
}
|
||||
|
||||
Ftor m_ftor;
|
||||
};
|
||||
|
||||
template <typename Ftor>
|
||||
inline _wrapper<Ftor>
|
||||
make_wrapper(Ftor ftor) {
|
||||
return _wrapper<Ftor>(ftor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,314 @@
|
||||
// -*- c++ -*-
|
||||
/* Do not edit! -- generated file */
|
||||
|
||||
#ifndef ALGO_BITS_IMPL_CALL_H
|
||||
#define ALGO_BITS_IMPL_CALL_H
|
||||
|
||||
namespace algo {
|
||||
|
||||
template <typename Func, typename Ret>
|
||||
struct _ptr_fun0 {
|
||||
|
||||
template <typename Arg0, bool r = traits<Ret>::REF>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
template <typename Arg0>
|
||||
struct _<Arg0, false> {
|
||||
typedef const Ret return_t;
|
||||
};
|
||||
|
||||
_ptr_fun0(Func func) :
|
||||
m_func(func) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return m_func();
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return m_func();
|
||||
}
|
||||
|
||||
Func m_func;
|
||||
|
||||
};
|
||||
|
||||
template <typename Func, typename Ret, typename Parm1>
|
||||
struct _ptr_fun1 {
|
||||
|
||||
template <typename Arg0, bool r = traits<Ret>::REF>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
template <typename Arg0>
|
||||
struct _<Arg0, false> {
|
||||
typedef const Ret return_t;
|
||||
};
|
||||
|
||||
_ptr_fun1(Func func, Parm1 parm1) :
|
||||
m_func(func), m_parm1(parm1) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0));
|
||||
}
|
||||
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
};
|
||||
|
||||
template <typename Func, typename Ret, typename Parm1,typename Parm2>
|
||||
struct _ptr_fun2 {
|
||||
|
||||
template <typename Arg0, bool r = traits<Ret>::REF>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
template <typename Arg0>
|
||||
struct _<Arg0, false> {
|
||||
typedef const Ret return_t;
|
||||
};
|
||||
|
||||
_ptr_fun2(Func func, Parm1 parm1,Parm2 parm2) :
|
||||
m_func(func), m_parm1(parm1),m_parm2(parm2) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0),m_parm2(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0),m_parm2(arg0));
|
||||
}
|
||||
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
Parm2 m_parm2;
|
||||
};
|
||||
|
||||
template <typename Func, typename Ret, typename Parm1,typename Parm2,typename Parm3>
|
||||
struct _ptr_fun3 {
|
||||
|
||||
template <typename Arg0, bool r = traits<Ret>::REF>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
template <typename Arg0>
|
||||
struct _<Arg0, false> {
|
||||
typedef const Ret return_t;
|
||||
};
|
||||
|
||||
_ptr_fun3(Func func, Parm1 parm1,Parm2 parm2,Parm3 parm3) :
|
||||
m_func(func), m_parm1(parm1),m_parm2(parm2),m_parm3(parm3) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0));
|
||||
}
|
||||
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
Parm2 m_parm2;
|
||||
Parm3 m_parm3;
|
||||
};
|
||||
|
||||
template <typename Func, typename Ret, typename Parm1,typename Parm2,typename Parm3,typename Parm4>
|
||||
struct _ptr_fun4 {
|
||||
|
||||
template <typename Arg0, bool r = traits<Ret>::REF>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
template <typename Arg0>
|
||||
struct _<Arg0, false> {
|
||||
typedef const Ret return_t;
|
||||
};
|
||||
|
||||
_ptr_fun4(Func func, Parm1 parm1,Parm2 parm2,Parm3 parm3,Parm4 parm4) :
|
||||
m_func(func), m_parm1(parm1),m_parm2(parm2),m_parm3(parm3),m_parm4(parm4) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0),m_parm4(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return m_func(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0),m_parm4(arg0));
|
||||
}
|
||||
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
Parm2 m_parm2;
|
||||
Parm3 m_parm3;
|
||||
Parm4 m_parm4;
|
||||
};
|
||||
|
||||
|
||||
template <typename Target, typename Func, typename Ret>
|
||||
struct _mem_fun0 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
_mem_fun0(Target target, Func func) :
|
||||
m_target(target), m_func(func) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)();
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)();
|
||||
}
|
||||
|
||||
Target m_target;
|
||||
Func m_func;
|
||||
|
||||
};
|
||||
|
||||
template <typename Target, typename Func, typename Ret, typename Parm1>
|
||||
struct _mem_fun1 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
_mem_fun1(Target target, Func func, Parm1 parm1) :
|
||||
m_target(target), m_func(func), m_parm1(parm1) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0));
|
||||
}
|
||||
|
||||
Target m_target;
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
};
|
||||
|
||||
template <typename Target, typename Func, typename Ret, typename Parm1,typename Parm2>
|
||||
struct _mem_fun2 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
_mem_fun2(Target target, Func func, Parm1 parm1,Parm2 parm2) :
|
||||
m_target(target), m_func(func), m_parm1(parm1),m_parm2(parm2) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0),m_parm2(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0),m_parm2(arg0));
|
||||
}
|
||||
|
||||
Target m_target;
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
Parm2 m_parm2;
|
||||
};
|
||||
|
||||
template <typename Target, typename Func, typename Ret, typename Parm1,typename Parm2,typename Parm3>
|
||||
struct _mem_fun3 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
_mem_fun3(Target target, Func func, Parm1 parm1,Parm2 parm2,Parm3 parm3) :
|
||||
m_target(target), m_func(func), m_parm1(parm1),m_parm2(parm2),m_parm3(parm3) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0));
|
||||
}
|
||||
|
||||
Target m_target;
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
Parm2 m_parm2;
|
||||
Parm3 m_parm3;
|
||||
};
|
||||
|
||||
template <typename Target, typename Func, typename Ret, typename Parm1,typename Parm2,typename Parm3,typename Parm4>
|
||||
struct _mem_fun4 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
_mem_fun4(Target target, Func func, Parm1 parm1,Parm2 parm2,Parm3 parm3,Parm4 parm4) :
|
||||
m_target(target), m_func(func), m_parm1(parm1),m_parm2(parm2),m_parm3(parm3),m_parm4(parm4) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0),m_parm4(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return (m_target(arg0).*m_func)(m_parm1(arg0),m_parm2(arg0),m_parm3(arg0),m_parm4(arg0));
|
||||
}
|
||||
|
||||
Target m_target;
|
||||
Func m_func;
|
||||
|
||||
Parm1 m_parm1;
|
||||
Parm2 m_parm2;
|
||||
Parm3 m_parm3;
|
||||
Parm4 m_parm4;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,102 @@
|
||||
#ifndef ALGO_BITS_IMPL_ENTRY_H
|
||||
#define ALGO_BITS_IMPL_ENTRY_H
|
||||
|
||||
namespace algo {
|
||||
|
||||
template <typename Type>
|
||||
struct _entry {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Type return_t;
|
||||
};
|
||||
|
||||
_entry(Type t) : m_t(t) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return m_t;
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return m_t;
|
||||
}
|
||||
|
||||
Type m_t;
|
||||
};
|
||||
|
||||
template <typename Target, typename Type, typename Class>
|
||||
struct _member {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef typename traits<Type>::ref_t return_t;
|
||||
};
|
||||
|
||||
_member(Target target, Type Class::*member) :
|
||||
m_target(target), m_member(member) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return (m_target(arg0)).*m_member;
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return (m_target(arg0)).*m_member;
|
||||
}
|
||||
|
||||
Target m_target;
|
||||
Type Class::*m_member;
|
||||
};
|
||||
|
||||
struct _arg0 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef typename traits<Arg0>::ref_t return_t;
|
||||
};
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return arg0;
|
||||
}
|
||||
};
|
||||
|
||||
// Consider implementing _on0 and _on2 as m4 macros, but there will
|
||||
// never be more than 0-2, so dunno.
|
||||
template <typename Target, typename Parm0>
|
||||
struct _on1 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef typeof(_makeT<Target>()(_makeT<Arg0>())) return_t;
|
||||
};
|
||||
|
||||
_on1(Target target, Parm0 parm0) :
|
||||
m_target(target), m_parm0(parm0) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0>::return_t operator () (Arg0& arg0) {
|
||||
return m_target(m_parm0(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0>::return_t operator () (const Arg0& arg0) {
|
||||
return m_target(m_parm0(arg0));
|
||||
}
|
||||
|
||||
Target m_target;
|
||||
Parm0 m_parm0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
#ifndef ALGO_BITS_IMPL_LAMBDA_H
|
||||
#define ALGO_BITS_IMPL_LAMBDA_H
|
||||
|
||||
#define ALGO_OP_BINARY( NAME, OP ) \
|
||||
template <typename Ftor1, typename Ftor2> \
|
||||
struct _op_##NAME { \
|
||||
\
|
||||
template <typename Arg0> \
|
||||
struct _ { \
|
||||
typedef typename tmpl_if<traits<Arg0>::REF && !traits<Arg0>::CONST, \
|
||||
Arg0, typename traits<Arg0>::b_ref_t>::result Type; \
|
||||
\
|
||||
typedef typeof(_makeT<Ftor1>()(_makeT<Type>()) OP \
|
||||
_makeT<Ftor2>()(_makeT<Type>())) return_t; \
|
||||
}; \
|
||||
\
|
||||
_op_##NAME(Ftor1 ftor1, Ftor2 ftor2) : m_ftor1(ftor1), m_ftor2(ftor2) {} \
|
||||
\
|
||||
template <typename Arg0> \
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) { \
|
||||
return m_ftor1(arg0) OP m_ftor2(arg0); \
|
||||
} \
|
||||
\
|
||||
template <typename Arg0> \
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) { \
|
||||
return m_ftor1(arg0) OP m_ftor2(arg0); \
|
||||
} \
|
||||
\
|
||||
Ftor1 m_ftor1; \
|
||||
Ftor2 m_ftor2; \
|
||||
};
|
||||
|
||||
#define ALGO_MK_BINARY( NAME, OP ) \
|
||||
template <typename Ftor1, typename Ftor2> \
|
||||
inline _wrapper<_op_##NAME<Ftor1, Ftor2> > \
|
||||
operator OP (_wrapper<Ftor1> w1, _wrapper<Ftor2> w2) { \
|
||||
return make_wrapper(_op_##NAME<Ftor1, Ftor2>(w1.m_ftor, w2.m_ftor)); \
|
||||
}
|
||||
|
||||
#define ALGO_OP_UNARY( NAME, OP ) \
|
||||
template <typename Ftor1> \
|
||||
struct _op_##NAME { \
|
||||
\
|
||||
template <typename Arg0> \
|
||||
struct _ { \
|
||||
typedef typename tmpl_if<traits<Arg0>::REF && !traits<Arg0>::CONST, \
|
||||
Arg0, typename traits<Arg0>::b_ref_t>::result Type; \
|
||||
\
|
||||
typedef typeof( OP _makeT<Ftor1>()(_makeT<Type>()) ) return_t; \
|
||||
}; \
|
||||
\
|
||||
_op_##NAME(Ftor1 ftor1) : m_ftor1(ftor1) {} \
|
||||
\
|
||||
template <typename Arg0> \
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) { \
|
||||
return OP m_ftor1(arg0); \
|
||||
} \
|
||||
\
|
||||
template <typename Arg0> \
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) { \
|
||||
return OP m_ftor1(arg0); \
|
||||
} \
|
||||
\
|
||||
Ftor1 m_ftor1; \
|
||||
}; \
|
||||
\
|
||||
template <typename Ftor1> \
|
||||
inline _wrapper<_op_##NAME<Ftor1> > \
|
||||
operator OP (_wrapper<Ftor1> w1) { \
|
||||
return make_wrapper(_op_##NAME<Ftor1>(w1.m_ftor)); \
|
||||
}
|
||||
|
||||
namespace algo {
|
||||
|
||||
template <typename Ftor, typename Ret>
|
||||
struct op_cast {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Ret return_t;
|
||||
};
|
||||
|
||||
op_cast(Ftor ftor) : m_ftor(ftor) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return m_ftor(arg0);
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return m_ftor(arg0);
|
||||
}
|
||||
|
||||
Ftor m_ftor;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,156 @@
|
||||
// -*- c++ -*-
|
||||
/* Do not edit! -- generated file */
|
||||
|
||||
#ifndef ALGO_BITS_IMPL_MEMORY_H
|
||||
#define ALGO_BITS_IMPL_MEMORY_H
|
||||
|
||||
namespace algo {
|
||||
|
||||
template <typename Ftor>
|
||||
struct _delete {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef void return_t;
|
||||
};
|
||||
|
||||
_delete(Ftor ftor) : m_ftor(ftor) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
delete m_ftor(arg0);
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
delete m_ftor(arg0);
|
||||
}
|
||||
|
||||
Ftor m_ftor;
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
struct _new0 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Type* return_t;
|
||||
};
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return new Type;
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return new Type;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Type, typename P1>
|
||||
struct _new1 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Type* return_t;
|
||||
};
|
||||
|
||||
_new1(P1 p1) :
|
||||
m_p1(p1) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return new Type(m_p1(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return new Type(m_p1(arg0));
|
||||
}
|
||||
|
||||
P1 m_p1;
|
||||
};
|
||||
|
||||
template <typename Type, typename P1,typename P2>
|
||||
struct _new2 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Type* return_t;
|
||||
};
|
||||
|
||||
_new2(P1 p1,P2 p2) :
|
||||
m_p1(p1),m_p2(p2) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return new Type(m_p1(arg0),m_p2(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return new Type(m_p1(arg0),m_p2(arg0));
|
||||
}
|
||||
|
||||
P1 m_p1;
|
||||
P2 m_p2;
|
||||
};
|
||||
|
||||
template <typename Type, typename P1,typename P2,typename P3>
|
||||
struct _new3 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Type* return_t;
|
||||
};
|
||||
|
||||
_new3(P1 p1,P2 p2,P3 p3) :
|
||||
m_p1(p1),m_p2(p2),m_p3(p3) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return new Type(m_p1(arg0),m_p2(arg0),m_p3(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return new Type(m_p1(arg0),m_p2(arg0),m_p3(arg0));
|
||||
}
|
||||
|
||||
P1 m_p1;
|
||||
P2 m_p2;
|
||||
P3 m_p3;
|
||||
};
|
||||
|
||||
template <typename Type, typename P1,typename P2,typename P3,typename P4>
|
||||
struct _new4 {
|
||||
|
||||
template <typename Arg0>
|
||||
struct _ {
|
||||
typedef Type* return_t;
|
||||
};
|
||||
|
||||
_new4(P1 p1,P2 p2,P3 p3,P4 p4) :
|
||||
m_p1(p1),m_p2(p2),m_p3(p3),m_p4(p4) {}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<Arg0&>::return_t operator () (Arg0& arg0) {
|
||||
return new Type(m_p1(arg0),m_p2(arg0),m_p3(arg0),m_p4(arg0));
|
||||
}
|
||||
|
||||
template <typename Arg0>
|
||||
typename _<const Arg0&>::return_t operator () (const Arg0& arg0) {
|
||||
return new Type(m_p1(arg0),m_p2(arg0),m_p3(arg0),m_p4(arg0));
|
||||
}
|
||||
|
||||
P1 m_p1;
|
||||
P2 m_p2;
|
||||
P3 m_p3;
|
||||
P4 m_p4;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
// -*- c++ -*-
|
||||
/* Do not edit! -- generated file */
|
||||
|
||||
#ifndef ALGO_CALL_H
|
||||
#define ALGO_CALL_H
|
||||
|
||||
#include <algo/bits/common.h>
|
||||
#include <algo/bits/impl_call.h>
|
||||
|
||||
namespace algo {
|
||||
|
||||
template <typename FuncRet>
|
||||
inline _wrapper<
|
||||
_ptr_fun0<FuncRet (*)(), FuncRet > >
|
||||
|
||||
ptr_fun(FuncRet (*func)()) {
|
||||
|
||||
return make_wrapper(_ptr_fun0<
|
||||
FuncRet (*)(), FuncRet >
|
||||
(func));
|
||||
}
|
||||
|
||||
template <typename FuncParm1, typename FuncRet, typename Parm1>
|
||||
inline _wrapper<
|
||||
_ptr_fun1<FuncRet (*)(FuncParm1), FuncRet, Parm1 > >
|
||||
|
||||
ptr_fun(FuncRet (*func)(FuncParm1), _wrapper<Parm1> parm1) {
|
||||
|
||||
return make_wrapper(_ptr_fun1<
|
||||
FuncRet (*)(FuncParm1), FuncRet, Parm1 >
|
||||
(func, parm1.m_ftor));
|
||||
}
|
||||
|
||||
template <typename FuncParm1,typename FuncParm2, typename FuncRet, typename Parm1,typename Parm2>
|
||||
inline _wrapper<
|
||||
_ptr_fun2<FuncRet (*)(FuncParm1,FuncParm2), FuncRet, Parm1,Parm2 > >
|
||||
|
||||
ptr_fun(FuncRet (*func)(FuncParm1,FuncParm2), _wrapper<Parm1> parm1,_wrapper<Parm2> parm2) {
|
||||
|
||||
return make_wrapper(_ptr_fun2<
|
||||
FuncRet (*)(FuncParm1,FuncParm2), FuncRet, Parm1,Parm2 >
|
||||
(func, parm1.m_ftor,parm2.m_ftor));
|
||||
}
|
||||
|
||||
template <typename FuncParm1,typename FuncParm2,typename FuncParm3, typename FuncRet, typename Parm1,typename Parm2,typename Parm3>
|
||||
inline _wrapper<
|
||||
_ptr_fun3<FuncRet (*)(FuncParm1,FuncParm2,FuncParm3), FuncRet, Parm1,Parm2,Parm3 > >
|
||||
|
||||
ptr_fun(FuncRet (*func)(FuncParm1,FuncParm2,FuncParm3), _wrapper<Parm1> parm1,_wrapper<Parm2> parm2,_wrapper<Parm3> parm3) {
|
||||
|
||||
return make_wrapper(_ptr_fun3<
|
||||
FuncRet (*)(FuncParm1,FuncParm2,FuncParm3), FuncRet, Parm1,Parm2,Parm3 >
|
||||
(func, parm1.m_ftor,parm2.m_ftor,parm3.m_ftor));
|
||||
}
|
||||
|
||||
template <typename FuncParm1,typename FuncParm2,typename FuncParm3,typename FuncParm4, typename FuncRet, typename Parm1,typename Parm2,typename Parm3,typename Parm4>
|
||||
inline _wrapper<
|
||||
_ptr_fun4<FuncRet (*)(FuncParm1,FuncParm2,FuncParm3,FuncParm4), FuncRet, Parm1,Parm2,Parm3,Parm4 > >
|
||||
|
||||
ptr_fun(FuncRet (*func)(FuncParm1,FuncParm2,FuncParm3,FuncParm4), _wrapper<Parm1> parm1,_wrapper<Parm2> parm2,_wrapper<Parm3> parm3,_wrapper<Parm4> parm4) {
|
||||
|
||||
return make_wrapper(_ptr_fun4<
|
||||
FuncRet (*)(FuncParm1,FuncParm2,FuncParm3,FuncParm4), FuncRet, Parm1,Parm2,Parm3,Parm4 >
|
||||
(func, parm1.m_ftor,parm2.m_ftor,parm3.m_ftor,parm4.m_ftor));
|
||||
}
|
||||
|
||||
|
||||
template <typename Target, typename FuncRet, typename FuncClass>
|
||||
inline _wrapper<
|
||||
_mem_fun0<Target, FuncRet (FuncClass::*)(), FuncRet > >
|
||||
|
||||
mem_fun(_wrapper<Target> target, FuncRet (FuncClass::*func)()) {
|
||||
|
||||
return make_wrapper(_mem_fun0<
|
||||
Target, FuncRet (FuncClass::*)(), FuncRet >
|
||||
(target.m_ftor, func));
|
||||
}
|
||||
|
||||
template <typename FuncParm1, typename Target, typename FuncRet, typename FuncClass, typename Parm1>
|
||||
inline _wrapper<
|
||||
_mem_fun1<Target, FuncRet (FuncClass::*)(FuncParm1), FuncRet, Parm1 > >
|
||||
|
||||
mem_fun(_wrapper<Target> target, FuncRet (FuncClass::*func)(FuncParm1), _wrapper<Parm1> parm1) {
|
||||
|
||||
return make_wrapper(_mem_fun1<
|
||||
Target, FuncRet (FuncClass::*)(FuncParm1), FuncRet, Parm1 >
|
||||
(target.m_ftor, func, parm1.m_ftor));
|
||||
}
|
||||
|
||||
template <typename FuncParm1,typename FuncParm2, typename Target, typename FuncRet, typename FuncClass, typename Parm1,typename Parm2>
|
||||
inline _wrapper<
|
||||
_mem_fun2<Target, FuncRet (FuncClass::*)(FuncParm1,FuncParm2), FuncRet, Parm1,Parm2 > >
|
||||
|
||||
mem_fun(_wrapper<Target> target, FuncRet (FuncClass::*func)(FuncParm1,FuncParm2), _wrapper<Parm1> parm1,_wrapper<Parm2> parm2) {
|
||||
|
||||
return make_wrapper(_mem_fun2<
|
||||
Target, FuncRet (FuncClass::*)(FuncParm1,FuncParm2), FuncRet, Parm1,Parm2 >
|
||||
(target.m_ftor, func, parm1.m_ftor,parm2.m_ftor));
|
||||
}
|
||||
|
||||
template <typename FuncParm1,typename FuncParm2,typename FuncParm3, typename Target, typename FuncRet, typename FuncClass, typename Parm1,typename Parm2,typename Parm3>
|
||||
inline _wrapper<
|
||||
_mem_fun3<Target, FuncRet (FuncClass::*)(FuncParm1,FuncParm2,FuncParm3), FuncRet, Parm1,Parm2,Parm3 > >
|
||||
|
||||
mem_fun(_wrapper<Target> target, FuncRet (FuncClass::*func)(FuncParm1,FuncParm2,FuncParm3), _wrapper<Parm1> parm1,_wrapper<Parm2> parm2,_wrapper<Parm3> parm3) {
|
||||
|
||||
return make_wrapper(_mem_fun3<
|
||||
Target, FuncRet (FuncClass::*)(FuncParm1,FuncParm2,FuncParm3), FuncRet, Parm1,Parm2,Parm3 >
|
||||
(target.m_ftor, func, parm1.m_ftor,parm2.m_ftor,parm3.m_ftor));
|
||||
}
|
||||
|
||||
template <typename FuncParm1,typename FuncParm2,typename FuncParm3,typename FuncParm4, typename Target, typename FuncRet, typename FuncClass, typename Parm1,typename Parm2,typename Parm3,typename Parm4>
|
||||
inline _wrapper<
|
||||
_mem_fun4<Target, FuncRet (FuncClass::*)(FuncParm1,FuncParm2,FuncParm3,FuncParm4), FuncRet, Parm1,Parm2,Parm3,Parm4 > >
|
||||
|
||||
mem_fun(_wrapper<Target> target, FuncRet (FuncClass::*func)(FuncParm1,FuncParm2,FuncParm3,FuncParm4), _wrapper<Parm1> parm1,_wrapper<Parm2> parm2,_wrapper<Parm3> parm3,_wrapper<Parm4> parm4) {
|
||||
|
||||
return make_wrapper(_mem_fun4<
|
||||
Target, FuncRet (FuncClass::*)(FuncParm1,FuncParm2,FuncParm3,FuncParm4), FuncRet, Parm1,Parm2,Parm3,Parm4 >
|
||||
(target.m_ftor, func, parm1.m_ftor,parm2.m_ftor,parm3.m_ftor,parm4.m_ftor));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef ALGO_ENTRY_H
|
||||
#define ALGO_ENTRY_H
|
||||
|
||||
#include <algo/bits/common.h>
|
||||
#include <algo/bits/impl_entry.h>
|
||||
|
||||
namespace algo {
|
||||
|
||||
// Use a copy of the value of 't'.
|
||||
template <typename Type>
|
||||
inline _wrapper<_entry<typename traits<Type>::type_t> >
|
||||
value(Type t) {
|
||||
|
||||
return make_wrapper(_entry<typename traits<Type>::type_t>(t));
|
||||
}
|
||||
|
||||
// Use the reference to 't'.
|
||||
template <typename Type>
|
||||
inline _wrapper<_entry<typename traits<Type>::ref_t> >
|
||||
ref(Type& t) {
|
||||
|
||||
return make_wrapper(_entry<typename traits<Type>::ref_t>(t));
|
||||
}
|
||||
|
||||
inline _wrapper<_arg0>
|
||||
_0() {
|
||||
return make_wrapper(_arg0());
|
||||
}
|
||||
|
||||
// Use the reference to the member 't', in the class used
|
||||
// as an argument when calling this functor.
|
||||
template <typename Target, typename Type, typename Class>
|
||||
inline _wrapper<_member<Target, Type, Class> >
|
||||
member(_wrapper<Target> target, Type Class::*mem) {
|
||||
|
||||
return make_wrapper(_member<Target, Type, Class>(target.m_ftor, mem));
|
||||
}
|
||||
|
||||
template <typename Target, typename Parm0>
|
||||
inline _wrapper<_on1<Target, Parm0> >
|
||||
on(_wrapper<Target> target, _wrapper<Parm0> parm0) {
|
||||
|
||||
return make_wrapper(_on1<Target, Parm0>(target.m_ftor, parm0.m_ftor));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef ALGO_LAMBDA_H
|
||||
#define ALGO_LAMBDA_H
|
||||
|
||||
#include <algo/bits/common.h>
|
||||
#include <algo/bits/impl_lambda.h>
|
||||
|
||||
namespace algo {
|
||||
|
||||
ALGO_OP_BINARY( add, + )
|
||||
ALGO_MK_BINARY( add, + )
|
||||
ALGO_OP_BINARY( sub, - )
|
||||
ALGO_MK_BINARY( sub, - )
|
||||
ALGO_OP_BINARY( mult, * )
|
||||
ALGO_MK_BINARY( mult, * )
|
||||
ALGO_OP_BINARY( div, / )
|
||||
ALGO_MK_BINARY( div, / )
|
||||
ALGO_OP_BINARY( mod, % )
|
||||
ALGO_MK_BINARY( mod, % )
|
||||
ALGO_OP_BINARY( lshift, << )
|
||||
ALGO_MK_BINARY( lshift, << )
|
||||
ALGO_OP_BINARY( rshift, >> )
|
||||
ALGO_MK_BINARY( rshift, >> )
|
||||
ALGO_OP_BINARY( and, & )
|
||||
ALGO_MK_BINARY( and, & )
|
||||
ALGO_OP_BINARY( or, | )
|
||||
ALGO_MK_BINARY( or, | )
|
||||
ALGO_OP_BINARY( xor, ^ )
|
||||
ALGO_MK_BINARY( xor, ^ )
|
||||
|
||||
ALGO_OP_BINARY( assign, = )
|
||||
ALGO_OP_BINARY( aadd, += )
|
||||
ALGO_MK_BINARY( aadd, += )
|
||||
ALGO_OP_BINARY( asub, -= )
|
||||
ALGO_MK_BINARY( asub, -= )
|
||||
ALGO_OP_BINARY( amult, *= )
|
||||
ALGO_MK_BINARY( amult, *= )
|
||||
ALGO_OP_BINARY( adiv, /= )
|
||||
ALGO_MK_BINARY( adiv, /= )
|
||||
ALGO_OP_BINARY( amod, %= )
|
||||
ALGO_MK_BINARY( amod, %= )
|
||||
|
||||
ALGO_OP_BINARY( band, && )
|
||||
ALGO_MK_BINARY( band, && )
|
||||
ALGO_OP_BINARY( bor, || )
|
||||
ALGO_MK_BINARY( bor, || )
|
||||
ALGO_OP_BINARY( beq, == )
|
||||
ALGO_MK_BINARY( beq, == )
|
||||
ALGO_OP_BINARY( bneq, != )
|
||||
ALGO_MK_BINARY( bneq, != )
|
||||
ALGO_OP_BINARY( bless, < )
|
||||
ALGO_MK_BINARY( bless, < )
|
||||
ALGO_OP_BINARY( bleq, <= )
|
||||
ALGO_MK_BINARY( bleq, <= )
|
||||
ALGO_OP_BINARY( bgrt, > )
|
||||
ALGO_MK_BINARY( bgrt, > )
|
||||
ALGO_OP_BINARY( bgeq, >= )
|
||||
ALGO_MK_BINARY( bgeq, >= )
|
||||
|
||||
ALGO_OP_UNARY( not, ! )
|
||||
ALGO_OP_UNARY( inv, ~ )
|
||||
ALGO_OP_UNARY( addr, & )
|
||||
ALGO_OP_UNARY( pntr, * )
|
||||
|
||||
template <typename Type, typename Ftor>
|
||||
inline _wrapper<op_cast<Ftor, Type> >
|
||||
cast(_wrapper<Ftor> w1) {
|
||||
return make_wrapper(op_cast<Ftor, Type>(w1.m_ftor));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
// -*- c++ -*-
|
||||
/* Do not edit! -- generated file */
|
||||
|
||||
#ifndef ALGO_MEMORY_H
|
||||
#define ALGO_MEMORY_H
|
||||
|
||||
#include <algo/bits/common.h>
|
||||
#include <algo/bits/impl_memory.h>
|
||||
|
||||
namespace algo {
|
||||
|
||||
template <typename Ftor>
|
||||
inline _wrapper<_delete<Ftor> >
|
||||
call_delete(_wrapper<Ftor> w) {
|
||||
return make_wrapper(_delete<Ftor>(w.m_ftor));
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline _wrapper<_new0<Type> >
|
||||
call_new() {
|
||||
return make_wrapper(_new0<Type >());
|
||||
}
|
||||
|
||||
template <typename Type, typename P1>
|
||||
inline _wrapper<_new1<Type, P1> >
|
||||
call_new(_wrapper<P1> p1) {
|
||||
return make_wrapper(_new1<Type, P1 >(p1.m_ftor));
|
||||
}
|
||||
|
||||
template <typename Type, typename P1,typename P2>
|
||||
inline _wrapper<_new2<Type, P1,P2> >
|
||||
call_new(_wrapper<P1> p1,_wrapper<P2> p2) {
|
||||
return make_wrapper(_new2<Type, P1,P2 >(p1.m_ftor,p2.m_ftor));
|
||||
}
|
||||
|
||||
template <typename Type, typename P1,typename P2,typename P3>
|
||||
inline _wrapper<_new3<Type, P1,P2,P3> >
|
||||
call_new(_wrapper<P1> p1,_wrapper<P2> p2,_wrapper<P3> p3) {
|
||||
return make_wrapper(_new3<Type, P1,P2,P3 >(p1.m_ftor,p2.m_ftor,p3.m_ftor));
|
||||
}
|
||||
|
||||
template <typename Type, typename P1,typename P2,typename P3,typename P4>
|
||||
inline _wrapper<_new4<Type, P1,P2,P3,P4> >
|
||||
call_new(_wrapper<P1> p1,_wrapper<P2> p2,_wrapper<P3> p3,_wrapper<P4> p4) {
|
||||
return make_wrapper(_new4<Type, P1,P2,P3,P4 >(p1.m_ftor,p2.m_ftor,p3.m_ftor,p4.m_ftor));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,97 @@
|
||||
// -*- c++ -*-
|
||||
/* Do not edit! -- generated file */
|
||||
|
||||
#ifndef ALGO_CALL_H
|
||||
#define ALGO_CALL_H
|
||||
|
||||
#include <algo/bits/common.h>
|
||||
|
||||
namespace algo {
|
||||
|
||||
template <typename Func, typename T1 = _nil,typename T2 = _nil,typename T3 = _nil,typename T4 = _nil>
|
||||
struct test_args;
|
||||
|
||||
struct test_args0 {
|
||||
static const int result = 1;
|
||||
};
|
||||
|
||||
template <typename T1, typename P1>
|
||||
struct test_args1 {
|
||||
|
||||
static _one test(P1);
|
||||
static _two test(...);
|
||||
|
||||
static const int result = sizeof(test(_makeT<T1>()))
|
||||
== 1 ? 1 : 0;
|
||||
};
|
||||
|
||||
template <typename T1,typename T2, typename P1,typename P2>
|
||||
struct test_args2 {
|
||||
|
||||
static _one test(P1,P2);
|
||||
static _two test(...);
|
||||
|
||||
static const int result = sizeof(test(_makeT<T1>(),_makeT<T2>()))
|
||||
== 1 ? 1 : 0;
|
||||
};
|
||||
|
||||
template <typename T1,typename T2,typename T3, typename P1,typename P2,typename P3>
|
||||
struct test_args3 {
|
||||
|
||||
static _one test(P1,P2,P3);
|
||||
static _two test(...);
|
||||
|
||||
static const int result = sizeof(test(_makeT<T1>(),_makeT<T2>(),_makeT<T3>()))
|
||||
== 1 ? 1 : 0;
|
||||
};
|
||||
|
||||
template <typename T1,typename T2,typename T3,typename T4, typename P1,typename P2,typename P3,typename P4>
|
||||
struct test_args4 {
|
||||
|
||||
static _one test(P1,P2,P3,P4);
|
||||
static _two test(...);
|
||||
|
||||
static const int result = sizeof(test(_makeT<T1>(),_makeT<T2>(),_makeT<T3>(),_makeT<T4>()))
|
||||
== 1 ? 1 : 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename Ret>
|
||||
struct test_args<Ret (*)()> {
|
||||
|
||||
static const int result = 1;
|
||||
};
|
||||
|
||||
template <typename P1, typename T1,
|
||||
typename Ret>
|
||||
struct test_args<Ret (*)(P1), T1> {
|
||||
|
||||
static const int result = test_args1<T1, P1>::result;
|
||||
};
|
||||
|
||||
template <typename P1,typename P2, typename T1,typename T2,
|
||||
typename Ret>
|
||||
struct test_args<Ret (*)(P1,P2), T1,T2> {
|
||||
|
||||
static const int result = test_args2<T1,T2, P1,P2>::result;
|
||||
};
|
||||
|
||||
template <typename P1,typename P2,typename P3, typename T1,typename T2,typename T3,
|
||||
typename Ret>
|
||||
struct test_args<Ret (*)(P1,P2,P3), T1,T2,T3> {
|
||||
|
||||
static const int result = test_args3<T1,T2,T3, P1,P2,P3>::result;
|
||||
};
|
||||
|
||||
template <typename P1,typename P2,typename P3,typename P4, typename T1,typename T2,typename T3,typename T4,
|
||||
typename Ret>
|
||||
struct test_args<Ret (*)(P1,P2,P3,P4), T1,T2,T3,T4> {
|
||||
|
||||
static const int result = test_args4<T1,T2,T3,T4, P1,P2,P3,P4>::result;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,10 @@ noinst_LIBRARIES = libsub_display.a
|
||||
libsub_display_a_SOURCES = \
|
||||
canvas.cc \
|
||||
canvas.h \
|
||||
layers.cc \
|
||||
layers.h
|
||||
manager.cc \
|
||||
manager.h \
|
||||
manager_element.h \
|
||||
window.h \
|
||||
window.cc \
|
||||
|
||||
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "canvas.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
namespace display {
|
||||
|
||||
void
|
||||
Canvas::resize(int x, int y, int w, int h) {
|
||||
delwin(m_window);
|
||||
m_window = newwin(h, w, y, x);
|
||||
}
|
||||
|
||||
void
|
||||
Canvas::init() {
|
||||
initscr();
|
||||
|
||||
@@ -8,20 +8,20 @@ namespace display {
|
||||
|
||||
class Canvas {
|
||||
public:
|
||||
Canvas(int x, int y, int width = 0, int height = 0) :
|
||||
Canvas(int x = 0, int y = 0, int width = 0, int height = 0) :
|
||||
m_window(newwin(height, width, y, x)) {}
|
||||
~Canvas() { delwin(m_window); }
|
||||
|
||||
void refresh() { wnoutrefresh(m_window); }
|
||||
void redraw() { redrawwin(m_window); }
|
||||
|
||||
void update_size(int w, int h) { wresize(m_window, h, w); }
|
||||
void resize(int w, int h) { wresize(m_window, h, w); }
|
||||
void resize(int x, int y, int w, int h);
|
||||
|
||||
int get_x() { int x, y; getyx(m_window, y, x); return x; }
|
||||
int get_y() { int x, y; getyx(m_window, y, x); return y; }
|
||||
int get_width() { int x, y; getmaxyx(m_window, y, x); return x; }
|
||||
int get_height() { int x, y; getmaxyx(m_window, y, x); return y; }
|
||||
|
||||
chtype get_background() { return getbkgd(m_window); }
|
||||
void set_background(chtype c) { return wbkgdset(m_window, c); }
|
||||
|
||||
@@ -44,6 +44,9 @@ public:
|
||||
static void init();
|
||||
static void cleanup();
|
||||
|
||||
static int get_screen_width() { int x, y; getmaxyx(stdscr, y, x); return x; }
|
||||
static int get_screen_height() { int x, y; getmaxyx(stdscr, y, x); return y; }
|
||||
|
||||
static void do_update() { doupdate(); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "layers.h"
|
||||
#include "canvas.h"
|
||||
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
namespace display {
|
||||
|
||||
void
|
||||
Layers::do_update() {
|
||||
std::for_each(rbegin(), rend(), std::mem_fun(&Canvas::refresh));
|
||||
|
||||
Canvas::do_update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef RTORRENT_DISPLAY_LAYERS_H
|
||||
#define RTORRENT_DISPLAY_LAYERS_H
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace display {
|
||||
|
||||
class Canvas;
|
||||
|
||||
class Layers : private std::list<Canvas*> {
|
||||
public:
|
||||
typedef std::list<Canvas*> Base;
|
||||
|
||||
using Base::iterator;
|
||||
using Base::const_iterator;
|
||||
using Base::reverse_iterator;
|
||||
using Base::const_reverse_iterator;
|
||||
|
||||
using Base::begin;
|
||||
using Base::end;
|
||||
using Base::rbegin;
|
||||
using Base::rend;
|
||||
using Base::push_front;
|
||||
using Base::push_back;
|
||||
using Base::pop_front;
|
||||
using Base::pop_back;
|
||||
|
||||
void do_update();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <algo/call.h>
|
||||
#include <algo/entry.h>
|
||||
#include <algo/lambda.h>
|
||||
|
||||
#include "canvas.h"
|
||||
#include "manager.h"
|
||||
#include "window_base.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
using namespace algo;
|
||||
|
||||
void
|
||||
Manager::adjust_layout() {
|
||||
adjust_row(begin(), end(), 0, 0, display::Canvas::get_screen_width(), display::Canvas::get_screen_height());
|
||||
}
|
||||
|
||||
void
|
||||
Manager::adjust_row(iterator bItr, iterator eItr, int x, int y, int w, int h) {
|
||||
int t;
|
||||
int dist = std::distance(bItr, eItr);
|
||||
|
||||
switch (dist) {
|
||||
case 1:
|
||||
bItr->get_window()->resize(x, y, w, h);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
t = w / 2 + w % 2;
|
||||
|
||||
bItr->get_window()->resize(x, y, t, h);
|
||||
++bItr;
|
||||
bItr->get_window()->resize(x + t, y, w - t, h);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::logic_error("Manager::adjust_row(...) got a range with invalid number of elements");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::do_update() {
|
||||
std::for_each(begin(), end(), mem_fun(*mem_fun(_0(), &WindowBase::get_canvas), &Canvas::refresh));
|
||||
|
||||
Canvas::do_update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef RTORRENT_DISPLAY_MANAGER_H
|
||||
#define RTORRENT_DISPLAY_MANAGER_H
|
||||
|
||||
#include <list>
|
||||
#include "manager_element.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
class WindowBase;
|
||||
|
||||
class Manager : private std::list<ManagerElement> {
|
||||
public:
|
||||
typedef std::list<ManagerElement> Base;
|
||||
|
||||
using Base::iterator;
|
||||
using Base::const_iterator;
|
||||
using Base::reverse_iterator;
|
||||
using Base::const_reverse_iterator;
|
||||
|
||||
using Base::begin;
|
||||
using Base::end;
|
||||
using Base::rbegin;
|
||||
using Base::rend;
|
||||
|
||||
enum {
|
||||
NEW_ROW = 0x1
|
||||
};
|
||||
|
||||
Base::iterator add(WindowBase* w, int flags = 0) { return Base::insert(end(), ManagerElement(w, flags)); }
|
||||
|
||||
void adjust_layout();
|
||||
void do_update();
|
||||
|
||||
private:
|
||||
// Functions for adjusting ranges in different directions.
|
||||
void adjust_row(iterator bItr, iterator eItr, int x, int y, int w, int h);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef RTORRENT_DISPLAY_MANAGER_ELEMENT_H
|
||||
#define RTORRENT_DISPLAY_MANAGER_ELEMENT_H
|
||||
|
||||
namespace display {
|
||||
|
||||
class WindowBase;
|
||||
|
||||
class ManagerElement {
|
||||
public:
|
||||
ManagerElement(WindowBase* w, int flags) : m_window(w), m_flags(flags) {}
|
||||
|
||||
WindowBase* get_window() { return m_window; }
|
||||
void set_window(WindowBase* w) { m_window = w; }
|
||||
|
||||
int get_flags() { return m_flags; }
|
||||
void set_flags(int flags) { m_flags = flags; }
|
||||
|
||||
private:
|
||||
WindowBase* m_window;
|
||||
int m_flags;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "window_base.h"
|
||||
#include "canvas.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
void
|
||||
Window::refresh() {
|
||||
m_canvas->refresh();
|
||||
}
|
||||
|
||||
void
|
||||
Window::resize(int x, int y, int w, int h) {
|
||||
m_canvas->resize(x, y, w, h);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef RTORRENT_WINDOW_BASE_H
|
||||
#define RTORRENT_WINDOW_BASE_H
|
||||
|
||||
namespace display {
|
||||
|
||||
class Canvas;
|
||||
|
||||
class WindowBase {
|
||||
public:
|
||||
WindowBase() : m_canvas(NULL) {}
|
||||
virtual ~WindowBase() {}
|
||||
|
||||
Canvas* get_canvas() { return m_canvas; }
|
||||
void set_canvas(Canvas* c) { m_canvas = c; }
|
||||
|
||||
void refresh();
|
||||
void resize(int x, int y, int w, int h);
|
||||
|
||||
virtual void do_update() = 0;
|
||||
|
||||
protected:
|
||||
Canvas* m_canvas;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+34
-14
@@ -1,30 +1,50 @@
|
||||
#include <string>
|
||||
|
||||
#include "display/window_base.h"
|
||||
#include "display/canvas.h"
|
||||
#include "display/layers.h"
|
||||
#include "display/manager.h"
|
||||
|
||||
class WindowTest : public display::WindowBase {
|
||||
public:
|
||||
WindowTest(const std::string& str) : m_str(str) {}
|
||||
|
||||
virtual void do_update() {
|
||||
if (m_canvas == NULL)
|
||||
return;
|
||||
|
||||
m_canvas->erase();
|
||||
m_canvas->print_border('|', '|', '-', '-', '+', '+', '+', '+');
|
||||
m_canvas->print(1, 1, "%s", m_str.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_str;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
display::Canvas::init();
|
||||
display::Layers layers;
|
||||
display::Manager manager;
|
||||
|
||||
display::Canvas canvas1(0, 0, 20, 0);
|
||||
display::Canvas canvas2(15, 5, 20, 10);
|
||||
WindowTest window1("This is window 1");
|
||||
WindowTest window2("This is window 2");
|
||||
|
||||
layers.push_front(&canvas1);
|
||||
layers.push_front(&canvas2);
|
||||
window1.set_canvas(new display::Canvas());
|
||||
window2.set_canvas(new display::Canvas());
|
||||
|
||||
canvas1.erase();
|
||||
canvas2.erase();
|
||||
canvas1.set_background(A_REVERSE);
|
||||
manager.add(&window1);
|
||||
manager.add(&window2);
|
||||
|
||||
canvas1.print_border('|', '|', '-', '-', '+', '+', '+', '+');
|
||||
canvas2.print_border('|', '|', '-', '-', '+', '+', '+', '+');
|
||||
window1.get_canvas()->set_background(A_REVERSE);
|
||||
|
||||
canvas1.print(2, 5, "test %i %s", 42, "bar");
|
||||
|
||||
layers.do_update();
|
||||
manager.adjust_layout();
|
||||
manager.do_update();
|
||||
|
||||
while (true);
|
||||
|
||||
display::Canvas::cleanup();
|
||||
|
||||
delete window1.get_canvas();
|
||||
delete window2.get_canvas();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user