Skip to content

Commit

Permalink
From ESP8266 updates to Delegate.h: add assignment operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
dok-net committed Jan 6, 2021
1 parent 1fa01d7 commit adec3fe
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 12 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EspSoftwareSerial",
"version": "6.11.1",
"version": "6.11.2",
"keywords": [
"serial", "io", "softwareserial"
],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EspSoftwareSerial
version=6.11.1
version=6.11.2
author=Dirk Kaar, Peter Lerup
maintainer=Dirk Kaar <dok@dok-net.net>
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.
Expand Down
146 changes: 136 additions & 10 deletions src/circular_queue/Delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ namespace delegate
return *this;
}

template<typename F> DelegatePImpl& operator=(F functional)
{
if (FUNC == kind)
{
this->functional.~FunctionType();
}
else if (FPA == kind)
{
obj.~A();
}
kind = FUNC;
new (&this->functional) FunctionType(std::forward<F>(functional));
return *this;
}

DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
{
if (FUNC == kind)
Expand Down Expand Up @@ -421,10 +436,10 @@ namespace delegate
DelegatePImpl::fn = fn;
}

template<typename F> DelegatePImpl(F fn)
template<typename F> DelegatePImpl(F functional)
{
kind = FP;
DelegatePImpl::fn = std::forward<F>(fn);
fn = std::forward<F>(functional);
}

DelegatePImpl& operator=(const DelegatePImpl& del)
Expand Down Expand Up @@ -484,6 +499,16 @@ namespace delegate
return *this;
}

template<typename F> DelegatePImpl& operator=(F functional)
{
if (FPA == kind)
{
obj = {};
}
kind = FP;
fn = std::forward<F>(functional);
}

DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
{
if (FPA == kind)
Expand Down Expand Up @@ -683,6 +708,17 @@ namespace delegate
return *this;
}

template<typename F> DelegatePImpl& operator=(F functional)
{
if (FUNC == kind)
{
this->functional.~FunctionType();
}
kind = FUNC;
new (&this->functional) FunctionType(std::forward<F>(functional));
return *this;
}

DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
{
if (FUNC == kind)
Expand Down Expand Up @@ -823,6 +859,12 @@ namespace delegate
return *this;
}

template<typename F> DelegatePImpl& operator=(F functional)
{
fn = std::forward<F>(functional);
return *this;
}

DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
{
fn = nullptr;
Expand Down Expand Up @@ -1040,6 +1082,21 @@ namespace delegate
return *this;
}

template<typename F> DelegateImpl& operator=(F functional)
{
if (FUNC == kind)
{
this->functional.~FunctionType();
}
else if (FPA == kind)
{
obj.~A();
}
kind = FUNC;
new (&this->functional) FunctionType(std::forward<F>(functional));
return *this;
}

DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
{
if (FUNC == kind)
Expand Down Expand Up @@ -1284,6 +1341,17 @@ namespace delegate
return *this;
}

template<typename F> DelegateImpl& operator=(F functional)
{
if (FPA == kind)
{
obj.~A();
}
kind = FP;
fn = std::forward<F>(functional);
return *this;
}

DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
{
if (FPA == kind)
Expand Down Expand Up @@ -1482,6 +1550,17 @@ namespace delegate
return *this;
}

template<typename F> DelegateImpl& operator=(F functional)
{
if (FUNC == kind)
{
this->functional.~FunctionType();
}
kind = FUNC;
new (&this->functional) FunctionType(std::forward<F>(functional));
return *this;
}

DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
{
if (FUNC == kind)
Expand Down Expand Up @@ -1622,6 +1701,12 @@ namespace delegate
return *this;
}

template<typename F> DelegateImpl& operator=(F functional)
{
fn = std::forward<F>(functional);
return *this;
}

DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
{
fn = nullptr;
Expand Down Expand Up @@ -1691,7 +1776,7 @@ namespace delegate

Delegate(FunPtr fn) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(fn) {}

template<typename F> Delegate(F functional) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(functional) {}
template<typename F> Delegate(F functional) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
detail::DelegatePImpl<A, R, P...>::operator=(del);
Expand All @@ -1708,6 +1793,11 @@ namespace delegate
return *this;
}

template<typename F> Delegate& operator=(F functional) {
detail::DelegatePImpl<A, R, P...>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
detail::DelegatePImpl<A, R, P...>::operator=(nullptr);
return *this;
Expand Down Expand Up @@ -1770,7 +1860,7 @@ namespace delegate

Delegate(FunPtr fn) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(fn) {}

template<typename F> Delegate(F functional) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(functional) {}
template<typename F> Delegate(F functional) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
detail::DelegatePImpl<A*, R, P...>::operator=(del);
Expand All @@ -1787,6 +1877,11 @@ namespace delegate
return *this;
}

