20#ifndef CCGSL_FUNCTION_SCL_HPP
21#define CCGSL_FUNCTION_SCL_HPP
26#if __cplusplus <= 199711L
30#include<gsl/gsl_math.h>
106 typedef double (*function_t)(double,
void*);
115 virtual function_t function() = 0;
121 class Fx :
public base_F {
127 Fx(
double (*
const f)(A) ) :
f(
f ){}
131 function_t function(){
return &
fn; }
136 double (*
const f)(A);
144 static double fn(
double x,
void* params ){
145 return reinterpret_cast<Fx<A>*
>( params )->
f( x ); }
151 class Fxc :
public base_F {
157 Fxc(
double const (*
const f)(A) ) :
f(
f ){}
161 function_t function(){
return &
fn; }
166 double const (*
const f)(A);
174 static double fn(
double x,
void* params ){
175 return reinterpret_cast<Fxc<A>*
>( params )->
f( x ); }
181 template<
typename T,
typename R,
typename A>
182 class F :
public base_F {
191 F(T& c, R (T::*
f)(A)) : c( c ),
f(
f) {}
197 double operator()(
double x ){
return (c.*
f)( x ); }
201 function_t function(){
return &function_s; }
211 static double function_s(
double x,
void* params ){
212 F<T,R,A>*
const cl =
reinterpret_cast<F<T,R,A>*
>( params );
213 return (cl->c.*cl->f)(x); }
227 template<
typename T,
typename R,
typename A>
228 class Fc :
public base_F {
237 Fc(T& c, R (T::*
f)(A)
const) : c( c ),
f(
f) {}
243 double operator()(
double x ){
return (c.*
f)( x ); }
247 function_t function(){
return &function_s; }
257 static double function_s(
double x,
void* params ){
258 Fc<T,R,A>*
const cl =
reinterpret_cast<Fc<T,R,A>*
>( params );
259 return (cl->c.*cl->f)(x); }
272 template<
typename T,
typename R,
typename A>
273 class Fv :
public base_F {
282 Fv(T& c, R (T::*
f)(A)
volatile) : c( c ),
f(
f) {}
288 double operator()(
double x ){
return (c.*
f)( x ); }
292 function_t function(){
return &function_s; }
302 static double function_s(
double x,
void* params ){
303 Fv<T,R,A>*
const cl =
reinterpret_cast<Fv<T,R,A>*
>( params );
304 return (cl->c.*cl->f)(x); }
312 R (T::*
f)(A)
volatile;
317 template<
typename T,
typename R,
typename A>
318 class Fcv :
public base_F {
327 Fcv(T& c, R (T::*
f)(A)
const volatile) : c( c ),
f(
f) {}
333 double operator()(
double x ){
return (c.*
f)( x ); }
337 function_t function(){
return &function_s; }
347 static double function_s(
double x,
void* params ){
348 Fcv<T,R,A>*
const cl =
reinterpret_cast<Fcv<T,R,A>*
>( params );
349 return (cl->c.*cl->f)(x); }
357 R (T::*
f)(A)
const volatile;
383 function = v.function;
397 this->f =
new Fx<A>(
f );
399 function =
dynamic_cast<Fx<A>*
>(this->
f)->
fn;
412 this->f =
new Fxc<A>(
f );
414 function =
dynamic_cast<Fxc<A>*
>(this->
f)->
fn;
424 template<
typename T,
typename R,
typename A>
function_scl( T& c, R (T::*
f)(A) ){
425 this->f =
new F<T,R,A>( c,
f );
437 template<
typename T,
typename R,
typename A>
function_scl( T& c, R (T::*
f)(A)
const){
438 this->f =
new Fc<T,R,A>( c,
f );
450 template<
typename T,
typename R,
typename A>
function_scl( T& c, R (T::*
f)(A)
volatile){
451 this->f =
new Fv<T,R,A>( c,
f );
463 template<
typename T,
typename R,
typename A>
function_scl( T& c, R (T::*
f)(A)
465 this->f =
new Fcv<T,R,A>( c,
f );
479 function = v.function;
496 function = v.function;
502#ifdef __GXX_EXPERIMENTAL_CXX0X__
508 std::swap( function, v.function );
509 std::swap( params, v.params );
510 std::swap(
count, v.count );
520 std::swap( function, v.function );
521 std::swap( params, v.params );
522 std::swap(
count, v.count );
544 static double fn(
double x,
void* params ){
545 base_F*
const b =
reinterpret_cast<base_F*
>( params );
546 return b->function()( x, params );
558 template<
typename T,
typename R,
typename A>
569 template<
typename T,
typename R,
typename A>
571 function_scl fn( c, f );
579 template<
typename T,
typename R,
typename A>
581 function_scl fn( c, f );
589 template<
typename T,
typename R,
typename A>
591 function_scl fn( c, f );
600 inline double fn_eval( gsl_function
const*
const F,
double const x ){
601 return (
F->function)( x,
F->params );
610 inline double fn_eval( gsl_function
const&
F,
double const x ){
611 return (
F.function)( x,
F.params );
Class that extends gsl_function so that it can be constructed from arbitrary function objects.
function_scl(double(*const f)(A))
Construct from a function.
function_scl(T &c, R(T::*f)(A) const)
Construct from a function object and a suitable const member function.
function_scl(gsl_function &v)
Could construct from a gsl_function.
function_scl(double const (*const f)(A))
Construct from a function.
function_scl & operator=(function_scl const &v)
The assignment operator.
function_scl(T &c, R(T::*f)(A) volatile)
Construct from a function object and a suitable volatile member function.
function_scl & operator=(function_scl &&v)
Move operator.
size_t * count
The shared reference count.
function_scl(function_scl const &v)
The copy constructor.
static double fn(double x, void *params)
This is the function that gsl_function points to if function_scl is constructed from a function objec...
function_scl()
The default constructor is only really useful for assigning to.
function_scl(T &c, R(T::*f)(A) const volatile)
Construct from a function object and a suitable const volatile member function.
function_scl(T &c, R(T::*f)(A))
Construct from a function object and a suitable non-const member function.
~function_scl()
The destructor unshares any shared resource.
function_scl(function_scl &&v)
Move constructor.
double F(double phi, double k, mode_t mode)
C++ version of gsl_sf_ellint_F().
double b(int order, double qq)
C++ version of gsl_sf_mathieu_b().
The gsl package creates an interface to the GNU Scientific Library for C++.
double fn_eval(gsl_function const &F, double const x)
Evaluate a gsl::function (or gsl_function).
function_scl make_function_scl(T &c, R(T::*f)(A))
Make a gsl::function_scl from a function object and a suitable non-const member function.