Commit 43a028bb authored by Davis King's avatar Davis King

Turned the member_function_pointer into a single implementation component.

parent fe93ddaf
......@@ -4,36 +4,7 @@
#define DLIB_MEMBER_FUNCTION_POINTEr_
#include "member_function_pointer/member_function_pointer_kernel_1.h"
#include "member_function_pointer/member_function_pointer_kernel_c.h"
#include "member_function_pointer/make_mfp.h"
namespace dlib
{
template <
typename PARAM1 = void,
typename PARAM2 = void,
typename PARAM3 = void,
typename PARAM4 = void
>
class member_function_pointer
{
member_function_pointer() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef mfpk1<PARAM1,PARAM2,PARAM3,PARAM4>
kernel_1a;
typedef mfpkc<kernel_1a>
kernel_1a_c;
};
}
#endif // DLIB_MEMBER_FUNCTION_POINTEr_
......@@ -14,12 +14,12 @@ namespace dlib
template <
typename T
>
mfpk1<> make_mfp (
member_function_pointer<> make_mfp (
T& object,
void (T::*cb)()
)
{
mfpk1<> temp;
member_function_pointer<> temp;
temp.set(object, cb);
return temp;
}
......@@ -27,12 +27,12 @@ namespace dlib
template <
typename T
>
mfpk1<> make_mfp (
member_function_pointer<> make_mfp (
const T& object,
void (T::*cb)()const
)
{
mfpk1<> temp;
member_function_pointer<> temp;
temp.set(object, cb);
return temp;
}
......@@ -43,12 +43,12 @@ namespace dlib
typename T,
typename A1
>
mfpk1<A1> make_mfp (
member_function_pointer<A1> make_mfp (
T& object,
void (T::*cb)(A1)
)
{
mfpk1<A1> temp;
member_function_pointer<A1> temp;
temp.set(object, cb);
return temp;
}
......@@ -57,12 +57,12 @@ namespace dlib
typename T,
typename A1
>
mfpk1<A1> make_mfp (
member_function_pointer<A1> make_mfp (
const T& object,
void (T::*cb)(A1)const
)
{
mfpk1<A1> temp;
member_function_pointer<A1> temp;
temp.set(object, cb);
return temp;
}
......@@ -74,12 +74,12 @@ namespace dlib
typename A1,
typename A2
>
mfpk1<A1,A2> make_mfp (
member_function_pointer<A1,A2> make_mfp (
T& object,
void (T::*cb)(A1,A2)
)
{
mfpk1<A1,A2> temp;
member_function_pointer<A1,A2> temp;
temp.set(object, cb);
return temp;
}
......@@ -89,12 +89,12 @@ namespace dlib
typename A1,
typename A2
>
mfpk1<A1,A2> make_mfp (
member_function_pointer<A1,A2> make_mfp (
const T& object,
void (T::*cb)(A1,A2)const
)
{
mfpk1<A1,A2> temp;
member_function_pointer<A1,A2> temp;
temp.set(object, cb);
return temp;
}
......@@ -107,12 +107,12 @@ namespace dlib
typename A2,
typename A3
>
mfpk1<A1,A2,A3> make_mfp (
member_function_pointer<A1,A2,A3> make_mfp (
T& object,
void (T::*cb)(A1,A2,A3)
)
{
mfpk1<A1,A2,A3> temp;
member_function_pointer<A1,A2,A3> temp;
temp.set(object, cb);
return temp;
}
......@@ -123,12 +123,12 @@ namespace dlib
typename A2,
typename A3
>
mfpk1<A1,A2,A3> make_mfp (
member_function_pointer<A1,A2,A3> make_mfp (
const T& object,
void (T::*cb)(A1,A2,A3)const
)
{
mfpk1<A1,A2,A3> temp;
member_function_pointer<A1,A2,A3> temp;
temp.set(object, cb);
return temp;
}
......@@ -142,12 +142,12 @@ namespace dlib
typename A3,
typename A4
>
mfpk1<A1,A2,A3,A4> make_mfp (
member_function_pointer<A1,A2,A3,A4> make_mfp (
T& object,
void (T::*cb)(A1,A2,A3,A4)
)
{
mfpk1<A1,A2,A3,A4> temp;
member_function_pointer<A1,A2,A3,A4> temp;
temp.set(object, cb);
return temp;
}
......@@ -159,12 +159,12 @@ namespace dlib
typename A3,
typename A4
>
mfpk1<A1,A2,A3,A4> make_mfp (
member_function_pointer<A1,A2,A3,A4> make_mfp (
const T& object,
void (T::*cb)(A1,A2,A3,A4)const
)
{
mfpk1<A1,A2,A3,A4> temp;
member_function_pointer<A1,A2,A3,A4> temp;
temp.set(object, cb);
return temp;
}
......
......@@ -13,7 +13,7 @@ namespace dlib
template <
typename T
>
member_function_pointer<>::kernel_1a make_mfp (
member_function_pointer<> make_mfp (
T& object,
void (T::*cb)()
);
......@@ -29,7 +29,7 @@ namespace dlib
template <
typename T
>
member_function_pointer<>::kernel_1a make_mfp (
member_function_pointer<> make_mfp (
const T& object,
void (T::*cb)()const
);
......@@ -48,7 +48,7 @@ namespace dlib
typename T,
typename A1
>
typename member_function_pointer<A1>::kernel_1a make_mfp (
member_function_pointer<A1> make_mfp (
T& object,
void (T::*cb)(A1 a1)
);
......@@ -65,7 +65,7 @@ namespace dlib
typename T,
typename A1
>
typename member_function_pointer<A1>::kernel_1a make_mfp (
member_function_pointer<A1> make_mfp (
const T& object,
void (T::*cb)(A1 a1)const
);
......@@ -85,7 +85,7 @@ namespace dlib
typename A1,
typename A2
>
typename member_function_pointer<A1,A2>::kernel_1a make_mfp (
member_function_pointer<A1,A2> make_mfp (
T& object,
void (T::*cb)(A1 a1, A2 a2)
);
......@@ -103,7 +103,7 @@ namespace dlib
typename A1,
typename A2
>
typename member_function_pointer<A1,A2>::kernel_1a make_mfp (
member_function_pointer<A1,A2> make_mfp (
const T& object,
void (T::*cb)(A1 a1, A2 a2)const
);
......@@ -124,7 +124,7 @@ namespace dlib
typename A2,
typename A3
>
typename member_function_pointer<A1,A2,A3>::kernel_1a make_mfp (
member_function_pointer<A1,A2,A3> make_mfp (
T& object,
void (T::*cb)(A1 a1, A2 a2, A3 a3)
);
......@@ -143,7 +143,7 @@ namespace dlib
typename A2,
typename A3
>
typename member_function_pointer<A1,A2,A3>::kernel_1a make_mfp (
member_function_pointer<A1,A2,A3> make_mfp (
const T& object,
void (T::*cb)(A1 a1, A2 a2, A3 a3)const
);
......@@ -165,7 +165,7 @@ namespace dlib
typename A3,
typename A4
>
typename member_function_pointer<A1,A2,A3,A4>::kernel_1a make_mfp (
member_function_pointer<A1,A2,A3,A4> make_mfp (
T& object,
void (T::*cb)(A1 a1, A2 a2, A3 a3, A4 a4)
);
......@@ -185,7 +185,7 @@ namespace dlib
typename A3,
typename A4
>
typename member_function_pointer<A1,A2,A3,A4>::kernel_1a make_mfp (
member_function_pointer<A1,A2,A3,A4> make_mfp (
const T& object,
void (T::*cb)(A1 a1, A2 a2, A3 a3, A4 a4)const
);
......
......@@ -19,7 +19,20 @@ namespace dlib
typename PARAM3 = void,
typename PARAM4 = void
>
class mfpk1;
class member_function_pointer;
// ----------------------------------------------------------------------------------------
#define DLIB_MFP_SC DLIB_ASSERT(cb != 0, \
"\tvoid member_function_pointer::set" \
<< "\n\tthe member function pointer can't be null" \
<< "\n\tthis: " << this );
#define DLIB_MFP_OC DLIB_ASSERT(this->is_set() == true , \
"\tvoid member_function_pointer::operator()" \
<< "\n\tYou must call set() before you can use this function" \
<< "\n\tthis: " << this);
// ----------------------------------------------------------------------------------------
......@@ -188,7 +201,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template <>
class mfpk1<void,void,void,void> : public mfp_kernel_1_base_class<0>
class member_function_pointer<void,void,void,void> : public mfp_kernel_1_base_class<0>
{
class mp_base : public mp_base_base {
public:
......@@ -222,16 +235,22 @@ namespace dlib
typedef void param3_type;
typedef void param4_type;
void operator() () const { static_cast<const mp_base*>(mp_memory.get())->call(); }
// These two typedefs are here for backwards compatibility with previous versions
// of dlib.
typedef member_function_pointer kernel_1a;
typedef member_function_pointer kernel_1a_c;
void operator() () const { DLIB_MFP_OC; static_cast<const mp_base*>(mp_memory.get())->call(); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -240,7 +259,7 @@ namespace dlib
template <
typename PARAM1
>
class mfpk1<PARAM1,void,void,void> : public mfp_kernel_1_base_class<1>
class member_function_pointer<PARAM1,void,void,void> : public mfp_kernel_1_base_class<1>
{
class mp_base : public mp_base_base {
public:
......@@ -274,16 +293,22 @@ namespace dlib
typedef void param3_type;
typedef void param4_type;
void operator() (PARAM1 p1) const { static_cast<const mp_base*>(mp_memory.get())->call(p1); }
// These two typedefs are here for backwards compatibility with previous versions
// of dlib.
typedef member_function_pointer kernel_1a;
typedef member_function_pointer kernel_1a_c;
void operator() (PARAM1 p1) const { DLIB_MFP_OC; static_cast<const mp_base*>(mp_memory.get())->call(p1); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -293,7 +318,7 @@ namespace dlib
typename PARAM1,
typename PARAM2
>
class mfpk1<PARAM1,PARAM2,void,void> : public mfp_kernel_1_base_class<2>
class member_function_pointer<PARAM1,PARAM2,void,void> : public mfp_kernel_1_base_class<2>
{
class mp_base : public mp_base_base {
public:
......@@ -327,16 +352,21 @@ namespace dlib
typedef void param3_type;
typedef void param4_type;
void operator() (PARAM1 p1, PARAM2 p2) const { static_cast<const mp_base*>(mp_memory.get())->call(p1,p2); }
// These two typedefs are here for backwards compatibility with previous versions
// of dlib.
typedef member_function_pointer kernel_1a;
typedef member_function_pointer kernel_1a_c;
void operator() (PARAM1 p1, PARAM2 p2) const { DLIB_MFP_OC; static_cast<const mp_base*>(mp_memory.get())->call(p1,p2); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -347,7 +377,7 @@ namespace dlib
typename PARAM2,
typename PARAM3
>
class mfpk1<PARAM1,PARAM2,PARAM3,void> : public mfp_kernel_1_base_class<3>
class member_function_pointer<PARAM1,PARAM2,PARAM3,void> : public mfp_kernel_1_base_class<3>
{
class mp_base : public mp_base_base {
public:
......@@ -381,16 +411,21 @@ namespace dlib
typedef PARAM3 param3_type;
typedef void param4_type;
void operator() (PARAM1 p1, PARAM2 p2, PARAM3 p3) const { static_cast<const mp_base*>(mp_memory.get())->call(p1,p2,p3); }
// These two typedefs are here for backwards compatibility with previous versions
// of dlib.
typedef member_function_pointer kernel_1a;
typedef member_function_pointer kernel_1a_c;
void operator() (PARAM1 p1, PARAM2 p2, PARAM3 p3) const { DLIB_MFP_OC; static_cast<const mp_base*>(mp_memory.get())->call(p1,p2,p3); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -402,7 +437,7 @@ namespace dlib
typename PARAM3,
typename PARAM4
>
class mfpk1 : public mfp_kernel_1_base_class<4>
class member_function_pointer : public mfp_kernel_1_base_class<4>
{
class mp_base : public mp_base_base {
public:
......@@ -436,17 +471,22 @@ namespace dlib
typedef PARAM3 param3_type;
typedef PARAM4 param4_type;
// These two typedefs are here for backwards compatibility with previous versions
// of dlib.
typedef member_function_pointer kernel_1a;
typedef member_function_pointer kernel_1a_c;
void operator() (PARAM1 p1, PARAM2 p2, PARAM3 p3, PARAM4 p4) const
{ static_cast<const mp_base*>(mp_memory.get())->call(p1,p2,p3,p4); }
{ DLIB_MFP_OC; static_cast<const mp_base*>(mp_memory.get())->call(p1,p2,p3,p4); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
{ DLIB_MFP_SC; destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......
......@@ -122,11 +122,11 @@ namespace
mfp<int,int,int> a3, b3;
mfp<int,int,int,int> a4, b4;
mfpkc<mfp<> > a0c, b0c;
mfpkc<mfp<int> > a1c, b1c;
mfpkc<mfp<int,int> > a2c, b2c;
mfpkc<mfp<int,int,int> > a3c, b3c;
mfpkc<mfp<int,int,int,int> > a4c, b4c;
mfp<> a0c, b0c;
mfp<int> a1c, b1c;
mfp<int,int> a2c, b2c;
mfp<int,int,int> a3c, b3c;
mfp<int,int,int,int> a4c, b4c;
DLIB_TEST(a0c == b0c);
DLIB_TEST(a1c == b1c);
......@@ -543,8 +543,8 @@ namespace
void perform_test (
)
{
member_function_pointer_kernel_test<mfpk1,mfp_test_helper>();
member_function_pointer_kernel_test<mfpk1,mfp_test_helper_const>();
member_function_pointer_kernel_test<member_function_pointer,mfp_test_helper>();
member_function_pointer_kernel_test<member_function_pointer,mfp_test_helper_const>();
}
} a;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment