2019-08-16 20:56:07 +01:00
|
|
|
#ifndef ARRAY_SLICE_H
|
|
|
|
#define ARRAY_SLICE_H
|
|
|
|
|
2020-01-15 21:12:10 +00:00
|
|
|
#include "fixed_array.h"
|
2019-08-16 20:56:07 +01:00
|
|
|
#include <core/error_macros.h>
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class ArraySlice {
|
|
|
|
public:
|
2020-01-15 21:12:10 +00:00
|
|
|
inline ArraySlice(T *p_ptr, size_t p_begin, size_t p_end) {
|
2019-08-16 20:56:07 +01:00
|
|
|
CRASH_COND(p_end <= p_begin);
|
|
|
|
_ptr = p_ptr + p_begin;
|
|
|
|
_size = p_end - p_begin;
|
|
|
|
}
|
|
|
|
|
2020-01-15 21:12:10 +00:00
|
|
|
template <unsigned int N>
|
|
|
|
inline ArraySlice(FixedArray<T, N> &a) {
|
|
|
|
_ptr = a.data();
|
|
|
|
_size = a.size();
|
|
|
|
}
|
|
|
|
|
2019-08-16 20:56:07 +01:00
|
|
|
inline T &operator[](size_t i) {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
CRASH_COND(i >= _size)
|
|
|
|
#endif
|
|
|
|
return _ptr[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const T &operator[](size_t i) const {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
CRASH_COND(i >= _size)
|
|
|
|
#endif
|
|
|
|
return _ptr[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t size() const {
|
|
|
|
return _size;
|
|
|
|
}
|
|
|
|
|
2020-01-15 21:12:10 +00:00
|
|
|
inline T *data() {
|
|
|
|
return _ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const T *data() const {
|
|
|
|
return _ptr;
|
|
|
|
}
|
|
|
|
|
2019-08-16 20:56:07 +01:00
|
|
|
private:
|
|
|
|
T *_ptr;
|
|
|
|
size_t _size;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ARRAY_SLICE_H
|