bsnes-libretro/nall/range.hpp
Tim Allen 3159285eaa Update to v106r68 release.
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.
2018-12-22 21:28:15 +11:00

52 lines
1.5 KiB
C++

#pragma once
namespace nall {
struct range_t {
struct iterator {
iterator(int64_t position, int64_t step = 0) : position(position), step(step) {}
auto operator*() const -> int64_t { return position; }
auto operator!=(const iterator& source) const -> bool { return step > 0 ? position < source.position : position > source.position; }
auto operator++() -> iterator& { position += step; return *this; }
private:
int64_t position;
const int64_t step;
};
struct reverse_iterator {
reverse_iterator(int64_t position, int64_t step = 0) : position(position), step(step) {}
auto operator*() const -> int64_t { return position; }
auto operator!=(const reverse_iterator& source) const -> bool { return step > 0 ? position > source.position : position < source.position; }
auto operator++() -> reverse_iterator& { position -= step; return *this; }
private:
int64_t position;
const int64_t step;
};
auto begin() const -> iterator { return {origin, stride}; }
auto end() const -> iterator { return {target}; }
auto rbegin() const -> reverse_iterator { return {target - stride, stride}; }
auto rend() const -> reverse_iterator { return {origin - stride}; }
int64_t origin;
int64_t target;
int64_t stride;
};
inline auto range(int64_t size) {
return range_t{0, size, 1};
}
inline auto range(int64_t offset, int64_t size) {
return range_t{offset, size, 1};
}
inline auto range(int64_t offset, int64_t size, int64_t step) {
return range_t{offset, size, step};
}
}