-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from rmpowell77/dev/generic_proxy
Issue #142: Generic needs a proxy
- Loading branch information
Showing
48 changed files
with
826 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2022 Richard Powell | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <wx/sizer.h> | ||
|
||
namespace wxUI::details { | ||
|
||
// https://stackoverflow.com/questions/27866909/get-function-arity-from-template-parameter | ||
template <typename T> | ||
constexpr bool noarg_callable_impl( | ||
typename std::enable_if<bool(sizeof((std::declval<T>()(), 0)))>::type*) | ||
{ | ||
return true; | ||
} | ||
|
||
template <typename T> | ||
constexpr bool noarg_callable_impl(...) | ||
{ | ||
return false; | ||
} | ||
|
||
template <typename T> | ||
constexpr bool is_noarg_callable() | ||
{ | ||
return noarg_callable_impl<T>(nullptr); | ||
} | ||
|
||
// BindInfo uses type erase to allow any binding for any Event type. | ||
struct BindInfo { | ||
|
||
void bindTo([[maybe_unused]] wxWindow* widget) const | ||
{ | ||
mInfo->bindTo(widget); | ||
} | ||
|
||
template <typename Event, typename Function> | ||
BindInfo([[maybe_unused]] Event event, [[maybe_unused]] Function function) | ||
: mInfo(std::make_unique<BindInfoDetails<Event, Function>>(event, function)) | ||
{ | ||
} | ||
|
||
~BindInfo() = default; | ||
|
||
BindInfo(BindInfo const& bindInfo) | ||
: mInfo(bindInfo.mInfo->clone()) | ||
{ | ||
} | ||
|
||
auto operator=(BindInfo const& bindInfo) -> BindInfo& | ||
{ | ||
if (this == &bindInfo) { | ||
return *this; | ||
} | ||
mInfo = bindInfo.mInfo->clone(); | ||
return *this; | ||
} | ||
|
||
BindInfo(BindInfo&& bindInfo) noexcept | ||
: mInfo(std::move(bindInfo.mInfo)) | ||
{ | ||
} | ||
|
||
auto operator=(BindInfo&& bindInfo) noexcept -> BindInfo& | ||
{ | ||
mInfo = std::move(bindInfo.mInfo); | ||
return *this; | ||
} | ||
|
||
private: | ||
struct BindInfoDetailsBase { | ||
virtual ~BindInfoDetailsBase() = default; | ||
virtual void bindTo(wxWindow* widget) const = 0; | ||
[[nodiscard]] virtual auto clone() const -> std::unique_ptr<BindInfoDetailsBase> = 0; | ||
}; | ||
|
||
template <typename Event, typename Function> | ||
struct BindInfoDetails : BindInfoDetailsBase { | ||
BindInfoDetails(Event event, Function function) | ||
: event(event) | ||
, function(function) | ||
{ | ||
} | ||
Event event; | ||
Function function; | ||
void bindTo(wxWindow* widget) const override | ||
{ | ||
widget->Bind(event, function); | ||
} | ||
[[nodiscard]] auto clone() const -> std::unique_ptr<BindInfoDetailsBase> override | ||
{ | ||
return std::make_unique<BindInfoDetails>(event, function); | ||
} | ||
}; | ||
|
||
std::unique_ptr<BindInfoDetailsBase> mInfo; | ||
}; | ||
|
||
static_assert(std::is_nothrow_move_constructible_v<BindInfo>); | ||
static_assert(std::is_nothrow_move_assignable_v<BindInfo>); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.