Add (unused) hb_array_t<>
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 10 Sep 2018 23:07:06 +0000 (01:07 +0200)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 10 Sep 2018 23:09:07 +0000 (01:09 +0200)
src/hb-dsalgs.hh

index 7e06ff1..def968e 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "hb.hh"
 
+#include "hb-null.hh"
+
 
 /* Void! For when we need a expression-type of void. */
 typedef const struct _hb_void_t *hb_void_t;
@@ -507,6 +509,24 @@ struct hb_auto_t : Type
   void fini (void) {}
 };
 
+template <typename T>
+struct hb_array_t
+{
+  inline hb_array_t (void) : arrayZ (nullptr), len (0) {}
+  inline hb_array_t (const T *array_, unsigned int len_) : arrayZ (array_), len (len_) {}
+
+  inline const T& operator [] (unsigned int i) const
+  {
+    if (unlikely (i >= len)) return Null(T);
+    return arrayZ[i];
+  }
+
+  inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; }
+
+  const T *arrayZ;
+  unsigned int len;
+};
+
 struct hb_bytes_t
 {
   inline hb_bytes_t (void) : bytes (nullptr), len (0) {}