Add hb_assign(obj, value)
This commit is contained in:
parent
6124123393
commit
5b70074edf
|
@ -390,7 +390,7 @@ struct hb_sanitize_context_t :
|
|||
{
|
||||
if (this->may_edit (obj, hb_static_size (Type)))
|
||||
{
|
||||
const_cast<Type *> (obj)->set (v);
|
||||
hb_assign (* const_cast<Type *> (obj), v);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -59,7 +59,10 @@ struct hb_null_size
|
|||
{ enum { value = _hb_null_size<T, _hb_bool_type<true> >::value }; };
|
||||
#define hb_null_size(T) hb_null_size<T>::value
|
||||
|
||||
/* This doesn't belong here, but since is copy/paste from above, put it here. */
|
||||
/* These doesn't belong here, but since is copy/paste from above, put it here. */
|
||||
|
||||
/* hb_static_size (T)
|
||||
* Returns T::static_size if T::min_size is defined, or sizeof (T) otherwise. */
|
||||
|
||||
template <typename T, typename B>
|
||||
struct _hb_static_size
|
||||
|
@ -74,6 +77,25 @@ struct hb_static_size
|
|||
#define hb_static_size(T) hb_static_size<T>::value
|
||||
|
||||
|
||||
/* hb_assign (obj, value)
|
||||
* Calls obj.set (value) if obj.min_size is defined and value has different type
|
||||
* from obj, or obj = v otherwise. */
|
||||
|
||||
template <typename T, typename V, typename B>
|
||||
struct _hb_assign
|
||||
{ static inline void value (T &o, const V v) { o = v; } };
|
||||
template <typename T, typename V>
|
||||
struct _hb_assign<T, V, _hb_bool_type<(bool) (1 + (unsigned int) T::min_size)> >
|
||||
{ static inline void value (T &o, const V v) { o.set (v); } };
|
||||
template <typename T>
|
||||
struct _hb_assign<T, T, _hb_bool_type<(bool) (1 + (unsigned int) T::min_size)> >
|
||||
{ static inline void value (T &o, const T v) { o = v; } };
|
||||
|
||||
template <typename T, typename V>
|
||||
static inline void hb_assign (T &o, const V v)
|
||||
{ _hb_assign<T, V, _hb_bool_type<true> >::value (o, v); };
|
||||
|
||||
|
||||
/*
|
||||
* Null()
|
||||
*/
|
||||
|
|
|
@ -553,12 +553,13 @@ struct ArrayOf
|
|||
if (unlikely (!c->extend (*this))) return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
bool serialize (hb_serialize_context_t *c, hb_array_t<const Type> items)
|
||||
template <typename T>
|
||||
bool serialize (hb_serialize_context_t *c, hb_array_t<const T> items)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
if (unlikely (!serialize (c, items.len))) return_trace (false);
|
||||
for (unsigned int i = 0; i < items.len; i++)
|
||||
arrayZ[i] = items[i];
|
||||
hb_assign (arrayZ[i], items[i]);
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue