diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 0d908bd139a32823e0e3895bccb889ab8df3a62d..a8fd8d32ed7c9144706651dd209ff8ff35baa4c2 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -358,6 +358,24 @@ struct hb_serialize_context_t memcpy (ret, &obj, size); return ret; } + + template auto + _copy (const Type &obj, hb_priority<1>) const HB_RETURN (Type *, obj.copy (this)) + + template auto + _copy (const Type &obj, hb_priority<0>) const -> decltype (&(obj = obj)) + { + Type *ret = this->allocate_size (sizeof (Type)); + if (unlikely (!ret)) return nullptr; + *ret = obj; + return ret; + } + + /* Like embed, but active: calls obj.operator=() or obj.copy() to transfer data + * instead of memcpy(). */ + template + Type *copy (const Type &obj) { return _copy (obj, hb_prioritize); } + template hb_serialize_context_t &operator << (const Type &obj) { embed (obj); return *this; }