Add cast operators to hb_array_t

This commit is contained in:
Behdad Esfahbod 2018-11-02 11:51:21 -04:00
parent 72462eb765
commit c6ef5dbd5c
1 changed files with 13 additions and 8 deletions

View File

@ -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;
};