Bug 1760604 - fix bogus domain to be example.com which is part of our test PAC rules...
[gecko.git] / gfx / harfbuzz / src / hb-map.cc
blob9f1ac42846da1b0685385396ca958b8ee400054d
1 /*
2 * Copyright © 2018 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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.
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.
24 * Google Author(s): Behdad Esfahbod
27 #include "hb-map.hh"
30 /**
31 * SECTION:hb-map
32 * @title: hb-map
33 * @short_description: Object representing integer to integer mapping
34 * @include: hb.h
36 * Map objects are integer-to-integer hash-maps. Currently they are
37 * not used in the HarfBuzz public API, but are provided for client's
38 * use if desired.
39 **/
42 /**
43 * hb_map_create: (Xconstructor)
45 * Creates a new, initially empty map.
47 * Return value: (transfer full): The new #hb_map_t
49 * Since: 1.7.7
50 **/
51 hb_map_t *
52 hb_map_create ()
54 hb_map_t *map;
56 if (!(map = hb_object_create<hb_map_t> ()))
57 return hb_map_get_empty ();
59 map->init_shallow ();
61 return map;
64 /**
65 * hb_map_get_empty:
67 * Fetches the singleton empty #hb_map_t.
69 * Return value: (transfer full): The empty #hb_map_t
71 * Since: 1.7.7
72 **/
73 hb_map_t *
74 hb_map_get_empty ()
76 return const_cast<hb_map_t *> (&Null (hb_map_t));
79 /**
80 * hb_map_reference: (skip)
81 * @map: A map
83 * Increases the reference count on a map.
85 * Return value: (transfer full): The map
87 * Since: 1.7.7
88 **/
89 hb_map_t *
90 hb_map_reference (hb_map_t *map)
92 return hb_object_reference (map);
95 /**
96 * hb_map_destroy: (skip)
97 * @map: A map
99 * Decreases the reference count on a map. When
100 * the reference count reaches zero, the map is
101 * destroyed, freeing all memory.
103 * Since: 1.7.7
105 void
106 hb_map_destroy (hb_map_t *map)
108 if (!hb_object_destroy (map)) return;
110 map->fini_shallow ();
112 hb_free (map);
116 * hb_map_set_user_data: (skip)
117 * @map: A map
118 * @key: The user-data key to set
119 * @data: A pointer to the user data to set
120 * @destroy: (nullable): A callback to call when @data is not needed anymore
121 * @replace: Whether to replace an existing data with the same key
123 * Attaches a user-data key/data pair to the specified map.
125 * Return value: %true if success, %false otherwise
127 * Since: 1.7.7
129 hb_bool_t
130 hb_map_set_user_data (hb_map_t *map,
131 hb_user_data_key_t *key,
132 void * data,
133 hb_destroy_func_t destroy,
134 hb_bool_t replace)
136 return hb_object_set_user_data (map, key, data, destroy, replace);
140 * hb_map_get_user_data: (skip)
141 * @map: A map
142 * @key: The user-data key to query
144 * Fetches the user data associated with the specified key,
145 * attached to the specified map.
147 * Return value: (transfer none): A pointer to the user data
149 * Since: 1.7.7
151 void *
152 hb_map_get_user_data (hb_map_t *map,
153 hb_user_data_key_t *key)
155 return hb_object_get_user_data (map, key);
160 * hb_map_allocation_successful:
161 * @map: A map
163 * Tests whether memory allocation for a set was successful.
165 * Return value: %true if allocation succeeded, %false otherwise
167 * Since: 1.7.7
169 hb_bool_t
170 hb_map_allocation_successful (const hb_map_t *map)
172 return map->successful;
177 * hb_map_set:
178 * @map: A map
179 * @key: The key to store in the map
180 * @value: The value to store for @key
182 * Stores @key:@value in the map.
184 * Since: 1.7.7
186 void
187 hb_map_set (hb_map_t *map,
188 hb_codepoint_t key,
189 hb_codepoint_t value)
191 /* Immutable-safe. */
192 map->set (key, value);
196 * hb_map_get:
197 * @map: A map
198 * @key: The key to query
200 * Fetches the value stored for @key in @map.
202 * Since: 1.7.7
204 hb_codepoint_t
205 hb_map_get (const hb_map_t *map,
206 hb_codepoint_t key)
208 return map->get (key);
212 * hb_map_del:
213 * @map: A map
214 * @key: The key to delete
216 * Removes @key and its stored value from @map.
218 * Since: 1.7.7
220 void
221 hb_map_del (hb_map_t *map,
222 hb_codepoint_t key)
224 /* Immutable-safe. */
225 map->del (key);
229 * hb_map_has:
230 * @map: A map
231 * @key: The key to query
233 * Tests whether @key is an element of @map.
235 * Return value: %true if @key is found in @map, %false otherwise
237 * Since: 1.7.7
239 hb_bool_t
240 hb_map_has (const hb_map_t *map,
241 hb_codepoint_t key)
243 return map->has (key);
248 * hb_map_clear:
249 * @map: A map
251 * Clears out the contents of @map.
253 * Since: 1.7.7
255 void
256 hb_map_clear (hb_map_t *map)
258 return map->clear ();
262 * hb_map_is_empty:
263 * @map: A map
265 * Tests whether @map is empty (contains no elements).
267 * Return value: %true if @map is empty
269 * Since: 1.7.7
271 hb_bool_t
272 hb_map_is_empty (const hb_map_t *map)
274 return map->is_empty ();
278 * hb_map_get_population:
279 * @map: A map
281 * Returns the number of key-value pairs in the map.
283 * Return value: The population of @map
285 * Since: 1.7.7
287 unsigned int
288 hb_map_get_population (const hb_map_t *map)
290 return map->get_population ();