diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2023-02-27 19:48:51 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2023-02-27 19:48:51 -0400 |
commit | 91847f04a552098883541d2c4ab5d0a05120c8f5 (patch) | |
tree | a4866a4e9972c6d0cb816d74f77205351eb1c993 | |
parent | 115fe1992e2c50fd108f7bc7cc31d7d2b1f5c6b8 (diff) |
TArray: Add some extra functions
-rw-r--r-- | context.h | 18 | ||||
-rw-r--r-- | include/pso/TArray.h | 18 |
2 files changed, 36 insertions, 0 deletions
@@ -178,15 +178,33 @@ public: return m_data[i]; }; + T *start() { + return m_data; + }; + + T *end() { + return &m_data[size()-1]; + }; + template<typename T2> T2 *as() { return reinterpret_cast<T2 *>(m_data); }; + template<typename T2> + TArray<T2, (n * sizeof(T))/sizeof(T2)> &to() { + typedef TArray<T2, sizeof(m_data)/sizeof(T2)> to_type; + return reinterpret_cast<to_type &>(*this); + }; + u8 *as_bytes() { return reinterpret_cast<u8 *>(m_data); }; + void fill(u8 val) { + memset(m_data, val, byte_size()); + }; + void fill_with(u8 val) { _fill_with<false>(val); }; diff --git a/include/pso/TArray.h b/include/pso/TArray.h index fb7a903..29dc01e 100644 --- a/include/pso/TArray.h +++ b/include/pso/TArray.h @@ -27,15 +27,33 @@ public: return m_data[i]; }; + T *start() { + return m_data; + }; + + T *end() { + return &m_data[size()-1]; + }; + template<typename T2> T2 *as() { return reinterpret_cast<T2 *>(m_data); }; + template<typename T2> + TArray<T2, (n * sizeof(T))/sizeof(T2)> &to() { + typedef TArray<T2, sizeof(m_data)/sizeof(T2)> to_type; + return reinterpret_cast<to_type &>(*this); + }; + u8 *as_bytes() { return reinterpret_cast<u8 *>(m_data); }; + void fill(u8 val) { + memset(m_data, val, byte_size()); + }; + void fill_with(u8 val) { _fill_with<false>(val); }; |