[serializer] Accept pointer & reference in more methods
This commit is contained in:
parent
839618de3b
commit
5c0f62adc9
|
@ -324,14 +324,11 @@ struct hb_serialize_context_t
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
Type *start_embed (const Type &_ HB_UNUSED) const
|
Type *start_embed (const Type *obj HB_UNUSED = nullptr) const
|
||||||
{ return start_embed<Type> (); }
|
{ return reinterpret_cast<Type *> (this->head); }
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
Type *start_embed (const Type *_ HB_UNUSED = nullptr) const
|
Type *start_embed (const Type &obj) const
|
||||||
{
|
{ return start_embed (hb_addressof (obj)); }
|
||||||
Type *ret = reinterpret_cast<Type *> (this->head);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Following two functions exist to allow setting breakpoint on. */
|
/* Following two functions exist to allow setting breakpoint on. */
|
||||||
void err_ran_out_of_room () { this->ran_out_of_room = true; }
|
void err_ran_out_of_room () { this->ran_out_of_room = true; }
|
||||||
|
@ -391,25 +388,37 @@ struct hb_serialize_context_t
|
||||||
template <typename Type, typename ...Ts>
|
template <typename Type, typename ...Ts>
|
||||||
Type *copy (const Type &src, Ts &&...ds)
|
Type *copy (const Type &src, Ts &&...ds)
|
||||||
{ return _copy (src, hb_prioritize, hb_forward<Ts> (ds)...); }
|
{ return _copy (src, hb_prioritize, hb_forward<Ts> (ds)...); }
|
||||||
|
template <typename Type, typename ...Ts>
|
||||||
|
Type *copy (const Type *src, Ts &&...ds)
|
||||||
|
{ return copy (*src, hb_forward<Ts> (ds)...); }
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; }
|
hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; }
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
Type *extend_size (Type &obj, unsigned int size)
|
Type *extend_size (Type *obj, unsigned int size)
|
||||||
{
|
{
|
||||||
assert (this->start <= (char *) &obj);
|
assert (this->start <= (char *) obj);
|
||||||
assert ((char *) &obj <= this->head);
|
assert ((char *) obj <= this->head);
|
||||||
assert ((char *) &obj + size >= this->head);
|
assert ((char *) obj + size >= this->head);
|
||||||
if (unlikely (!this->allocate_size<Type> (((char *) &obj) + size - this->head))) return nullptr;
|
if (unlikely (!this->allocate_size<Type> (((char *) obj) + size - this->head))) return nullptr;
|
||||||
return reinterpret_cast<Type *> (&obj);
|
return reinterpret_cast<Type *> (obj);
|
||||||
}
|
}
|
||||||
|
template <typename Type>
|
||||||
|
Type *extend_size (Type &obj, unsigned int size)
|
||||||
|
{ return extend_size (hb_addressof (obj), size); }
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
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 <typename Type>
|
||||||
|
Type *extend_min (Type &obj) { return extend_min (hb_addressof (obj)); }
|
||||||
|
|
||||||
template <typename Type, typename ...Ts>
|
template <typename Type, typename ...Ts>
|
||||||
Type *extend (Type &obj, Ts &&...ds) { return extend_size (obj, obj.get_size (hb_forward<Ts> (ds)...)); }
|
Type *extend (Type *obj, Ts &&...ds)
|
||||||
|
{ return extend_size (obj, obj->get_size (hb_forward<Ts> (ds)...)); }
|
||||||
|
template <typename Type, typename ...Ts>
|
||||||
|
Type *extend (Type &obj, Ts &&...ds)
|
||||||
|
{ return extend (hb_addressof (obj), hb_forward<Ts> (ds)...); }
|
||||||
|
|
||||||
/* Output routines. */
|
/* Output routines. */
|
||||||
hb_bytes_t copy_bytes () const
|
hb_bytes_t copy_bytes () const
|
||||||
|
|
Loading…
Reference in New Issue