提交 4d4fd64f 编写于 作者: B Behdad Esfahbod

Allow non-nullable OffsetTo<> to non-Null'able objects

上级 fa9f585e
......@@ -231,17 +231,31 @@ struct FixedVersion
* Use: (base+offset)
*/
template <typename Type, bool has_null>
struct _hb_has_null
{
static inline const Type *get_null (void) { return nullptr; }
static inline Type *get_crap (void) { return nullptr; }
};
template <typename Type>
struct _hb_has_null<Type, true>
{
static inline const Type *get_null (void) { return &Null(Type); }
static inline Type *get_crap (void) { return &Crap(Type); }
};
template <typename Type, typename OffsetType=HBUINT16, bool has_null=true>
struct OffsetTo : Offset<OffsetType, has_null>
{
inline const Type& operator () (const void *base) const
{
if (unlikely (this->is_null ())) return Null (Type);
if (unlikely (this->is_null ())) return *_hb_has_null<Type, has_null>::get_null ();
return StructAtOffset<const Type> (base, *this);
}
inline Type& operator () (void *base) const
{
if (unlikely (this->is_null ())) return Crap (Type);
if (unlikely (this->is_null ())) return *_hb_has_null<Type, has_null>::get_crap ();
return StructAtOffset<Type> (base, *this);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册