mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-25 07:32:28 +01:00
byuu says: Changelog: - added \~130 new PAL games to icarus (courtesy of Smarthuman and aquaman) - added all three Korean-localized games to icarus - sfc: removed SuperDisc emulation (it was going nowhere) - sfc: fixed MSU1 regression where the play/repeat flags were not being cleared on track select - nall: cryptography support added; will be used to sign future databases (validation will always be optional) - minor shims to fix compilation issues due to nall changes The real magic is that we now have 25-30% of the PAL SNES library in icarus! Signing will be tricky. Obviously if I put the public key inside the higan archive, then all anyone has to do is change that public key for their own releases. And if you download from my site (which is now over HTTPS), then you don't need the signing to verify integrity. I may just put the public key on my site on my site and leave it at that, we'll see.
71 lines
2.8 KiB
C++
71 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <nall/traits.hpp>
|
|
|
|
namespace nall {
|
|
|
|
template<typename T> struct function;
|
|
|
|
template<typename R, typename... P> struct function<auto (P...) -> R> {
|
|
//value = true if auto L::operator()(P...) -> R exists
|
|
template<typename L> struct is_compatible {
|
|
template<typename T> static auto exists(T*) -> const typename is_same<R, decltype(declval<T>().operator()(declval<P>()...))>::type;
|
|
template<typename T> static auto exists(...) -> const false_type;
|
|
static constexpr bool value = decltype(exists<L>(0))::value;
|
|
};
|
|
|
|
function() {}
|
|
function(const function& source) { operator=(source); }
|
|
function(void* function) { if(function) callback = new global((auto (*)(P...) -> R)function); }
|
|
function(auto (*function)(P...) -> R) { callback = new global(function); }
|
|
template<typename C> function(auto (C::*function)(P...) -> R, C* object) { callback = new member<C>(function, object); }
|
|
template<typename C> function(auto (C::*function)(P...) const -> R, C* object) { callback = new member<C>((auto (C::*)(P...) -> R)function, object); }
|
|
template<typename L, typename = enable_if_t<is_compatible<L>::value>> function(const L& object) { callback = new lambda<L>(object); }
|
|
~function() { if(callback) delete callback; }
|
|
|
|
explicit operator bool() const { return callback; }
|
|
auto operator()(P... p) const -> R { return (*callback)(forward<P>(p)...); }
|
|
auto reset() -> void { if(callback) { delete callback; callback = nullptr; } }
|
|
|
|
auto operator=(const function& source) -> function& {
|
|
if(this != &source) {
|
|
if(callback) { delete callback; callback = nullptr; }
|
|
if(source.callback) callback = source.callback->copy();
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
struct container {
|
|
virtual auto operator()(P... p) const -> R = 0;
|
|
virtual auto copy() const -> container* = 0;
|
|
virtual ~container() = default;
|
|
};
|
|
|
|
container* callback = nullptr;
|
|
|
|
struct global : container {
|
|
auto (*function)(P...) -> R;
|
|
auto operator()(P... p) const -> R { return function(forward<P>(p)...); }
|
|
auto copy() const -> container* { return new global(function); }
|
|
global(auto (*function)(P...) -> R) : function(function) {}
|
|
};
|
|
|
|
template<typename C> struct member : container {
|
|
auto (C::*function)(P...) -> R;
|
|
C* object;
|
|
auto operator()(P... p) const -> R { return (object->*function)(forward<P>(p)...); }
|
|
auto copy() const -> container* { return new member(function, object); }
|
|
member(auto (C::*function)(P...) -> R, C* object) : function(function), object(object) {}
|
|
};
|
|
|
|
template<typename L> struct lambda : container {
|
|
mutable L object;
|
|
auto operator()(P... p) const -> R { return object(forward<P>(p)...); }
|
|
auto copy() const -> container* { return new lambda(object); }
|
|
lambda(const L& object) : object(object) {}
|
|
};
|
|
};
|
|
|
|
}
|