template<typename F> Delegate& operator=(F functional) {
detail::DelegatePImpl<A*, R, P...>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
detail::DelegatePImpl<A*, R, P...>::operator=(nullptr);
return *this;
Expand Down Expand Up @@ -1826,7 +1921,7 @@ namespace delegate

Delegate(FunPtr fn) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(fn) {}

template<typename F> Delegate(F functional) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(functional) {}
template<typename F> Delegate(F functional) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
detail::DelegatePImpl<void, R, P...>::operator=(del);
Expand All @@ -1843,6 +1938,11 @@ namespace delegate
return *this;
}

template<typename F> Delegate& operator=(F functional) {
detail::DelegatePImpl<void, R, P...>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
detail::DelegatePImpl<void, R, P...>::operator=(nullptr);
return *this;
Expand Down Expand Up @@ -1887,7 +1987,7 @@ namespace delegate

Delegate(FunPtr fn) : detail::DelegateImpl<A, R>::DelegateImpl(fn) {}

template<typename F> Delegate(F functional) : detail::DelegateImpl<A, R>::DelegateImpl(functional) {}
template<typename F> Delegate(F functional) : detail::DelegateImpl<A, R>::DelegateImpl(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
detail::DelegateImpl<A, R>::operator=(del);
Expand All @@ -1904,6 +2004,11 @@ namespace delegate
return *this;
}

template<typename F> Delegate& operator=(F functional) {
detail::DelegateImpl<A, R>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
detail::DelegateImpl<A, R>::operator=(nullptr);
return *this;
Expand Down Expand Up @@ -1966,7 +2071,7 @@ namespace delegate

Delegate(FunPtr fn) : detail::DelegateImpl<A*, R>::DelegateImpl(fn) {}

template<typename F> Delegate(F functional) : detail::DelegateImpl<A*, R>::DelegateImpl(functional) {}
template<typename F> Delegate(F functional) : detail::DelegateImpl<A*, R>::DelegateImpl(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
detail::DelegateImpl<A*, R>::operator=(del);
Expand All @@ -1983,6 +2088,11 @@ namespace delegate
return *this;
}

template<typename F> Delegate& operator=(F functional) {
detail::DelegateImpl<A*, R>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
detail::DelegateImpl<A*, R>::operator=(nullptr);
return *this;
Expand Down Expand Up @@ -2022,7 +2132,7 @@ namespace delegate

Delegate(FunPtr fn) : detail::DelegateImpl<void, R>::DelegateImpl(fn) {}

template<typename F> Delegate(F functional) : detail::DelegateImpl<void, R>::DelegateImpl(functional) {}
template<typename F> Delegate(F functional) : detail::DelegateImpl<void, R>::DelegateImpl(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
detail::DelegateImpl<void, R>::operator=(del);
Expand All @@ -2039,6 +2149,11 @@ namespace delegate
return *this;
}

template<typename F> Delegate& operator=(F functional) {
detail::DelegateImpl<void, R>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
detail::DelegateImpl<void, R>::operator=(nullptr);
return *this;
Expand Down Expand Up @@ -2067,7 +2182,7 @@ template<typename A, typename R, typename... P> class Delegate<R(P...), A> : pub

Delegate(typename delegate::detail::Delegate<A, R, P...>::FunPtr fn) : delegate::detail::Delegate<A, R, P...>::Delegate(fn) {}

template<typename F> Delegate(F functional) : delegate::detail::Delegate<A, R, P...>::Delegate(functional) {}
template<typename F> Delegate(F functional) : delegate::detail::Delegate<A, R, P...>::Delegate(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
delegate::detail::Delegate<A, R, P...>::operator=(del);
Expand All @@ -2084,11 +2199,17 @@ template<typename A, typename R, typename... P> class Delegate<R(P...), A> : pub
return *this;
}

template<typename F> Delegate& operator=(F functional) {
delegate::detail::Delegate<A, R, P...>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
delegate::detail::Delegate<A, R, P...>::operator=(nullptr);
return *this;
}
};

template<typename R, typename... P> class Delegate<R(P...)> : public delegate::detail::Delegate<void, R, P...>
{
public:
Expand All @@ -2104,7 +2225,7 @@ template<typename R, typename... P> class Delegate<R(P...)> : public delegate::d

Delegate(typename delegate::detail::Delegate<void, R, P...>::FunPtr fn) : delegate::detail::Delegate<void, R, P...>::Delegate(fn) {}

template<typename F> Delegate(F functional) : delegate::detail::Delegate<void, R, P...>::Delegate(functional) {}
template<typename F> Delegate(F functional) : delegate::detail::Delegate<void, R, P...>::Delegate(std::forward<F>(functional)) {}

Delegate& operator=(const Delegate& del) {
delegate::detail::Delegate<void, R, P...>::operator=(del);
Expand All @@ -2121,6 +2242,11 @@ template<typename R, typename... P> class Delegate<R(P...)> : public delegate::d
return *this;
}

template<typename F> Delegate& operator=(F functional) {
delegate::detail::Delegate<void, R, P...>::operator=(std::forward<F>(functional));
return *this;
}

Delegate& IRAM_ATTR operator=(std::nullptr_t) {
delegate::detail::Delegate<void, R, P...>::operator=(nullptr);
return *this;
Expand Down

0 comments on commit adec3fe

Please sign in to comment.