Add template-function convenience macros
This commit is contained in:
parent
ec83b2228e
commit
f99abcc379
@ -282,7 +282,7 @@ struct hb_atomic_int_t
|
||||
template <typename P>
|
||||
struct hb_atomic_ptr_t
|
||||
{
|
||||
typedef typename hb_remove_pointer<P>::value T;
|
||||
typedef typename hb_remove_pointer (P) T;
|
||||
|
||||
inline void init (T* v_ = nullptr) { set_relaxed (v_); }
|
||||
inline void set_relaxed (T* v_) { hb_atomic_ptr_impl_set_relaxed (&v, v_); }
|
||||
|
@ -60,7 +60,7 @@ struct hb_blob_t
|
||||
template <typename Type>
|
||||
inline const Type* as (void) const
|
||||
{
|
||||
return length < hb_null_size<Type>::value ? &Null(Type) : reinterpret_cast<const Type *> (data);
|
||||
return length < hb_null_size (Type) ? &Null(Type) : reinterpret_cast<const Type *> (data);
|
||||
}
|
||||
inline hb_bytes_t as_bytes (void) const
|
||||
{
|
||||
@ -86,7 +86,7 @@ struct hb_blob_t
|
||||
template <typename P>
|
||||
struct hb_blob_ptr_t
|
||||
{
|
||||
typedef typename hb_remove_pointer<P>::value T;
|
||||
typedef typename hb_remove_pointer (P) T;
|
||||
|
||||
inline hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {}
|
||||
inline hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; }
|
||||
|
@ -784,7 +784,7 @@ parse_uint32 (const char **pp, const char *end, uint32_t *pv)
|
||||
static void free_static_C_locale (void);
|
||||
#endif
|
||||
|
||||
static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<HB_LOCALE_T>::value,
|
||||
static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer (HB_LOCALE_T),
|
||||
hb_C_locale_lazy_loader_t>
|
||||
{
|
||||
static inline HB_LOCALE_T create (void)
|
||||
|
@ -748,7 +748,7 @@ hb_ft_font_create_referenced (FT_Face ft_face)
|
||||
static void free_static_ft_library (void);
|
||||
#endif
|
||||
|
||||
static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<FT_Library>::value,
|
||||
static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer (FT_Library),
|
||||
hb_ft_library_lazy_loader_t>
|
||||
{
|
||||
static inline FT_Library create (void)
|
||||
|
@ -56,6 +56,7 @@ struct _hb_null_size<T, _hb_bool_type<(bool) (1 + (unsigned int) T::min_size)> >
|
||||
template <typename T>
|
||||
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
|
||||
|
||||
extern HB_INTERNAL
|
||||
hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)];
|
||||
@ -63,10 +64,10 @@ hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_
|
||||
/* Generic nul-content Null objects. */
|
||||
template <typename Type>
|
||||
static inline Type const & Null (void) {
|
||||
static_assert (hb_null_size<Type>::value <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE.");
|
||||
static_assert (hb_null_size (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE.");
|
||||
return *reinterpret_cast<Type const *> (_hb_NullPool);
|
||||
}
|
||||
#define Null(Type) Null<typename hb_remove_const<typename hb_remove_reference<Type>::value>::value>()
|
||||
#define Null(Type) Null<typename hb_remove_const (typename hb_remove_reference (Type))> ()
|
||||
|
||||
/* Specializations for arbitrary-content Null objects expressed in bytes. */
|
||||
#define DECLARE_NULL_NAMESPACE_BYTES(Namespace, Type) \
|
||||
@ -104,12 +105,12 @@ extern HB_INTERNAL
|
||||
/* CRAP pool: Common Region for Access Protection. */
|
||||
template <typename Type>
|
||||
static inline Type& Crap (void) {
|
||||
static_assert (hb_null_size<Type>::value <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE.");
|
||||
static_assert (hb_null_size (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE.");
|
||||
Type *obj = reinterpret_cast<Type *> (_hb_CrapPool);
|
||||
memcpy (obj, &Null(Type), sizeof (*obj));
|
||||
return *obj;
|
||||
}
|
||||
#define Crap(Type) Crap<typename hb_remove_const<typename hb_remove_reference<Type>::value>::value>()
|
||||
#define Crap(Type) Crap<typename hb_remove_const (typename hb_remove_reference (Type))> ()
|
||||
|
||||
template <typename Type>
|
||||
struct CrapOrNull {
|
||||
@ -129,7 +130,7 @@ struct CrapOrNull<const Type> {
|
||||
template <typename P>
|
||||
struct hb_nonnull_ptr_t
|
||||
{
|
||||
typedef typename hb_remove_pointer<P>::value T;
|
||||
typedef typename hb_remove_pointer (P) T;
|
||||
|
||||
inline hb_nonnull_ptr_t (T *v_ = nullptr) : v (v_) {}
|
||||
inline T * operator = (T *v_) { return v = v_; }
|
||||
|
@ -508,10 +508,13 @@ _hb_memalign(void **memptr, size_t alignment, size_t size)
|
||||
/* Some really basic things everyone wants. */
|
||||
template <typename T> struct hb_remove_const { typedef T value; };
|
||||
template <typename T> struct hb_remove_const<const T> { typedef T value; };
|
||||
#define hb_remove_const(T) hb_remove_const<T>::value
|
||||
template <typename T> struct hb_remove_reference { typedef T value; };
|
||||
template <typename T> struct hb_remove_reference<T &> { typedef T value; };
|
||||
#define hb_remove_reference(T) hb_remove_reference<T>::value
|
||||
template <typename T> struct hb_remove_pointer { typedef T value; };
|
||||
template <typename T> struct hb_remove_pointer<T *> { typedef T value; };
|
||||
#define hb_remove_pointer(T) hb_remove_pointer<T>::value
|
||||
|
||||
|
||||
/* Headers we include for everyone. Keep sorted. They express dependency amongst
|
||||
|
Loading…
Reference in New Issue
Block a user