DGtal  1.5.beta
DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor > Class Template Reference

Aim: hold any object callable on points as a DGtal::concepts::CPointFunctor model. More...

#include <DGtal/kernel/PointFunctorHolder.h>

Public Types

using Self = PointFunctorHolder< TPoint, TValue, TFunctor >
 
using Point = TPoint
 
using Value = TValue
 
using Functor = TFunctor
 

Public Member Functions

template<typename Function , typename std::enable_if<!std::is_base_of< PointFunctorHolder, typename std::decay< Function >::type >::value, int >::type = 0>
 PointFunctorHolder (Function &&fn)
 Constructor. More...
 
Value operator() (Point const &aPoint) const
 Evaluates the functor at the given point. More...
 
void selfDisplay (std::ostream &out) const
 Writes/Displays the object on an output stream. More...
 
constexpr bool isValid () const
 Checks the validity/consistency of the object. More...
 

Private Attributes

Functor myFunctor
 The held functor. More...
 

Detailed Description

template<typename TPoint, typename TValue, typename TFunctor>
class DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >

Aim: hold any object callable on points as a DGtal::concepts::CPointFunctor model.

Template Parameters
TPointPoint type.
TValueValue type returned by the functor.
TFunctorType of the functor.

The functor must accept a point and return a value whose type is Value.

Warning
This class is not meant to be directly constructed by the user. Use instead the holdPointFunctor helper that will choose the more appropriate storage type for the functor depending on the given callable object.

A typical usage would be:

using Point = PointVector<2, int>;
auto fn = holdPointFunctor<Point>( // auto-deduced Value template
[] (Point const& pt) { return pt.norm(); }
);
MyPointD Point
Definition: testClone2.cpp:383

In you want to use a function instead of a functor or lambda, consider wrapping it into a lambda to avoid a performance penalty due to the fact that a pointer to a function cannot be inlined:

using Point = PointVector<2, int>;
auto fn = holdPointFunctor<Point>( // auto-deduced Value template
[] (Point const& pt) { return my_function(pt); }
);

You can find more informations about how to use this class appropriately in the module about Using functions, functors and lambdas in DGtal.

See also
holdPointFunctor, FunctorHolder, Using functions, functors and lambdas in DGtal

Definition at line 95 of file PointFunctorHolder.h.

Member Typedef Documentation

◆ Functor

template<typename TPoint , typename TValue , typename TFunctor >
using DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::Functor = TFunctor

Definition at line 104 of file PointFunctorHolder.h.

◆ Point

template<typename TPoint , typename TValue , typename TFunctor >
using DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::Point = TPoint

Definition at line 102 of file PointFunctorHolder.h.

◆ Self

template<typename TPoint , typename TValue , typename TFunctor >
using DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::Self = PointFunctorHolder<TPoint, TValue, TFunctor>

Definition at line 101 of file PointFunctorHolder.h.

◆ Value

template<typename TPoint , typename TValue , typename TFunctor >
using DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::Value = TValue

Definition at line 103 of file PointFunctorHolder.h.

Constructor & Destructor Documentation

◆ PointFunctorHolder()

template<typename TPoint , typename TValue , typename TFunctor >
template<typename Function , typename std::enable_if<!std::is_base_of< PointFunctorHolder, typename std::decay< Function >::type >::value, int >::type = 0>
DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::PointFunctorHolder ( Function &&  fn)
inlineexplicit

Constructor.

Template Parameters
FunctionThe type of the callable object (auto-deduced).
Parameters
fnThe callable object.

Definition at line 119 of file PointFunctorHolder.h.

120  : myFunctor(std::forward<Function>(fn))
121  {
122  }

Member Function Documentation

◆ isValid()

template<typename TPoint , typename TValue , typename TFunctor >
constexpr bool DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::isValid ( ) const
inlineconstexpr

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Definition at line 152 of file PointFunctorHolder.h.

153  {
154  return true;
155  }

◆ operator()()

template<typename TPoint , typename TValue , typename TFunctor >
Value DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::operator() ( Point const &  aPoint) const
inline

Evaluates the functor at the given point.

Parameters
aPointThe point.

Definition at line 132 of file PointFunctorHolder.h.

133  {
134  return myFunctor( aPoint );
135  }
const Point aPoint(3, 4)

References aPoint(), and DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::myFunctor.

◆ selfDisplay()

template<typename TPoint , typename TValue , typename TFunctor >
void DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Definition at line 142 of file PointFunctorHolder.h.

143  {
144  out << "[PointFunctorHolder] holding a " << myFunctor;
145  }

References DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::myFunctor.

Field Documentation

◆ myFunctor

template<typename TPoint , typename TValue , typename TFunctor >
Functor DGtal::functors::PointFunctorHolder< TPoint, TValue, TFunctor >::myFunctor
private

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