mirror of
https://github.com/libretro/bsnes-libretro.git
synced 2024-11-27 02:50:32 +00:00
f3e67da937
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.
84 lines
2.4 KiB
C++
84 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <typeinfo>
|
|
#include <nall/traits.hpp>
|
|
|
|
namespace nall {
|
|
|
|
struct any {
|
|
any() = default;
|
|
any(const any& source) { operator=(source); }
|
|
any(any&& source) { operator=(move(source)); }
|
|
template<typename T> any(const T& value) { operator=(value); }
|
|
~any() { reset(); }
|
|
|
|
explicit operator bool() const { return container; }
|
|
auto reset() -> void { if(container) { delete container; container = nullptr; } }
|
|
|
|
auto type() const -> const std::type_info& {
|
|
return container ? container->type() : typeid(void);
|
|
}
|
|
|
|
template<typename T> auto is() const -> bool {
|
|
return type() == typeid(typename remove_reference<T>::type);
|
|
}
|
|
|
|
template<typename T> auto get() -> T& {
|
|
if(!is<T>()) throw;
|
|
return static_cast<holder<typename remove_reference<T>::type>*>(container)->value;
|
|
}
|
|
|
|
template<typename T> auto get() const -> const T& {
|
|
if(!is<T>()) throw;
|
|
return static_cast<holder<typename remove_reference<T>::type>*>(container)->value;
|
|
}
|
|
|
|
template<typename T> auto get(const T& fallback) const -> const T& {
|
|
if(!is<T>()) return fallback;
|
|
return static_cast<holder<typename remove_reference<T>::type>*>(container)->value;
|
|
}
|
|
|
|
template<typename T> auto operator=(const T& value) -> any& {
|
|
using auto_t = typename conditional<is_array<T>::value, typename remove_extent<typename add_const<T>::type>::type*, T>::type;
|
|
|
|
if(type() == typeid(auto_t)) {
|
|
static_cast<holder<auto_t>*>(container)->value = (auto_t)value;
|
|
} else {
|
|
if(container) delete container;
|
|
container = new holder<auto_t>((auto_t)value);
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
auto operator=(const any& source) -> any& {
|
|
if(container) { delete container; container = nullptr; }
|
|
if(source.container) container = source.container->copy();
|
|
return *this;
|
|
}
|
|
|
|
auto operator=(any&& source) -> any& {
|
|
if(container) delete container;
|
|
container = source.container;
|
|
source.container = nullptr;
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
struct placeholder {
|
|
virtual ~placeholder() = default;
|
|
virtual auto type() const -> const std::type_info& = 0;
|
|
virtual auto copy() const -> placeholder* = 0;
|
|
};
|
|
placeholder* container = nullptr;
|
|
|
|
template<typename T> struct holder : placeholder {
|
|
holder(const T& value) : value(value) {}
|
|
auto type() const -> const std::type_info& { return typeid(T); }
|
|
auto copy() const -> placeholder* { return new holder(value); }
|
|
T value;
|
|
};
|
|
};
|
|
|
|
}
|