[machinery] Refactor shared code into a macro

This commit is contained in:
Behdad Esfahbod 2022-12-31 12:15:14 -07:00
parent ebb475bae7
commit a0b46f3f6b
1 changed files with 16 additions and 32 deletions

View File

@ -305,38 +305,22 @@ struct hb_table_lazy_loader_t : hb_lazy_loader_t<T,
hb_blob_t* get_blob () const { return this->get_stored (); }
};
template <typename Subclass>
struct hb_font_funcs_lazy_loader_t : hb_lazy_loader_t<hb_font_funcs_t, Subclass>
{
static void destroy (hb_font_funcs_t *p)
{ hb_font_funcs_destroy (p); }
static const hb_font_funcs_t *get_null ()
{ return hb_font_funcs_get_empty (); }
};
template <typename Subclass>
struct hb_unicode_funcs_lazy_loader_t : hb_lazy_loader_t<hb_unicode_funcs_t, Subclass>
{
static void destroy (hb_unicode_funcs_t *p)
{ hb_unicode_funcs_destroy (p); }
static const hb_unicode_funcs_t *get_null ()
{ return hb_unicode_funcs_get_empty (); }
};
template <typename Subclass>
struct hb_draw_funcs_lazy_loader_t : hb_lazy_loader_t<hb_draw_funcs_t, Subclass>
{
static void destroy (hb_draw_funcs_t *p)
{ hb_draw_funcs_destroy (p); }
static const hb_draw_funcs_t *get_null ()
{ return hb_draw_funcs_get_empty (); }
};
template <typename Subclass>
struct hb_paint_funcs_lazy_loader_t : hb_lazy_loader_t<hb_paint_funcs_t, Subclass>
{
static void destroy (hb_paint_funcs_t *p)
{ hb_paint_funcs_destroy (p); }
static const hb_paint_funcs_t *get_null ()
{ return hb_paint_funcs_get_empty (); }
};
#define HB_DEFINE_TYPE_FUNCS_LAZY_LOADER_T(Type) \
template <typename Subclass> \
struct hb_##Type##_funcs_lazy_loader_t : hb_lazy_loader_t<hb_##Type##_funcs_t, Subclass> \
{ \
static void destroy (hb_##Type##_funcs_t *p) \
{ hb_##Type##_funcs_destroy (p); } \
static const hb_##Type##_funcs_t *get_null () \
{ return hb_##Type##_funcs_get_empty (); } \
}
HB_DEFINE_TYPE_FUNCS_LAZY_LOADER_T (font);
HB_DEFINE_TYPE_FUNCS_LAZY_LOADER_T (unicode);
HB_DEFINE_TYPE_FUNCS_LAZY_LOADER_T (draw);
HB_DEFINE_TYPE_FUNCS_LAZY_LOADER_T (paint);
#undef HB_DEFINE_TYPE_FUNCS_LAZY_LOADER_T
#endif /* HB_MACHINERY_HH */