ab2a3462d8d717c8e05f21fa8dff7245d06763ac
[framework/uifw/harfbuzz.git] / src / hb-open-type-private.hh
1 /*
2  * Copyright © 2007,2008,2009,2010  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_OPEN_TYPE_PRIVATE_HH
28 #define HB_OPEN_TYPE_PRIVATE_HH
29
30 #include "hb-private.hh"
31
32 #include "hb-blob.h"
33
34 HB_BEGIN_DECLS
35 HB_END_DECLS
36
37
38 /*
39  * Casts
40  */
41
42 /* Cast to struct T, reference to reference */
43 template<typename Type, typename TObject>
44 inline const Type& CastR(const TObject &X)
45 { return reinterpret_cast<const Type&> (X); }
46 template<typename Type, typename TObject>
47 inline Type& CastR(TObject &X)
48 { return reinterpret_cast<Type&> (X); }
49
50 /* Cast to struct T, pointer to pointer */
51 template<typename Type, typename TObject>
52 inline const Type* CastP(const TObject *X)
53 { return reinterpret_cast<const Type*> (X); }
54 template<typename Type, typename TObject>
55 inline Type* CastP(TObject *X)
56 { return reinterpret_cast<Type*> (X); }
57
58 /* StructAtOffset<T>(P,Ofs) returns the struct T& that is placed at memory
59  * location pointed to by P plus Ofs bytes. */
60 template<typename Type>
61 inline const Type& StructAtOffset(const void *P, unsigned int offset)
62 { return * reinterpret_cast<const Type*> ((const char *) P + offset); }
63 template<typename Type>
64 inline Type& StructAtOffset(void *P, unsigned int offset)
65 { return * reinterpret_cast<Type*> ((char *) P + offset); }
66
67 /* StructAfter<T>(X) returns the struct T& that is placed after X.
68  * Works with X of variable size also.  X must implement get_size() */
69 template<typename Type, typename TObject>
70 inline const Type& StructAfter(const TObject &X)
71 { return StructAtOffset<Type>(&X, X.get_size()); }
72 template<typename Type, typename TObject>
73 inline Type& StructAfter(TObject &X)
74 { return StructAtOffset<Type>(&X, X.get_size()); }
75
76
77
78 /*
79  * Size checking
80  */
81
82 /* Check _assertion in a method environment */
83 #define _DEFINE_SIZE_ASSERTION(_assertion) \
84   inline void _size_assertion (void) const \
85   { ASSERT_STATIC (_assertion); }
86 /* Check that _code compiles in a method environment */
87 #define _DEFINE_COMPILES_ASSERTION(_code) \
88   inline void _compiles_assertion (void) const \
89   { _code; }
90
91
92 #define DEFINE_SIZE_STATIC(size) \
93   _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size)); \
94   static const unsigned int static_size = (size); \
95   static const unsigned int min_size = (size)
96
97 /* Size signifying variable-sized array */
98 #define VAR 1
99
100 #define DEFINE_SIZE_UNION(size, _member) \
101   _DEFINE_SIZE_ASSERTION (this->u._member.static_size == (size)); \
102   static const unsigned int min_size = (size)
103
104 #define DEFINE_SIZE_MIN(size) \
105   _DEFINE_SIZE_ASSERTION (sizeof (*this) >= (size)); \
106   static const unsigned int min_size = (size)
107
108 #define DEFINE_SIZE_ARRAY(size, array) \
109   _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \
110   _DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \
111   static const unsigned int min_size = (size)
112
113 #define DEFINE_SIZE_ARRAY2(size, array1, array2) \
114   _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \
115   _DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \
116   static const unsigned int min_size = (size)
117
118
119
120 /*
121  * Null objects
122  */
123
124 /* Global nul-content Null pool.  Enlarge as necessary. */
125 static const void *_NullPool[64 / sizeof (void *)];
126
127 /* Generic nul-content Null objects. */
128 template <typename Type>
129 static inline const Type& Null (void) {
130   ASSERT_STATIC (Type::min_size <= sizeof (_NullPool));
131   return *CastP<Type> (_NullPool);
132 }
133
134 /* Specializaiton for arbitrary-content arbitrary-sized Null objects. */
135 #define DEFINE_NULL_DATA(Type, data) \
136 static const char _Null##Type[Type::min_size + 1] = data; /* +1 is for nul-termination in data */ \
137 template <> \
138 inline const Type& Null<Type> (void) { \
139   return *CastP<Type> (_Null##Type); \
140 } /* The following line really exists such that we end in a place needing semicolon */ \
141 ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type))
142
143 /* Accessor macro. */
144 #define Null(Type) Null<Type>()
145
146
147
148 /*
149  * Sanitize
150  */
151
152 #ifndef HB_DEBUG_SANITIZE
153 #define HB_DEBUG_SANITIZE (HB_DEBUG+0)
154 #endif
155
156
157 #define TRACE_SANITIZE() \
158         hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&c->debug_depth, "SANITIZE", this, NULL, HB_FUNC);
159
160
161 struct hb_sanitize_context_t
162 {
163   inline void init (hb_blob_t *b)
164   {
165     this->blob = hb_blob_reference (b);
166     this->writable = false;
167   }
168
169   inline void setup (void)
170   {
171     this->start = hb_blob_get_data (this->blob, NULL);
172     this->end = this->start + hb_blob_get_length (this->blob);
173     this->edit_count = 0;
174     this->debug_depth = 0;
175
176     DEBUG_MSG (SANITIZE, this->blob,
177                "init [%p..%p] (%lu bytes)",
178                this->start, this->end,
179                (unsigned long) (this->end - this->start));
180   }
181
182   inline void finish (void)
183   {
184     DEBUG_MSG (SANITIZE, this->blob,
185                "fini [%p..%p] %u edit requests",
186                this->start, this->end, this->edit_count);
187
188     hb_blob_destroy (this->blob);
189     this->blob = NULL;
190     this->start = this->end = NULL;
191   }
192
193   inline bool check_range (const void *base, unsigned int len) const
194   {
195     const char *p = (const char *) base;
196     bool ret = this->start <= p &&
197                p <= this->end &&
198                (unsigned int) (this->end - p) >= len;
199
200     DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth,
201                      "%-*d-> range [%p..%p] (%d bytes) in [%p..%p] -> %s",
202                      this->debug_depth, this->debug_depth,
203                      p, p + len, len,
204                      this->start, this->end,
205                      ret ? "pass" : "FAIL");
206
207     return likely (ret);
208   }
209
210   inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const
211   {
212     const char *p = (const char *) base;
213     bool overflows = _hb_unsigned_int_mul_overflows (len, record_size);
214
215     DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth,
216                      "%-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s",
217                      this->debug_depth, this->debug_depth,
218                      p, p + (record_size * len), record_size, len, (unsigned long) record_size * len,
219                      this->start, this->end,
220                      !overflows ? "does not overflow" : "OVERFLOWS FAIL");
221
222     return likely (!overflows && this->check_range (base, record_size * len));
223   }
224
225   template <typename Type>
226   inline bool check_struct (const Type *obj) const
227   {
228     return likely (this->check_range (obj, obj->min_size));
229   }
230
231   inline bool can_edit (const void *base HB_UNUSED, unsigned int len HB_UNUSED)
232   {
233     const char *p = (const char *) base;
234     this->edit_count++;
235
236     DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth,
237                      "%-*d-> edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
238                      this->debug_depth, this->debug_depth,
239                      this->edit_count,
240                      p, p + len, len,
241                      this->start, this->end,
242                      this->writable ? "granted" : "REJECTED");
243
244     return this->writable;
245   }
246
247   unsigned int debug_depth;
248   const char *start, *end;
249   bool writable;
250   unsigned int edit_count;
251   hb_blob_t *blob;
252 };
253
254
255
256 /* Template to sanitize an object. */
257 template <typename Type>
258 struct Sanitizer
259 {
260   static hb_blob_t *sanitize (hb_blob_t *blob) {
261     hb_sanitize_context_t c[1] = {{0}};
262     bool sane;
263
264     /* TODO is_sane() stuff */
265
266     c->init (blob);
267
268   retry:
269     DEBUG_MSG_FUNC (SANITIZE, blob, "start");
270
271     c->setup ();
272
273     if (unlikely (!c->start)) {
274       c->finish ();
275       return blob;
276     }
277
278     Type *t = CastP<Type> (const_cast<char *> (c->start));
279
280     sane = t->sanitize (c);
281     if (sane) {
282       if (c->edit_count) {
283         DEBUG_MSG_FUNC (SANITIZE, blob, "passed first round with %d edits; going for second round", c->edit_count);
284
285         /* sanitize again to ensure no toe-stepping */
286         c->edit_count = 0;
287         sane = t->sanitize (c);
288         if (c->edit_count) {
289           DEBUG_MSG_FUNC (SANITIZE, blob, "requested %d edits in second round; FAILLING", c->edit_count);
290           sane = false;
291         }
292       }
293     } else {
294       unsigned int edit_count = c->edit_count;
295       if (edit_count && !c->writable) {
296         c->start = hb_blob_get_data_writable (blob, NULL);
297         c->end = c->start + hb_blob_get_length (blob);
298
299         if (c->start) {
300           c->writable = true;
301           /* ok, we made it writable by relocating.  try again */
302           DEBUG_MSG_FUNC (SANITIZE, blob, "retry");
303           goto retry;
304         }
305       }
306     }
307
308     c->finish ();
309
310     DEBUG_MSG_FUNC (SANITIZE, blob, sane ? "PASSED" : "FAILED");
311     if (sane)
312       return blob;
313     else {
314       hb_blob_destroy (blob);
315       return hb_blob_get_empty ();
316     }
317   }
318
319   static const Type* lock_instance (hb_blob_t *blob) {
320     hb_blob_make_immutable (blob);
321     const char *base = hb_blob_get_data (blob, NULL);
322     return unlikely (!base) ? &Null(Type) : CastP<Type> (base);
323   }
324 };
325
326
327
328
329 /*
330  *
331  * The OpenType Font File: Data Types
332  */
333
334
335 /* "The following data types are used in the OpenType font file.
336  *  All OpenType fonts use Motorola-style byte ordering (Big Endian):" */
337
338 /*
339  * Int types
340  */
341
342
343 template <typename Type, int Bytes> class BEInt;
344
345 /* LONGTERMTODO: On machines allowing unaligned access, we can make the
346  * following tighter by using byteswap instructions on ints directly. */
347 template <typename Type>
348 class BEInt<Type, 2>
349 {
350   public:
351   inline void set (Type i) { hb_be_uint16_put (v,i); }
352   inline operator Type (void) const { return hb_be_uint16_get (v); }
353   inline bool operator == (const BEInt<Type, 2>& o) const { return hb_be_uint16_eq (v, o.v); }
354   inline bool operator != (const BEInt<Type, 2>& o) const { return !(*this == o); }
355   private: uint8_t v[2];
356 };
357 template <typename Type>
358 class BEInt<Type, 4>
359 {
360   public:
361   inline void set (Type i) { hb_be_uint32_put (v,i); }
362   inline operator Type (void) const { return hb_be_uint32_get (v); }
363   inline bool operator == (const BEInt<Type, 4>& o) const { return hb_be_uint32_eq (v, o.v); }
364   inline bool operator != (const BEInt<Type, 4>& o) const { return !(*this == o); }
365   private: uint8_t v[4];
366 };
367
368 /* Integer types in big-endian order and no alignment requirement */
369 template <typename Type>
370 struct IntType
371 {
372   inline void set (Type i) { v.set (i); }
373   inline operator Type(void) const { return v; }
374   inline bool operator == (const IntType<Type> &o) const { return v == o.v; }
375   inline bool operator != (const IntType<Type> &o) const { return v != o.v; }
376   inline int cmp (Type a) const { Type b = v; return a < b ? -1 : a == b ? 0 : +1; }
377   inline bool sanitize (hb_sanitize_context_t *c) {
378     TRACE_SANITIZE ();
379     return likely (c->check_struct (this));
380   }
381   protected:
382   BEInt<Type, sizeof (Type)> v;
383   public:
384   DEFINE_SIZE_STATIC (sizeof (Type));
385 };
386
387 typedef IntType<uint16_t> USHORT;       /* 16-bit unsigned integer. */
388 typedef IntType<int16_t>  SHORT;        /* 16-bit signed integer. */
389 typedef IntType<uint32_t> ULONG;        /* 32-bit unsigned integer. */
390 typedef IntType<int32_t>  LONG;         /* 32-bit signed integer. */
391
392 /* Date represented in number of seconds since 12:00 midnight, January 1,
393  * 1904. The value is represented as a signed 64-bit integer. */
394 struct LONGDATETIME
395 {
396   inline bool sanitize (hb_sanitize_context_t *c) {
397     TRACE_SANITIZE ();
398     return likely (c->check_struct (this));
399   }
400   private:
401   LONG major;
402   ULONG minor;
403   public:
404   DEFINE_SIZE_STATIC (8);
405 };
406
407 /* Array of four uint8s (length = 32 bits) used to identify a script, language
408  * system, feature, or baseline */
409 struct Tag : ULONG
410 {
411   /* What the char* converters return is NOT nul-terminated.  Print using "%.4s" */
412   inline operator const char* (void) const { return reinterpret_cast<const char *> (&this->v); }
413   inline operator char* (void) { return reinterpret_cast<char *> (&this->v); }
414   public:
415   DEFINE_SIZE_STATIC (4);
416 };
417 DEFINE_NULL_DATA (Tag, "    ");
418
419 /* Glyph index number, same as uint16 (length = 16 bits) */
420 typedef USHORT GlyphID;
421
422 /* Script/language-system/feature index */
423 struct Index : USHORT {
424   static const unsigned int NOT_FOUND_INDEX = 0xFFFF;
425 };
426 DEFINE_NULL_DATA (Index, "\xff\xff");
427
428 /* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */
429 typedef USHORT Offset;
430
431 /* LongOffset to a table, same as uint32 (length = 32 bits), Null offset = 0x00000000 */
432 typedef ULONG LongOffset;
433
434
435 /* CheckSum */
436 struct CheckSum : ULONG
437 {
438   static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length)
439   {
440     uint32_t Sum = 0L;
441     ULONG *EndPtr = Table+((Length+3) & ~3) / ULONG::static_size;
442
443     while (Table < EndPtr)
444       Sum += *Table++;
445     return Sum;
446   }
447   public:
448   DEFINE_SIZE_STATIC (4);
449 };
450
451
452 /*
453  * Version Numbers
454  */
455
456 struct FixedVersion
457 {
458   inline uint32_t to_int (void) const { return (major << 16) + minor; }
459
460   inline bool sanitize (hb_sanitize_context_t *c) {
461     TRACE_SANITIZE ();
462     return c->check_struct (this);
463   }
464
465   USHORT major;
466   USHORT minor;
467   public:
468   DEFINE_SIZE_STATIC (4);
469 };
470
471
472
473 /*
474  * Template subclasses of Offset and LongOffset that do the dereferencing.
475  * Use: (base+offset)
476  */
477
478 template <typename OffsetType, typename Type>
479 struct GenericOffsetTo : OffsetType
480 {
481   inline const Type& operator () (const void *base) const
482   {
483     unsigned int offset = *this;
484     if (unlikely (!offset)) return Null(Type);
485     return StructAtOffset<Type> (base, offset);
486   }
487
488   inline bool sanitize (hb_sanitize_context_t *c, void *base) {
489     TRACE_SANITIZE ();
490     if (unlikely (!c->check_struct (this))) return false;
491     unsigned int offset = *this;
492     if (unlikely (!offset)) return true;
493     Type &obj = StructAtOffset<Type> (base, offset);
494     return likely (obj.sanitize (c)) || neuter (c);
495   }
496   template <typename T>
497   inline bool sanitize (hb_sanitize_context_t *c, void *base, T user_data) {
498     TRACE_SANITIZE ();
499     if (unlikely (!c->check_struct (this))) return false;
500     unsigned int offset = *this;
501     if (unlikely (!offset)) return true;
502     Type &obj = StructAtOffset<Type> (base, offset);
503     return likely (obj.sanitize (c, user_data)) || neuter (c);
504   }
505
506   private:
507   /* Set the offset to Null */
508   inline bool neuter (hb_sanitize_context_t *c) {
509     if (c->can_edit (this, this->static_size)) {
510       this->set (0); /* 0 is Null offset */
511       return true;
512     }
513     return false;
514   }
515 };
516 template <typename Base, typename OffsetType, typename Type>
517 inline const Type& operator + (const Base &base, GenericOffsetTo<OffsetType, Type> offset) { return offset (base); }
518
519 template <typename Type>
520 struct OffsetTo : GenericOffsetTo<Offset, Type> {};
521
522 template <typename Type>
523 struct LongOffsetTo : GenericOffsetTo<LongOffset, Type> {};
524
525
526 /*
527  * Array Types
528  */
529
530 template <typename LenType, typename Type>
531 struct GenericArrayOf
532 {
533   const Type *sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const
534   {
535     unsigned int count = len;
536     if (unlikely (start_offset > count))
537       count = 0;
538     else
539       count -= start_offset;
540     count = MIN (count, *pcount);
541     *pcount = count;
542     return array + start_offset;
543   }
544
545   inline const Type& operator [] (unsigned int i) const
546   {
547     if (unlikely (i >= len)) return Null(Type);
548     return array[i];
549   }
550   inline unsigned int get_size (void) const
551   { return len.static_size + len * Type::static_size; }
552
553   inline bool sanitize (hb_sanitize_context_t *c) {
554     TRACE_SANITIZE ();
555     if (unlikely (!sanitize_shallow (c))) return false;
556
557     /* Note: for structs that do not reference other structs,
558      * we do not need to call their sanitize() as we already did
559      * a bound check on the aggregate array size.  We just include
560      * a small unreachable expression to make sure the structs
561      * pointed to do have a simple sanitize(), ie. they do not
562      * reference other structs via offsets.
563      */
564     (void) (false && array[0].sanitize (c));
565
566     return true;
567   }
568   inline bool sanitize (hb_sanitize_context_t *c, void *base) {
569     TRACE_SANITIZE ();
570     if (unlikely (!sanitize_shallow (c))) return false;
571     unsigned int count = len;
572     for (unsigned int i = 0; i < count; i++)
573       if (unlikely (!array[i].sanitize (c, base)))
574         return false;
575     return true;
576   }
577   template <typename T>
578   inline bool sanitize (hb_sanitize_context_t *c, void *base, T user_data) {
579     TRACE_SANITIZE ();
580     if (unlikely (!sanitize_shallow (c))) return false;
581     unsigned int count = len;
582     for (unsigned int i = 0; i < count; i++)
583       if (unlikely (!array[i].sanitize (c, base, user_data)))
584         return false;
585     return true;
586   }
587
588   private:
589   inline bool sanitize_shallow (hb_sanitize_context_t *c) {
590     TRACE_SANITIZE ();
591     return c->check_struct (this)
592         && c->check_array (this, Type::static_size, len);
593   }
594
595   public:
596   LenType len;
597   Type array[VAR];
598   public:
599   DEFINE_SIZE_ARRAY (sizeof (LenType), array);
600 };
601
602 /* An array with a USHORT number of elements. */
603 template <typename Type>
604 struct ArrayOf : GenericArrayOf<USHORT, Type> {};
605
606 /* An array with a ULONG number of elements. */
607 template <typename Type>
608 struct LongArrayOf : GenericArrayOf<ULONG, Type> {};
609
610 /* Array of Offset's */
611 template <typename Type>
612 struct OffsetArrayOf : ArrayOf<OffsetTo<Type> > {};
613
614 /* Array of LongOffset's */
615 template <typename Type>
616 struct LongOffsetArrayOf : ArrayOf<LongOffsetTo<Type> > {};
617
618 /* LongArray of LongOffset's */
619 template <typename Type>
620 struct LongOffsetLongArrayOf : LongArrayOf<LongOffsetTo<Type> > {};
621
622 /* Array of offsets relative to the beginning of the array itself. */
623 template <typename Type>
624 struct OffsetListOf : OffsetArrayOf<Type>
625 {
626   inline const Type& operator [] (unsigned int i) const
627   {
628     if (unlikely (i >= this->len)) return Null(Type);
629     return this+this->array[i];
630   }
631
632   inline bool sanitize (hb_sanitize_context_t *c) {
633     TRACE_SANITIZE ();
634     return OffsetArrayOf<Type>::sanitize (c, this);
635   }
636   template <typename T>
637   inline bool sanitize (hb_sanitize_context_t *c, T user_data) {
638     TRACE_SANITIZE ();
639     return OffsetArrayOf<Type>::sanitize (c, this, user_data);
640   }
641 };
642
643
644 /* An array with a USHORT number of elements,
645  * starting at second element. */
646 template <typename Type>
647 struct HeadlessArrayOf
648 {
649   inline const Type& operator [] (unsigned int i) const
650   {
651     if (unlikely (i >= len || !i)) return Null(Type);
652     return array[i-1];
653   }
654   inline unsigned int get_size (void) const
655   { return len.static_size + (len ? len - 1 : 0) * Type::static_size; }
656
657   inline bool sanitize_shallow (hb_sanitize_context_t *c) {
658     return c->check_struct (this)
659         && c->check_array (this, Type::static_size, len);
660   }
661
662   inline bool sanitize (hb_sanitize_context_t *c) {
663     TRACE_SANITIZE ();
664     if (unlikely (!sanitize_shallow (c))) return false;
665
666     /* Note: for structs that do not reference other structs,
667      * we do not need to call their sanitize() as we already did
668      * a bound check on the aggregate array size.  We just include
669      * a small unreachable expression to make sure the structs
670      * pointed to do have a simple sanitize(), ie. they do not
671      * reference other structs via offsets.
672      */
673     (void) (false && array[0].sanitize (c));
674
675     return true;
676   }
677
678   USHORT len;
679   Type array[VAR];
680   public:
681   DEFINE_SIZE_ARRAY (sizeof (USHORT), array);
682 };
683
684
685 /* An array with sorted elements.  Supports binary searching. */
686 template <typename Type>
687 struct SortedArrayOf : ArrayOf<Type> {
688
689   template <typename SearchType>
690   inline int search (const SearchType &x) const {
691     class Cmp {
692       public: static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); }
693     };
694     const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), (hb_compare_func_t) Cmp::cmp);
695     return p ? p - this->array : -1;
696   }
697 };
698
699
700 HB_BEGIN_DECLS
701 HB_END_DECLS
702
703 #endif /* HB_OPEN_TYPE_PRIVATE_HH */