mirror of
https://github.com/libretro/bsnes-libretro.git
synced 2024-11-23 08:59:40 +00:00
3159285eaa
byuu says: Changelog: - nall: converted range, iterator, vector to 64-bit - added (very poor) ColecoVision emulation (including Coleco Adam expansion) - added MSX skeleton - added Neo Geo Pocket skeleton - moved audio,video,resource folders into emulator folder - SFC heuristics: BS-X Town cart is "ZBSJ" [hex_usr] The nall change is for future work on things like BPA: I need to be able to handle files larger than 4GB. It is extremely possible that there are still some truncations to 32-bit lurking around, and even more disastrously, possibly some -1s lurking that won't sign-extend to `(uint64_t)0-1`. There's a lot more classes left to do: `string`, `array_view`, `array_span`, etc.
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
#pragma once
|
|
|
|
namespace nall {
|
|
|
|
template<typename T> struct iterator {
|
|
iterator(T* self, uint64_t offset) : self(self), offset(offset) {}
|
|
auto operator*() -> T& { return self[offset]; }
|
|
auto operator!=(const iterator& source) const -> bool { return offset != source.offset; }
|
|
auto operator++() -> iterator& { return offset++, *this; }
|
|
|
|
private:
|
|
T* self;
|
|
uint64_t offset;
|
|
};
|
|
|
|
template<typename T> struct iterator_const {
|
|
iterator_const(const T* self, uint64_t offset) : self(self), offset(offset) {}
|
|
auto operator*() -> const T& { return self[offset]; }
|
|
auto operator!=(const iterator_const& source) const -> bool { return offset != source.offset; }
|
|
auto operator++() -> iterator_const& { return offset++, *this; }
|
|
|
|
private:
|
|
const T* self;
|
|
uint64_t offset;
|
|
};
|
|
|
|
template<typename T> struct reverse_iterator {
|
|
reverse_iterator(T* self, uint64_t offset) : self(self), offset(offset) {}
|
|
auto operator*() -> T& { return self[offset]; }
|
|
auto operator!=(const reverse_iterator& source) const -> bool { return offset != source.offset; }
|
|
auto operator++() -> reverse_iterator& { return offset--, *this; }
|
|
|
|
private:
|
|
T* self;
|
|
uint64_t offset;
|
|
};
|
|
|
|
template<typename T> struct reverse_iterator_const {
|
|
reverse_iterator_const(const T* self, uint64_t offset) : self(self), offset(offset) {}
|
|
auto operator*() -> const T& { return self[offset]; }
|
|
auto operator!=(const reverse_iterator_const& source) const -> bool { return offset != source.offset; }
|
|
auto operator++() -> reverse_iterator_const& { return offset--, *this; }
|
|
|
|
private:
|
|
const T* self;
|
|
uint64_t offset;
|
|
};
|
|
|
|
//std::rbegin(), std::rend() is missing from GCC 4.9; which I still target
|
|
|
|
template<typename T, uint64_t Size> auto rbegin(T (&array)[Size]) { return reverse_iterator<T>{array, Size - 1}; }
|
|
template<typename T, uint64_t Size> auto rend(T (&array)[Size]) { return reverse_iterator<T>{array, (uint64_t)-1}; }
|
|
|
|
template<typename T> auto rbegin(T& self) { return self.rbegin(); }
|
|
template<typename T> auto rend(T& self) { return self.rend(); }
|
|
|
|
template<typename T> struct reverse_wrapper {
|
|
T self;
|
|
|
|
auto begin() { return rbegin(self); }
|
|
auto end() { return rend(self); }
|
|
|
|
auto begin() const { return rbegin(self); }
|
|
auto end() const { return rend(self); }
|
|
};
|
|
|
|
template<typename T> auto reverse(T& object) -> reverse_wrapper<T&> {
|
|
return {object};
|
|
}
|
|
|
|
template<typename T> auto reverse(T&& object) -> reverse_wrapper<T> {
|
|
return {object};
|
|
}
|
|
|
|
}
|