00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_functor_h)
00024 #define octave_functor_h 1
00025
00026 template <typename RT, typename PT>
00027 class fcn_ptr
00028 {
00029 public:
00030 typedef RT (*TYPE) (PT);
00031 };
00032
00033 template <typename RT, typename PT>
00034 class functor
00035 {
00036 private:
00037 typedef typename fcn_ptr<RT, PT>::TYPE fcn_ptr_type;
00038 fcn_ptr_type fptr;
00039
00040 public:
00041
00042 functor (fcn_ptr_type p) : fptr (p) { }
00043
00044 RT operator () (PT arg) { return fptr (arg); }
00045 };
00046
00047 template <typename CT, typename RT, typename PT>
00048 class functor_with_conversion
00049 {
00050 private:
00051 typedef typename fcn_ptr<RT, PT>::TYPE fcn_ptr_type;
00052 fcn_ptr_type fptr;
00053
00054 public:
00055
00056 functor_with_conversion (fcn_ptr_type p) : fptr (p) { }
00057
00058 CT operator () (PT arg) { return CT (fptr (arg)); }
00059 };
00060
00061 template <typename RT, typename PT>
00062 functor<RT, PT>
00063 func_ptr (RT (*f) (PT))
00064 {
00065 return functor<RT, PT> (f);
00066 }
00067
00068 template <typename CT, typename RT, typename PT>
00069 functor_with_conversion<CT, RT, PT>
00070 func_ptr_with_conversion (RT (*f) (PT))
00071 {
00072 return functor_with_conversion<CT, RT, PT> (f);
00073 }
00074
00075 #endif
00076
00077
00078
00079
00080
00081