diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2018-11-02 11:51:21 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-11-02 11:51:21 -0400 |
commit | c6ef5dbd5c40cc8934756456221e080012a82530 (patch) | |
tree | 1eed0d4975d29018e1606d52cf053130e8810add | |
parent | 72462eb76584a2892f1d961c90fd289240ea9380 (diff) |
Add cast operators to hb_array_t
-rw-r--r-- | src/hb-dsalgs.hh | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 0940dc53..2249e128 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -539,19 +539,24 @@ struct hb_bytes_t unsigned int len; }; -template <typename T> +template <typename Type> struct hb_array_t { inline hb_array_t (void) : arrayZ (nullptr), len (0) {} - inline hb_array_t (T *array_, unsigned int len_) : arrayZ (array_), len (len_) {} + inline hb_array_t (Type *array_, unsigned int len_) : arrayZ (array_), len (len_) {} - inline T& operator [] (unsigned int i) const + inline Type& operator [] (unsigned int i) const { - if (unlikely (i >= len)) return Null(T); + if (unlikely (i >= len)) return Null(Type); return arrayZ[i]; } - inline hb_array_t<T> sub_array (unsigned int start_offset, unsigned int seg_count) const + inline unsigned int get_size (void) { return len * sizeof (Type); } + + template <typename T> inline operator T * (void) { return arrayZ; } + template <typename T> inline operator const T * (void) const { return arrayZ; } + + inline hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int seg_count) const { unsigned int count = len; if (unlikely (start_offset > count)) @@ -559,17 +564,17 @@ struct hb_array_t else count -= start_offset; count = MIN (count, seg_count); - return hb_array_t<T> (arrayZ + start_offset, count); + return hb_array_t<Type> (arrayZ + start_offset, count); } inline hb_bytes_t as_bytes (void) const { - return hb_bytes_t (arrayZ, len * sizeof (T)); + return hb_bytes_t (arrayZ, len * sizeof (Type)); } inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } - T *arrayZ; + Type *arrayZ; unsigned int len; }; |