OpenLB 1.7
|
Smart pointer for managing the various ways of passing functors around. More...
#include <functorPtr.h>
Public Member Functions | |
FunctorPtr (F &f) | |
Constructor for transparently accepting a functor reference. | |
FunctorPtr (F *f) | |
Constructor for transparently accepting a non-owning functor pointer. | |
FunctorPtr (const std::unique_ptr< F > &f) | |
Constructor for transparently accepting a owning functor pointer. | |
FunctorPtr (std::unique_ptr< F > &&f) | |
Constructor for transparently taking ownership of a owning functor pointer. | |
FunctorPtr (std::shared_ptr< F > f) | |
Constructor for transparently sharing ownership of a functor. | |
FunctorPtr () | |
Constructor for an empty instance. | |
FunctorPtr (FunctorPtr &)=delete | |
Copy construction is disabled as it is incompatible with unique ownership. | |
FunctorPtr (FunctorPtr &&)=default | |
Move constructor. | |
template<typename... Args> | |
bool | operator() (Args... args) |
Perfect forwarding functor operator. | |
std::add_lvalue_reference< F >::type | operator* () const |
std::add_pointer< F >::type | operator-> () const noexcept |
Enable pointer-like access to the exposed functor's members. | |
operator bool () const | |
Indicates whether a functor instance is exposed. | |
bool | isOwning () const |
Indicates whether a functor instance is both exposed and owned. | |
template<typename G = F> | |
auto | toShared () -> typename std::enable_if< util::has_identity_functor< G >::value, std::shared_ptr< F > >::type |
Lifts managed functor reference for usage in std::shared_ptr<F> arithmetic. | |
template<typename G = F> | |
auto | toShared () -> typename std::enable_if<!util::has_identity_functor< G >::value, std::shared_ptr< F > >::type |
Lifts managed functor reference for usage in std::shared_ptr<F> arithmetic (limited) | |
Smart pointer for managing the various ways of passing functors around.
There is a rich set of functors that compose other functors by accepting them as constructor arguments. e.g. SuperLpNorm3D, SuperPlaneIntegralF3D
Previously all of these functors only accepted other functors by reference which prevented e.g. the use case of accepting a std::unique_ptr to a indicator freshly created by SuperGeometry3D::getMaterialIndicator.
This class hides the memory management required to support accepting either functor references, non-owning pointers or owning pointers in a single argument.
Note that if this class is constructed by reference or raw pointer the caller is responsible for assuring that the passed functor is available for the full lifetime. This is not the case when constructed by a smart pointer.
Definition at line 60 of file functorPtr.h.
olb::FunctorPtr< F >::FunctorPtr | ( | F & | f | ) |
Constructor for transparently accepting a functor reference.
Definition at line 34 of file functorPtr.hh.
olb::FunctorPtr< F >::FunctorPtr | ( | F * | f | ) |
Constructor for transparently accepting a non-owning functor pointer.
Definition at line 42 of file functorPtr.hh.
olb::FunctorPtr< F >::FunctorPtr | ( | const std::unique_ptr< F > & | f | ) |
Constructor for transparently accepting a owning functor pointer.
Equivalent to construction using a non-owning functor pointer
Definition at line 50 of file functorPtr.hh.
olb::FunctorPtr< F >::FunctorPtr | ( | std::unique_ptr< F > && | f | ) |
Constructor for transparently taking ownership of a owning functor pointer.
Definition at line 55 of file functorPtr.hh.
olb::FunctorPtr< F >::FunctorPtr | ( | std::shared_ptr< F > | f | ) |
Constructor for transparently sharing ownership of a functor.
Definition at line 62 of file functorPtr.hh.
olb::FunctorPtr< F >::FunctorPtr | ( | ) |
Constructor for an empty instance.
Equivalent to construction by nullptr.
Definition at line 69 of file functorPtr.hh.
|
delete |
Copy construction is disabled as it is incompatible with unique ownership.
|
default |
Move constructor.
bool olb::FunctorPtr< F >::isOwning | ( | ) | const |
Indicates whether a functor instance is both exposed and owned.
It is not enough to check _ownF and _sharedF for non-nullptr contents as _sharedF is also used to store F::identity_functor_type instances created by toShared.
Definition at line 92 of file functorPtr.hh.
olb::FunctorPtr< F >::operator bool | ( | ) | const |
Indicates whether a functor instance is exposed.
This is useful for supporting optional functors in constructor interfaces by constructing FunctorPtr using a nullptr
Definition at line 86 of file functorPtr.hh.
|
inline |
Perfect forwarding functor operator.
Definition at line 98 of file functorPtr.h.
std::add_lvalue_reference< F >::type olb::FunctorPtr< F >::operator* | ( | ) | const |
Definition at line 74 of file functorPtr.hh.
|
noexcept |
Enable pointer-like access to the exposed functor's members.
Definition at line 80 of file functorPtr.hh.
auto olb::FunctorPtr< F >::toShared | ( | ) | -> typename std::enable_if< util::has_identity_functor<G>::value, std::shared_ptr<F>>::type |
Lifts managed functor reference for usage in std::shared_ptr<F> arithmetic.
Definition at line 99 of file functorPtr.hh.
auto olb::FunctorPtr< F >::toShared | ( | ) | -> typename std::enable_if<!util::has_identity_functor< G >::value, std::shared_ptr< F > >::type |
Lifts managed functor reference for usage in std::shared_ptr<F> arithmetic (limited)