Add hb_nonnull_ptr_t

Towards fixing https://github.com/harfbuzz/harfbuzz/issues/1146
pull/1355/head
Behdad Esfahbod 6 years ago
parent 8d98c51d13
commit fb0f30f55a
  1. 28
      src/hb-null.hh

@ -103,4 +103,32 @@ struct CrapOrNull<const Type> {
#define CrapOrNull(Type) CrapOrNull<Type>::get ()
/*
* hb_nonnull_ptr_t
*/
template <typename P>
struct hb_nonnull_ptr_t
{
typedef typename hb_remove_pointer<P>::value T;
inline hb_nonnull_ptr_t (T *v_ = nullptr) : v (v_) {}
inline T * operator = (T *v_) { return v = v_; }
inline T * operator -> (void) { return get (); }
inline const T * operator -> (void) const { return get (); }
inline T & operator * (void) { return *get (); }
inline const T & operator * (void) const { return *get (); }
inline T ** operator & (void) { return &v; }
inline const T ** operator & (void) const { return &v; }
inline operator T * (void) { return get (); }
inline operator const T * (void) const { return get (); }
inline T * get (void) { return v ? v : const_cast<T *> (&Null(T)); }
inline const T * get (void) const { return v ? v : const_cast<T *> (&Null(T)); }
inline T * get_raw (void) { return v; }
inline const T * get_raw (void) const { return v; }
T *v;
};
#endif /* HB_NULL_HH */

Loading…
Cancel
Save