template <typename Context, typename Return, unsigned int MaxDebugDepth>
struct hb_dispatch_context_t
{
+ private:
+ /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
+ const Context* thiz () const { return static_cast<const Context *> (this); }
+ Context* thiz () { return static_cast< Context *> (this); }
+ public:
static constexpr unsigned max_debug_depth = MaxDebugDepth;
typedef Return return_t;
template <typename T, typename F>
bool may_dispatch (const T *obj HB_UNUSED, const F *format HB_UNUSED) { return true; }
+ template <typename T>
+ return_t dispatch (const T &obj) { return _dispatch_impl (obj, hb_prioritize); }
static return_t no_dispatch_return_value () { return Context::default_return_value (); }
static bool stop_sublookup_iteration (const return_t r HB_UNUSED) { return false; }
+
+ private:
+ template <typename T>
+ auto _dispatch_impl (const T &obj, hb_priority<1>) HB_AUTO_RETURN (obj.dispatch (thiz ()))
+ template <typename T>
+ Return _dispatch_impl (const T &obj, hb_priority<0>) { return thiz()->_dispatch (obj); }
};
{
const char *get_name () { return "INTERSECTS"; }
template <typename T>
- return_t dispatch (const T &obj) { return obj.intersects (this->glyphs); }
+ return_t _dispatch (const T &obj) { return obj.intersects (this->glyphs); }
static return_t default_return_value () { return false; }
bool stop_sublookup_iteration (return_t r) const { return r; }
const char *get_name () { return "CLOSURE"; }
typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index);
template <typename T>
- return_t dispatch (const T &obj) { obj.closure (this); return hb_void_t (); }
+ return_t _dispatch (const T &obj) { obj.closure (this); return hb_void_t (); }
static return_t default_return_value () { return hb_void_t (); }
void recurse (unsigned int lookup_index)
{
{
const char *get_name () { return "WOULD_APPLY"; }
template <typename T>
- return_t dispatch (const T &obj) { return obj.would_apply (this); }
+ return_t _dispatch (const T &obj) { return obj.would_apply (this); }
static return_t default_return_value () { return false; }
bool stop_sublookup_iteration (return_t r) const { return r; }
const char *get_name () { return "COLLECT_GLYPHS"; }
typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index);
template <typename T>
- return_t dispatch (const T &obj) { obj.collect_glyphs (this); return hb_void_t (); }
+ return_t _dispatch (const T &obj) { obj.collect_glyphs (this); return hb_void_t (); }
static return_t default_return_value () { return hb_void_t (); }
void recurse (unsigned int lookup_index)
{
const char *get_name () { return "GET_COVERAGE"; }
typedef const Coverage &return_t;
template <typename T>
- return_t dispatch (const T &obj) { return obj.get_coverage (); }
+ return_t _dispatch (const T &obj) { return obj.get_coverage (); }
static return_t default_return_value () { return Null(Coverage); }
bool stop_sublookup_iteration (return_t r) const
{
const char *get_name () { return "APPLY"; }
typedef return_t (*recurse_func_t) (hb_ot_apply_context_t *c, unsigned int lookup_index);
template <typename T>
- return_t dispatch (const T &obj) { return obj.apply (this); }
+ return_t _dispatch (const T &obj) { return obj.apply (this); }
static return_t default_return_value () { return false; }
bool stop_sublookup_iteration (return_t r) const { return r; }
return_t recurse (unsigned int sub_lookup_index)
/* Dispatch interface. */
const char *get_name () { return "GET_SUBTABLES"; }
template <typename T>
- return_t dispatch (const T &obj)
+ return_t _dispatch (const T &obj)
{
hb_applicable_t *entry = array.push();
entry->init (obj, apply_to<T>);