#include "hb-blob.h"
+HB_BEGIN_DECLS
+HB_END_DECLS
/*
/* Generic nul-content Null objects. */
template <typename Type>
-static inline const Type& Null () {
+static inline const Type& Null (void) {
ASSERT_STATIC (Type::min_size <= sizeof (_NullPool));
return *CastP<Type> (_NullPool);
}
#define DEFINE_NULL_DATA(Type, data) \
static const char _Null##Type[Type::min_size + 1] = data; /* +1 is for nul-termination in data */ \
template <> \
-inline const Type& Null<Type> () { \
+inline const Type& Null<Type> (void) { \
return *CastP<Type> (_Null##Type); \
} /* The following line really exists such that we end in a place needing semicolon */ \
ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type))
this->debug_depth = 0;
if (HB_DEBUG_SANITIZE)
- fprintf (stderr, "sanitize %p init [%p..%p] (%u bytes)\n",
- this->blob, this->start, this->end, this->end - this->start);
+ fprintf (stderr, "sanitize %p init [%p..%p] (%lu bytes)\n",
+ this->blob, this->start, this->end,
+ (unsigned long) (this->end - this->start));
}
inline void finish (void)
inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const
{
const char *p = (const char *) base;
- bool overflows = len >= ((unsigned int) -1) / record_size;
+ bool overflows = record_size > 0 && len >= ((unsigned int) -1) / record_size;
if (HB_DEBUG_SANITIZE && (int) this->debug_depth < (int) HB_DEBUG_SANITIZE)
fprintf (stderr, "SANITIZE(%p) %-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s\n", \
class BEInt<Type, 2>
{
public:
- inline class BEInt<Type,2>& operator = (Type i) { hb_be_uint16_put (v,i); return *this; }
- inline operator Type () const { return hb_be_uint16_get (v); }
+ inline void set (Type i) { hb_be_uint16_put (v,i); }
+ inline operator Type (void) const { return hb_be_uint16_get (v); }
inline bool operator == (const BEInt<Type, 2>& o) const { return hb_be_uint16_cmp (v, o.v); }
inline bool operator != (const BEInt<Type, 2>& o) const { return !(*this == o); }
private: uint8_t v[2];
class BEInt<Type, 4>
{
public:
- inline class BEInt<Type,4>& operator = (Type i) { hb_be_uint32_put (v,i); return *this; }
- inline operator Type () const { return hb_be_uint32_get (v); }
+ inline void set (Type i) { hb_be_uint32_put (v,i); }
+ inline operator Type (void) const { return hb_be_uint32_get (v); }
inline bool operator == (const BEInt<Type, 4>& o) const { return hb_be_uint32_cmp (v, o.v); }
inline bool operator != (const BEInt<Type, 4>& o) const { return !(*this == o); }
private: uint8_t v[4];
template <typename Type>
struct IntType
{
- inline void set (Type i) { v = i; }
+ inline void set (Type i) { v.set (i); }
inline operator Type(void) const { return v; }
inline bool operator == (const IntType<Type> &o) const { return v == o.v; }
inline bool operator != (const IntType<Type> &o) const { return v != o.v; }
+ inline int cmp (Type a) const { Type b = v; return a < b ? -1 : a == b ? 0 : +1; }
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return likely (c->check_struct (this));
if (unlikely (i >= len)) return Null(Type);
return array[i];
}
- inline unsigned int get_size () const
+ inline unsigned int get_size (void) const
{ return len.static_size + len * Type::static_size; }
inline bool sanitize (hb_sanitize_context_t *c) {
if (unlikely (i >= len || !i)) return Null(Type);
return array[i-1];
}
- inline unsigned int get_size () const
+ inline unsigned int get_size (void) const
{ return len.static_size + (len ? len - 1 : 0) * Type::static_size; }
inline bool sanitize_shallow (hb_sanitize_context_t *c) {
};
+/* An array with sorted elements. Supports binary searching. */
+template <typename Type>
+struct SortedArrayOf : ArrayOf<Type> {
+
+ template <typename SearchType>
+ inline int search (const SearchType &x) const {
+ class Cmp {
+ public: static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); }
+ };
+ const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), (hb_compare_func_t) Cmp::cmp);
+ return p ? p - this->array : -1;
+ }
+};
+
+
+HB_BEGIN_DECLS
+HB_END_DECLS
+
#endif /* HB_OPEN_TYPE_PRIVATE_HH */