1 | /* |
2 | * Copyright © 2009 Red Hat, Inc. |
3 | * Copyright © 2018 Google, Inc. |
4 | * |
5 | * This is part of HarfBuzz, a text shaping library. |
6 | * |
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. |
12 | * |
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 |
17 | * DAMAGE. |
18 | * |
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. |
24 | * |
25 | * Red Hat Author(s): Behdad Esfahbod |
26 | * Google Author(s): Behdad Esfahbod |
27 | */ |
28 | |
29 | #ifndef HB_BLOB_HH |
30 | #define HB_BLOB_HH |
31 | |
32 | #include "hb.hh" |
33 | |
34 | |
35 | /* |
36 | * hb_blob_t |
37 | */ |
38 | |
39 | struct hb_blob_t |
40 | { |
41 | inline void fini_shallow (void) |
42 | { |
43 | destroy_user_data (); |
44 | } |
45 | |
46 | inline void destroy_user_data (void) |
47 | { |
48 | if (destroy) |
49 | { |
50 | destroy (user_data); |
51 | user_data = nullptr; |
52 | destroy = nullptr; |
53 | } |
54 | } |
55 | |
56 | HB_INTERNAL bool try_make_writable (void); |
57 | HB_INTERNAL bool try_make_writable_inplace (void); |
58 | HB_INTERNAL bool try_make_writable_inplace_unix (void); |
59 | |
60 | template <typename Type> |
61 | inline const Type* as (void) const |
62 | { |
63 | return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data); |
64 | } |
65 | inline hb_bytes_t as_bytes (void) const |
66 | { |
67 | return hb_bytes_t (data, length); |
68 | } |
69 | |
70 | public: |
71 | hb_object_header_t ; |
72 | ASSERT_POD (); |
73 | |
74 | bool immutable; |
75 | |
76 | const char *data; |
77 | unsigned int length; |
78 | hb_memory_mode_t mode; |
79 | |
80 | void *user_data; |
81 | hb_destroy_func_t destroy; |
82 | }; |
83 | DECLARE_NULL_INSTANCE (hb_blob_t); |
84 | |
85 | |
86 | #endif /* HB_BLOB_HH */ |
87 | |