Commit 2ce5a857 authored by Davis King's avatar Davis King

Converted the bound_function_pointer into a single implementation component.

parent 68658f88
...@@ -4,29 +4,6 @@ ...@@ -4,29 +4,6 @@
#define DLIB_BOUND_FUNCTION_POINTEr_ #define DLIB_BOUND_FUNCTION_POINTEr_
#include "bound_function_pointer/bound_function_pointer_kernel_1.h" #include "bound_function_pointer/bound_function_pointer_kernel_1.h"
#include "bound_function_pointer/bound_function_pointer_kernel_c.h"
namespace dlib
{
class bound_function_pointer
{
bound_function_pointer() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef bound_function_pointer_kernel_1
kernel_1a;
typedef bound_function_pointer_kernel_c<kernel_1a>
kernel_1a_c;
};
}
#endif // DLIB_BOUND_FUNCTION_POINTEr_ #endif // DLIB_BOUND_FUNCTION_POINTEr_
......
...@@ -221,27 +221,34 @@ namespace dlib ...@@ -221,27 +221,34 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
class bound_function_pointer_kernel_1 class bound_function_pointer
{ {
typedef bfp1_helpers::bound_function_helper_T<bfp1_helpers::bound_function_helper<void,int> > bf_null_type; typedef bfp1_helpers::bound_function_helper_T<bfp1_helpers::bound_function_helper<void,int> > bf_null_type;
public: public:
bound_function_pointer_kernel_1 (
// These typedefs are here for backwards compatibility with previous versions of
// dlib.
typedef bound_function_pointer kernel_1a;
typedef bound_function_pointer kernel_1a_c;
bound_function_pointer (
) { bf_null_type().safe_clone(bf_memory); } ) { bf_null_type().safe_clone(bf_memory); }
bound_function_pointer_kernel_1 ( bound_function_pointer (
const bound_function_pointer_kernel_1& item const bound_function_pointer& item
) { item.bf()->clone(bf_memory.get()); } ) { item.bf()->clone(bf_memory.get()); }
~bound_function_pointer_kernel_1() ~bound_function_pointer()
{ destroy_bf_memory(); } { destroy_bf_memory(); }
bound_function_pointer_kernel_1& operator= ( bound_function_pointer& operator= (
const bound_function_pointer_kernel_1& item const bound_function_pointer& item
) { bound_function_pointer_kernel_1(item).swap(*this); return *this; } ) { bound_function_pointer(item).swap(*this); return *this; }
void clear ( void clear (
) { bound_function_pointer_kernel_1().swap(*this); } ) { bound_function_pointer().swap(*this); }
bool is_set ( bool is_set (
) const ) const
...@@ -250,11 +257,11 @@ namespace dlib ...@@ -250,11 +257,11 @@ namespace dlib
} }
void swap ( void swap (
bound_function_pointer_kernel_1& item bound_function_pointer& item
) )
{ {
// make a temp copy of item // make a temp copy of item
bound_function_pointer_kernel_1 temp(item); bound_function_pointer temp(item);
// destory the stuff in item // destory the stuff in item
item.destroy_bf_memory(); item.destroy_bf_memory();
...@@ -270,6 +277,13 @@ namespace dlib ...@@ -270,6 +277,13 @@ namespace dlib
void operator() ( void operator() (
) const ) const
{ {
// make sure requires clause is not broken
DLIB_ASSERT(is_set() == true ,
"\tvoid bound_function_pointer::operator()"
<< "\n\tYou must call set() before you can use this function"
<< "\n\tthis: " << this
);
bf()->call(); bf()->call();
} }
...@@ -748,8 +762,8 @@ namespace dlib ...@@ -748,8 +762,8 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
inline void swap ( inline void swap (
bound_function_pointer_kernel_1& a, bound_function_pointer& a,
bound_function_pointer_kernel_1& b bound_function_pointer& b
) { a.swap(b); } ) { a.swap(b); }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
// Copyright (C) 2008 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BOUND_FUNCTION_POINTER_KERNEl_C_
#define DLIB_BOUND_FUNCTION_POINTER_KERNEl_C_
#include "bound_function_pointer_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
namespace dlib
{
template <
typename bound_function_pointer_base // is an implementation of bound_function_pointer_kernel_abstract.h
>
class bound_function_pointer_kernel_c : public bound_function_pointer_base
{
public:
void operator () (
) const;
};
template <
typename bound_function_pointer_base
>
inline void swap (
bound_function_pointer_kernel_c<bound_function_pointer_base>& a,
bound_function_pointer_kernel_c<bound_function_pointer_base>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename bound_function_pointer_base
>
void bound_function_pointer_kernel_c<bound_function_pointer_base>::
operator() (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(this->is_set() == true ,
"\tvoid bound_function_pointer::operator()"
<< "\n\tYou must call set() before you can use this function"
<< "\n\tthis: " << this
);
// call the real function
bound_function_pointer_base::operator()();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_BOUND_FUNCTION_POINTER_KERNEl_C_
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