Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Euclid::MathUtils::FunctionAdapter Class Referencefinal

Adapt a std::function<double(double)> to the Function Interface. More...

#include <FunctionAdapter.h>

Inheritance diagram for Euclid::MathUtils::FunctionAdapter:
Inheritance graph
[legend]
Collaboration diagram for Euclid::MathUtils::FunctionAdapter:
Collaboration graph
[legend]

Public Member Functions

 FunctionAdapter (std::function< double(double)> function)
 Constructor.
 
virtual ~FunctionAdapter ()=default
 Default destructor.
 
double operator() (const double x) const override
 
void operator() (const std::vector< double > &xs, std::vector< double > &out) const override
 
std::unique_ptr< Functionclone () const override
 

Private Attributes

std::function< double(double)> m_function
 

Detailed Description

Adapt a std::function<double(double)> to the Function Interface.

In some case one need to wrap a std::function into the Function Interface. This class provide this functionality. In particular it allows to build a Function out of a Lamda expression.

Definition at line 44 of file FunctionAdapter.h.

Constructor & Destructor Documentation

◆ FunctionAdapter()

Euclid::MathUtils::FunctionAdapter::FunctionAdapter ( std::function< double(double)>  function)
explicit

Constructor.

Parameters
functionA std::function<double(double)> to be adapted as a Function.

Definition at line 32 of file FunctionAdapter.cpp.

◆ ~FunctionAdapter()

virtual Euclid::MathUtils::FunctionAdapter::~FunctionAdapter ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ clone()

std::unique_ptr< Function > Euclid::MathUtils::FunctionAdapter::clone ( ) const
overridevirtual

Creates a clone of the function adapter object.

Returns
A copy of the FunctionAdapter object

Implements Euclid::MathUtils::NAryFunction< N >.

Definition at line 43 of file FunctionAdapter.cpp.

References m_function.

◆ operator()() [1/2]

double Euclid::MathUtils::FunctionAdapter::operator() ( const double  x) const
override

Converts the value x from the input domain to the output domain by calling the internal std::function<double(double)>.

Parameters
xThe value to convert
Returns
The value of the output domain

Definition at line 34 of file FunctionAdapter.cpp.

References m_function.

◆ operator()() [2/2]

void Euclid::MathUtils::FunctionAdapter::operator() ( const std::vector< double > &  xs,
std::vector< double > &  out 
) const
override

Converts the vector of x values from the input domain to the output domain by calling the internal std::function<double(double)> repeatedly.

Parameters
xsThe values to convert
outOutput vector

Definition at line 38 of file FunctionAdapter.cpp.

References std::vector< T >::begin(), std::array< T >::begin(), std::array< T >::end(), m_function, std::vector< T >::resize(), std::array< T >::size(), and std::transform().

Here is the call graph for this function:

Member Data Documentation

◆ m_function

std::function<double(double)> Euclid::MathUtils::FunctionAdapter::m_function
private

Definition at line 79 of file FunctionAdapter.h.

Referenced by clone(), operator()(), and operator()().


The documentation for this class was generated from the following files: