2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2018 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
41 void fini_shallow () { destroy_user_data (); }
43 void destroy_user_data ()
53 HB_INTERNAL bool try_make_writable ();
54 HB_INTERNAL bool try_make_writable_inplace ();
55 HB_INTERNAL bool try_make_writable_inplace_unix ();
57 template <typename Type>
58 const Type* as () const
60 return length < hb_null_size (Type) ? &Null(Type) : reinterpret_cast<const Type *> (data);
62 hb_bytes_t as_bytes () const
63 { return hb_bytes_t (data, length); }
66 hb_object_header_t header;
70 hb_memory_mode_t mode;
73 hb_destroy_func_t destroy;
84 typedef typename hb_remove_pointer (P) T;
86 hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {}
87 hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; }
88 const T * operator -> () const { return get (); }
89 const T & operator * () const { return *get (); }
90 template <typename C> operator const C * () const { return get (); }
91 operator const char * () const { return (const char *) get (); }
92 const T * get () const { return b->as<T> (); }
93 hb_blob_t * get_blob () const { return b.get_raw (); }
94 unsigned int get_length () const { return b.get ()->length; }
95 void destroy () { hb_blob_destroy (b.get ()); b = nullptr; }
97 hb_nonnull_ptr_t<hb_blob_t> b;
101 #endif /* HB_BLOB_HH */