DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
PointFunctorHolder.h
1
16
17
#pragma once
18
28
29
#if defined(PointFunctorHolder_RECURSES)
30
#error Recursive header files inclusion detected in PointFunctorHolder.h
31
#else
// defined(PointFunctorHolder_RECURSES)
33
#define PointFunctorHolder_RECURSES
34
35
#if !defined PointFunctorHolder_h
37
#define PointFunctorHolder_h
38
40
// Inclusions
41
#include <iostream>
42
#include <type_traits>
43
#include <utility>
44
45
#include "DGtal/base/FunctorHolder.h"
47
48
namespace
DGtal
49
{
50
namespace
functors
51
{
52
90
template
<
91
typename
TPoint,
92
typename
TValue,
93
typename
TFunctor
94
>
95
class
PointFunctorHolder
96
{
97
// ----------------------- Interface --------------------------------------
98
public
:
99
100
// DGtal types
101
using
Self
=
PointFunctorHolder<TPoint, TValue, TFunctor>
;
102
using
Point
= TPoint;
103
using
Value
= TValue;
104
using
Functor
= TFunctor;
105
106
// ----------------------- Standard services ------------------------------
107
public
:
108
114
template
<
115
typename
Function,
116
// SFINAE trick to disable this constructor in a copy/move construction context.
117
typename
std::enable_if<!std::is_base_of<PointFunctorHolder, typename std::decay<Function>::type>::value,
int
>::type = 0
118
>
119
explicit
PointFunctorHolder
(Function && fn)
120
:
myFunctor
(
std
::forward<Function>(fn))
121
{
122
}
123
124
// ----------------------- Interface --------------------------------------
125
public
:
126
131
inline
132
Value
operator()
(
Point
const
&
aPoint
)
const
133
{
134
return
myFunctor
(
aPoint
);
135
}
136
141
inline
142
void
selfDisplay
( std::ostream & out )
const
143
{
144
out <<
"[PointFunctorHolder] holding a "
<<
myFunctor
;
145
}
146
151
inline
constexpr
152
bool
isValid
()
const
153
{
154
return
true
;
155
}
156
157
158
// ------------------------- Private Data --------------------------------
159
private
:
160
Functor
myFunctor
;
161
162
};
// End of class PointFunctorHolder
163
164
171
template
<
typename
TPo
int
,
typename
TValue,
typename
TFunctor>
172
std::ostream&
173
operator<<
( std::ostream & out,
const
PointFunctorHolder<TPoint, TValue, TFunctor>
&
object
)
174
{
175
object
.selfDisplay(out);
176
return
out;
177
}
178
179
190
template
<
191
typename
TPoint,
192
typename
TValue,
193
typename
TFunctor
194
>
195
inline
auto
196
holdPointFunctor
( TFunctor && aFunctor )
197
->
PointFunctorHolder<TPoint, TValue, decltype(holdFunctor(std::forward<TFunctor>
(aFunctor)))>
198
{
199
return
PointFunctorHolder<TPoint, TValue, decltype(holdFunctor(std::forward<TFunctor>
(aFunctor)))>{
200
holdFunctor
(std::forward<TFunctor>(aFunctor))
201
};
202
}
203
213
template
<
214
typename
TPoint,
215
typename
TFunctor
216
>
217
inline
auto
218
holdPointFunctor
( TFunctor && aFunctor )
219
->
PointFunctorHolder
<
220
TPoint,
221
typename
std::decay<decltype(aFunctor(std::declval<TPoint>()))>::type,
222
decltype
(
holdFunctor
(std::forward<TFunctor>(aFunctor)))
223
>
224
{
225
return
PointFunctorHolder
<
226
TPoint,
227
typename
std::decay<decltype(aFunctor(std::declval<TPoint>()))>::type,
228
decltype
(
holdFunctor
(std::forward<TFunctor>(aFunctor)))
229
>{
holdFunctor
(std::forward<TFunctor>(aFunctor)) };
230
}
231
232
}
// namespace functors
233
}
// namespace DGtal
234
235
#endif
// !defined PointFunctorHolder_h
236
237
#undef PointFunctorHolder_RECURSES
238
#endif
// else defined(PointFunctorHolder_RECURSES)
DGtal::functors::PointFunctorHolder
Aim: hold any object callable on points as a DGtal::concepts::CPointFunctor model.
Definition
PointFunctorHolder.h:96
DGtal::functors::PointFunctorHolder::Functor
TFunctor Functor
Definition
PointFunctorHolder.h:104
DGtal::functors::PointFunctorHolder::Point
TPoint Point
Definition
PointFunctorHolder.h:102
DGtal::functors::PointFunctorHolder::selfDisplay
void selfDisplay(std::ostream &out) const
Writes/Displays the object on an output stream.
Definition
PointFunctorHolder.h:142
DGtal::functors::PointFunctorHolder::isValid
constexpr bool isValid() const
Checks the validity/consistency of the object.
Definition
PointFunctorHolder.h:152
DGtal::functors::PointFunctorHolder::Value
TValue Value
Definition
PointFunctorHolder.h:103
DGtal::functors::PointFunctorHolder::PointFunctorHolder
PointFunctorHolder(Function &&fn)
Constructor.
Definition
PointFunctorHolder.h:119
DGtal::functors::PointFunctorHolder::operator()
Value operator()(Point const &aPoint) const
Evaluates the functor at the given point.
Definition
PointFunctorHolder.h:132
DGtal::functors::PointFunctorHolder::Self
PointFunctorHolder< TPoint, TValue, TFunctor > Self
Definition
PointFunctorHolder.h:101
DGtal::functors::PointFunctorHolder::myFunctor
Functor myFunctor
The held functor.
Definition
PointFunctorHolder.h:160
DGtal::functors
functors namespace gathers all DGtal functors.
Definition
BasicBoolFunctors.h:49
DGtal::functors::operator<<
std::ostream & operator<<(std::ostream &out, const FunctorHolder< FunctorStorage, NeedDereference > &object)
Overloads 'operator<<' for displaying objects of class FunctorHolder.
Definition
FunctorHolder.h:239
DGtal::functors::holdPointFunctor
auto holdPointFunctor(TFunctor &&aFunctor) -> PointFunctorHolder< TPoint, TValue, decltype(holdFunctor(std::forward< TFunctor >(aFunctor)))>
PointFunctorHolder construction helper with specification of the return type.
Definition
PointFunctorHolder.h:196
DGtal::functors::holdFunctor
auto holdFunctor(Function &&fn) -> decltype(holdFunctorImpl(std::forward< Function >(fn), typename std::is_lvalue_reference< Function >{}))
Hold any callable object (function, functor, lambda, ...) as a C(Unary)Functor model.
Definition
FunctorHolder.h:279
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
std
STL namespace.
aPoint
const Point aPoint(3, 4)
src
DGtal
kernel
PointFunctorHolder.h
Generated on
for DGtal by
1.18.0