From 5c0f62adc969696b46c1ceb57cd3c2fa408eb94f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 7 May 2019 17:23:46 -0700 Subject: [PATCH] [serializer] Accept pointer & reference in more methods --- src/hb-serialize.hh | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index bb26371..21545a8 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -324,14 +324,11 @@ struct hb_serialize_context_t } template - Type *start_embed (const Type &_ HB_UNUSED) const - { return start_embed (); } + Type *start_embed (const Type *obj HB_UNUSED = nullptr) const + { return reinterpret_cast (this->head); } template - Type *start_embed (const Type *_ HB_UNUSED = nullptr) const - { - Type *ret = reinterpret_cast (this->head); - return ret; - } + Type *start_embed (const Type &obj) const + { return start_embed (hb_addressof (obj)); } /* Following two functions exist to allow setting breakpoint on. */ void err_ran_out_of_room () { this->ran_out_of_room = true; } @@ -391,25 +388,37 @@ struct hb_serialize_context_t template Type *copy (const Type &src, Ts &&...ds) { return _copy (src, hb_prioritize, hb_forward (ds)...); } + template + Type *copy (const Type *src, Ts &&...ds) + { return copy (*src, hb_forward (ds)...); } template hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; } template - Type *extend_size (Type &obj, unsigned int size) + Type *extend_size (Type *obj, unsigned int size) { - assert (this->start <= (char *) &obj); - assert ((char *) &obj <= this->head); - assert ((char *) &obj + size >= this->head); - if (unlikely (!this->allocate_size (((char *) &obj) + size - this->head))) return nullptr; - return reinterpret_cast (&obj); + assert (this->start <= (char *) obj); + assert ((char *) obj <= this->head); + assert ((char *) obj + size >= this->head); + if (unlikely (!this->allocate_size (((char *) obj) + size - this->head))) return nullptr; + return reinterpret_cast (obj); } + template + Type *extend_size (Type &obj, unsigned int size) + { return extend_size (hb_addressof (obj), size); } template - Type *extend_min (Type &obj) { return extend_size (obj, obj.min_size); } + Type *extend_min (Type *obj) { return extend_size (obj, obj->min_size); } + template + Type *extend_min (Type &obj) { return extend_min (hb_addressof (obj)); } template - Type *extend (Type &obj, Ts &&...ds) { return extend_size (obj, obj.get_size (hb_forward (ds)...)); } + Type *extend (Type *obj, Ts &&...ds) + { return extend_size (obj, obj->get_size (hb_forward (ds)...)); } + template + Type *extend (Type &obj, Ts &&...ds) + { return extend (hb_addressof (obj), hb_forward (ds)...); } /* Output routines. */ hb_bytes_t copy_bytes () const -- 2.7.4