Converted the bound_function_pointer into a single implementation component.

This commit is contained in:
Davis King 2012-11-18 12:07:38 -05:00
parent 68658f88c0
commit 2ce5a85722
3 changed files with 27 additions and 102 deletions

View File

@ -4,29 +4,6 @@
#define DLIB_BOUND_FUNCTION_POINTEr_
#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_

View File

@ -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;
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); }
bound_function_pointer_kernel_1 (
const bound_function_pointer_kernel_1& item
bound_function_pointer (
const bound_function_pointer& item
) { item.bf()->clone(bf_memory.get()); }
~bound_function_pointer_kernel_1()
~bound_function_pointer()
{ destroy_bf_memory(); }
bound_function_pointer_kernel_1& operator= (
const bound_function_pointer_kernel_1& item
) { bound_function_pointer_kernel_1(item).swap(*this); return *this; }
bound_function_pointer& operator= (
const bound_function_pointer& item
) { bound_function_pointer(item).swap(*this); return *this; }
void clear (
) { bound_function_pointer_kernel_1().swap(*this); }
) { bound_function_pointer().swap(*this); }
bool is_set (
) const
@ -250,11 +257,11 @@ namespace dlib
}
void swap (
bound_function_pointer_kernel_1& item
bound_function_pointer& item
)
{
// make a temp copy of item
bound_function_pointer_kernel_1 temp(item);
bound_function_pointer temp(item);
// destory the stuff in item
item.destroy_bf_memory();
@ -270,6 +277,13 @@ namespace dlib
void operator() (
) 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();
}
@ -748,8 +762,8 @@ namespace dlib
// ----------------------------------------------------------------------------------------
inline void swap (
bound_function_pointer_kernel_1& a,
bound_function_pointer_kernel_1& b
bound_function_pointer& a,
bound_function_pointer& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------

View File

@ -1,66 +0,0 @@
// 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_