1 /*
2 * Copyright © 2018 Google, 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 * Google Author(s): Behdad Esfahbod
25 */
26
27 #include "hb-map.hh"
28
29 /**
30 * SECTION:hb-map
31 * @title: hb-map
32 * @short_description: Object representing integer to integer mapping
33 * @include: hb.h
34 *
35 * Map objects are integer-to-integer hash-maps. Currently they are
36 * not used in the HarfBuzz public API, but are provided for client's
37 * use if desired.
38 **/
39
40 /**
41 * hb_map_create: (Xconstructor)
42 *
43 * Return value: (transfer full):
44 *
45 * Since: 1.7.7
46 **/
hb_map_create()47 hb_map_t *hb_map_create()
48 {
49 hb_map_t *map;
50
51 if (!(map = hb_object_create<hb_map_t>()))
52 return hb_map_get_empty();
53
54 map->init_shallow();
55
56 return map;
57 }
58
59 /**
60 * hb_map_get_empty:
61 *
62 * Return value: (transfer full):
63 *
64 * Since: 1.7.7
65 **/
hb_map_get_empty()66 hb_map_t *hb_map_get_empty()
67 {
68 return const_cast<hb_map_t *>(&Null(hb_map_t));
69 }
70
71 /**
72 * hb_map_reference: (skip)
73 * @map: a map.
74 *
75 * Return value: (transfer full):
76 *
77 * Since: 1.7.7
78 **/
hb_map_reference(hb_map_t * map)79 hb_map_t *hb_map_reference(hb_map_t *map)
80 {
81 return hb_object_reference(map);
82 }
83
84 /**
85 * hb_map_destroy: (skip)
86 * @map: a map.
87 *
88 * Since: 1.7.7
89 **/
hb_map_destroy(hb_map_t * map)90 void hb_map_destroy(hb_map_t *map)
91 {
92 if (!hb_object_destroy(map))
93 return;
94
95 map->fini_shallow();
96
97 free(map);
98 }
99
100 /**
101 * hb_map_allocation_successful:
102 * @map: a map.
103 *
104 *
105 *
106 * Return value:
107 *
108 * Since: 1.7.7
109 **/
hb_map_allocation_successful(const hb_map_t * map)110 hb_bool_t hb_map_allocation_successful(const hb_map_t *map)
111 {
112 return map->successful;
113 }
114
115 /**
116 * hb_map_set:
117 * @map: a map.
118 * @key:
119 * @value:
120 *
121 *
122 *
123 * Since: 1.7.7
124 **/
hb_map_set(hb_map_t * map,hb_codepoint_t key,hb_codepoint_t value)125 void hb_map_set(hb_map_t *map, hb_codepoint_t key, hb_codepoint_t value)
126 {
127 map->set(key, value);
128 }
129
130 /**
131 * hb_map_get:
132 * @map: a map.
133 * @key:
134 *
135 *
136 *
137 * Since: 1.7.7
138 **/
hb_map_get(const hb_map_t * map,hb_codepoint_t key)139 hb_codepoint_t hb_map_get(const hb_map_t *map, hb_codepoint_t key)
140 {
141 return map->get(key);
142 }
143
144 /**
145 * hb_map_del:
146 * @map: a map.
147 * @key:
148 *
149 *
150 *
151 * Since: 1.7.7
152 **/
hb_map_del(hb_map_t * map,hb_codepoint_t key)153 void hb_map_del(hb_map_t *map, hb_codepoint_t key)
154 {
155 map->del(key);
156 }
157
158 /**
159 * hb_map_has:
160 * @map: a map.
161 * @key:
162 *
163 *
164 *
165 * Since: 1.7.7
166 **/
hb_map_has(const hb_map_t * map,hb_codepoint_t key)167 hb_bool_t hb_map_has(const hb_map_t *map, hb_codepoint_t key)
168 {
169 return map->has(key);
170 }
171
172 /**
173 * hb_map_clear:
174 * @map: a map.
175 *
176 *
177 *
178 * Since: 1.7.7
179 **/
hb_map_clear(hb_map_t * map)180 void hb_map_clear(hb_map_t *map)
181 {
182 return map->clear();
183 }
184
185 /**
186 * hb_map_is_empty:
187 * @map: a map.
188 *
189 *
190 *
191 * Since: 1.7.7
192 **/
hb_map_is_empty(const hb_map_t * map)193 hb_bool_t hb_map_is_empty(const hb_map_t *map)
194 {
195 return map->is_empty();
196 }
197
198 /**
199 * hb_map_get_population:
200 * @map: a map.
201 *
202 *
203 *
204 * Since: 1.7.7
205 **/
hb_map_get_population(const hb_map_t * map)206 unsigned int hb_map_get_population(const hb_map_t *map)
207 {
208 return map->get_population();
209 }
210