Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
26 #ifndef JAU_FUNCTION_HPP_
27 #define JAU_FUNCTION_HPP_
77 template<
typename R,
typename... A>
97 virtual
bool operator==(const
InvocationFunc<R, A...>& rhs) const noexcept = 0;
99 virtual
bool operator!=(const
InvocationFunc<R, A...>& rhs) const noexcept = 0;
104 template<typename R, typename... A>
109 int getType() const noexcept
override {
return 0; }
119 return getType() == rhs.getType();
124 return !( *
this == rhs );
128 return "NullInvocation";
132 template<
typename R,
typename C,
typename... A>
140 : base(_base), member(_member) {
143 int getType() const noexcept
override {
return 1; }
148 return (base->*member)(args...);
156 if(
getType() != rhs.getType() ) {
160 return base == prhs->base && member == prhs->member;
165 return !( *
this == rhs );
174 template<
typename R,
typename... A>
181 : function(_function) {
184 int getType() const noexcept
override {
return 2; }
189 return (*
function)(args...);
197 if(
getType() != rhs.getType() ) {
201 return function == prhs->function;
206 return !( *
this == rhs );
211 return "PlainInvocation "+
to_hexstring( *((
void**)&
function) );
215 template<
typename R,
typename I,
typename... A>
219 R(*
function)(I&, A...);
225 : data(_data),
function(_function), dataIsIdentity(dataIsIdentity_) {
230 : data(std::move(_data)),
function(_function), dataIsIdentity(dataIsIdentity_) {
233 int getType() const noexcept
override {
return 3; }
238 return (*
function)(data, args...);
246 if(
getType() != rhs.getType() ) {
250 return dataIsIdentity == prhs->dataIsIdentity &&
function == prhs->function && ( !dataIsIdentity || data == prhs->data );
255 return !( *
this == rhs );
260 return "CaptureInvocation "+
to_hexstring( *((
void**)&
function) );
264 template<
typename R,
typename... A>
268 std::function<R(A...)>
function;
272 : id(_id),
function(_function) {
275 : id(_id),
function() {
278 int getType() const noexcept
override {
return 10; }
283 return function(args...);
291 if(
getType() != rhs.getType() ) {
295 return id == prhs->id;
300 return !( *
this == rhs );
308 template<
typename R,
typename... A>
325 : func( _funcPtr ) { }
339 {
return *func == *rhs.func; }
342 {
return *func != *rhs.func; }
351 return "FunctionDef["+func->toString()+
"]";
355 return func->invoke(args...);
359 template<
typename R,
typename C,
typename... A>
365 template<
typename R,
typename... A>
378 template<
typename R,
typename I,
typename... A>
380 bindCaptureFunc(
const I& data, R(*func)(I&, A...),
bool dataIsIdentity=
true) noexcept {
390 template<
typename R,
typename I,
typename... A>
396 template<
typename R,
typename... A>
401 template<
typename R,
typename... A>
InvocationFunc< R, A... > * cloneFunction() const noexcept
Returns a new instance of the held InvocationFunc<R, A...> function.
InvocationFunc< R, A... > * clone() const noexcept override
int getType() const noexcept override
NullInvocationFunc() noexcept
jau::FunctionDef< R, A... > bindCaptureFunc(const I &data, R(*func)(I &, A...), bool dataIsIdentity=true) noexcept
const I& data will be copied into the InvocationFunc<..> specialization and hence captured by copy.
std::string toString() const
R invoke(A... args) override
bool operator!=(const InvocationFunc< R, A... > &rhs) const noexcept override
InvocationFunc & operator=(InvocationFunc &&o) noexcept=default
std::string toString() const override
std::string toString() const override
One goal to produce the member-function type instance is to be class type agnostic for storing in the...
std::string toString() const override
std::string toString() const override
R invoke(A... args) override
R invoke(A... args) override
bool operator!=(const InvocationFunc< R, A... > &rhs) const noexcept override
InvocationFunc(const InvocationFunc &o) noexcept=default
CaptureInvocationFunc(I &&_data, R(*_function)(I &, A...), bool dataIsIdentity_) noexcept
Utilizes move-ctor from moved 'I&& _data'.
std::string toString() const override
bool operator!=(const InvocationFunc< R, A... > &rhs) const noexcept override
bool operator!=(const InvocationFunc< R, A... > &rhs) const noexcept override
InvocationFunc< R, A... > * clone() const noexcept override
jau::FunctionDef< R, A... > bindMemberFunc(C *base, R(C::*mfunc)(A...)) noexcept
InvocationFunc< R, A... > * clone() const noexcept override
jau::FunctionDef< R, A... > bindPlainFunc(R(*func)(A...)) noexcept
int getType() const noexcept override
FunctionDef(std::shared_ptr< InvocationFunc< R, A... >> _func) noexcept
Constructs an instance using the shared InvocationFunc<R, A...> function.
bool operator==(const InvocationFunc< R, A... > &rhs) const noexcept override
StdInvocationFunc(uint64_t _id) noexcept
jau::FunctionDef< R, A... > bindStdFunc(uint64_t id, std::function< R(A...)> func) noexcept
FunctionDef() noexcept
Constructs an instance with a null function.
InvocationFunc< R, A... > * clone() const noexcept override
FunctionDef(FunctionDef &&o) noexcept=default
bool operator==(const InvocationFunc< R, A... > &rhs) const noexcept override
StdInvocationFunc(uint64_t _id, std::function< R(A...)> _function) noexcept
virtual ~InvocationFunc() noexcept
bool operator==(const InvocationFunc< R, A... > &rhs) const noexcept override
bool operator==(const FunctionDef< R, A... > &rhs) const noexcept
std::string to_hexstring(value_type const &v) noexcept
Produce a lower-case hexadecimal string representation of the given pointer.
InvocationFunc(InvocationFunc &&o) noexcept=default
int getType() const noexcept override
virtual int getType() const noexcept=0
Poor man's RTTI.
int getType() const noexcept override
bool operator==(const InvocationFunc< R, A... > &rhs) const noexcept override
InvocationFunc() noexcept
InvocationFunc & operator=(const InvocationFunc &o) noexcept=default
bool operator!=(const InvocationFunc< R, A... > &rhs) const noexcept override
std::shared_ptr< InvocationFunc< R, A... > > getFunction() noexcept
Returns the shared InvocationFunc<R, A...> function.
FunctionDef & operator=(const FunctionDef &o) noexcept=default
FunctionDef(InvocationFunc< R, A... > *_funcPtr) noexcept
Constructs an instance by wrapping the given naked InvocationFunc<R, A...> function pointer in a shar...
FunctionDef(const FunctionDef &o) noexcept=default
virtual InvocationFunc< R, A... > * clone() const noexcept=0
InvocationFunc< R, A... > * clone() const noexcept override
bool operator==(const InvocationFunc< R, A... > &rhs) const noexcept override
CaptureInvocationFunc(const I &_data, R(*_function)(I &, A...), bool dataIsIdentity_) noexcept
Utilizes copy-ctor from 'const I& _data'.
FunctionDef & operator=(FunctionDef &&o) noexcept=default
virtual R invoke(A... args)=0
ClassInvocationFunc(C *_base, R(C::*_member)(A...)) noexcept
virtual std::string toString() const =0
PlainInvocationFunc(R(*_function)(A...)) noexcept
R invoke(A... args) override
bool operator!=(const FunctionDef< R, A... > &rhs) const noexcept
int getType() const noexcept override