mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
This represents a major code restructuring. The dot-based and scanline-based renderers are now split into two separate core libraries, asnes and bsnes. For now at least, these are -internal- names. I'm not entirely decided on how I'm going to handle releasing these two separate builds. Regardless, the folders need names. asnes has had all of the processor subfolders collapsed back into their parent folders. In other words, ppu's functions were moved into ppu/sppu, and then ppu was deleted, and then ppu/sppu became the new ppu. Repeat this for the cpu, smp and dsp and there you go. asnes/dsp also removed the DSP_STATE_MACHINE option. This was done for the sake of consistency with the rest of the core. asnes' debugger mode is currently extremely broken, but I will be fixing it in time. And for now, bsnes has kept the processor abstraction layer. I may keep it around, not sure yet. It doesn't hurt speed or anything, so I'm not too worried about making a decision right away. I may throw snesfilter, snesreader and supergameboy into this folder, just to have everything in one place. The alternate GUI forks are definitely going in there as dotnet, cocoa and python. Compiled output goes to the out/ folder now, to prevent conflicts with a file and folder named bsnes, for instance.
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#ifndef NALL_ANY_HPP
|
|
#define NALL_ANY_HPP
|
|
|
|
#include <typeinfo>
|
|
#include <type_traits>
|
|
#include <nall/static.hpp>
|
|
|
|
namespace nall {
|
|
class any {
|
|
public:
|
|
bool empty() const { return container; }
|
|
const std::type_info& type() const { return container ? container->type() : typeid(void); }
|
|
|
|
template<typename T> any& operator=(const T& value_) {
|
|
typedef typename static_if<
|
|
std::is_array<T>::value,
|
|
typename std::remove_extent<typename std::add_const<T>::type>::type*,
|
|
T
|
|
>::type auto_t;
|
|
|
|
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;
|
|
}
|
|
|
|
any() : container(0) {}
|
|
template<typename T> any(const T& value_) : container(0) { operator=(value_); }
|
|
|
|
private:
|
|
struct placeholder {
|
|
virtual const std::type_info& type() const = 0;
|
|
} *container;
|
|
|
|
template<typename T> struct holder : placeholder {
|
|
T value;
|
|
const std::type_info& type() const { return typeid(T); }
|
|
holder(const T& value_) : value(value_) {}
|
|
};
|
|
|
|
template<typename T> friend T any_cast(any&);
|
|
template<typename T> friend T any_cast(const any&);
|
|
template<typename T> friend T* any_cast(any*);
|
|
template<typename T> friend const T* any_cast(const any*);
|
|
};
|
|
|
|
template<typename T> T any_cast(any &value) {
|
|
typedef typename std::remove_reference<T>::type nonref;
|
|
if(value.type() != typeid(nonref)) throw;
|
|
return static_cast<any::holder<nonref>*>(value.container)->value;
|
|
}
|
|
|
|
template<typename T> T any_cast(const any &value) {
|
|
typedef const typename std::remove_reference<T>::type nonref;
|
|
if(value.type() != typeid(nonref)) throw;
|
|
return static_cast<any::holder<nonref>*>(value.container)->value;
|
|
}
|
|
|
|
template<typename T> T* any_cast(any *value) {
|
|
if(!value || value->type() != typeid(T)) return 0;
|
|
return &static_cast<any::holder<T>*>(value->container)->value;
|
|
}
|
|
|
|
template<typename T> const T* any_cast(const any *value) {
|
|
if(!value || value->type() != typeid(T)) return 0;
|
|
return &static_cast<any::holder<T>*>(value->container)->value;
|
|
}
|
|
}
|
|
|
|
#endif
|