w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

hb-map.cc
Go to the documentation of this file.
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 /**
31  * SECTION:hb-map
32  * @title: hb-map
33  * @short_description: Object representing integer to integer mapping
34  * @include: hb.h
35  *
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  **/
40 
41 
42 /**
43  * hb_map_create: (Xconstructor)
44  *
45  * Creates a new, initially empty map.
46  *
47  * Return value: (transfer full): The new #hb_map_t
48  *
49  * Since: 1.7.7
50  **/
51 hb_map_t *
53 {
54  hb_map_t *map;
55 
56  if (!(map = hb_object_create<hb_map_t> ()))
57  return hb_map_get_empty ();
58 
59  map->init_shallow ();
60 
61  return map;
62 }
63 
64 /**
65  * hb_map_get_empty:
66  *
67  * Fetches the singleton empty #hb_map_t.
68  *
69  * Return value: (transfer full): The empty #hb_map_t
70  *
71  * Since: 1.7.7
72  **/
73 hb_map_t *
75 {
76  return const_cast<hb_map_t *> (&Null (hb_map_t));
77 }
78 
79 /**
80  * hb_map_reference: (skip)
81  * @map: A map
82  *
83  * Increases the reference count on a map.
84  *
85  * Return value: (transfer full): The map
86  *
87  * Since: 1.7.7
88  **/
89 hb_map_t *
91 {
92  return hb_object_reference (map);
93 }
94 
95 /**
96  * hb_map_destroy: (skip)
97  * @map: A map
98  *
99  * Decreases the reference count on a map. When
100  * the reference count reaches zero, the map is
101  * destroyed, freeing all memory.
102  *
103  * Since: 1.7.7
104  **/
105 void
107 {
108  if (!hb_object_destroy (map)) return;
109 
110  map->fini_shallow ();
111 
112  free (map);
113 }
114 
115 /**
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: (optional): A callback to call when @data is not needed anymore
121  * @replace: Whether to replace an existing data with the same key
122  *
123  * Attaches a user-data key/data pair to the specified map.
124  *
125  * Return value: %true if success, %false otherwise
126  *
127  * Since: 1.7.7
128  **/
129 hb_bool_t
132  void * data,
133  hb_destroy_func_t destroy,
135 {
136  return hb_object_set_user_data (map, key, data, destroy, replace);
137 }
138 
139 /**
140  * hb_map_get_user_data: (skip)
141  * @map: A map
142  * @key: The user-data key to query
143  *
144  * Fetches the user data associated with the specified key,
145  * attached to the specified map.
146  *
147  * Return value: (transfer none): A pointer to the user data
148  *
149  * Since: 1.7.7
150  **/
151 void *
154 {
155  return hb_object_get_user_data (map, key);
156 }
157 
158 
159 /**
160  * hb_map_allocation_successful:
161  * @map: A map
162  *
163  * Tests whether memory allocation for a set was successful.
164  *
165  * Return value: %true if allocation succeeded, false otherwise
166  *
167  * Since: 1.7.7
168  **/
169 hb_bool_t
171 {
172  return map->successful;
173 }
174 
175 
176 /**
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
181  *
182  * Stores @key:@value in the map.
183  *
184  * Since: 1.7.7
185  **/
186 void
190 {
191  map->set (key, value);
192 }
193 
194 /**
195  * hb_map_get:
196  * @map: A map
197  * @key: The key to query
198  *
199  * Fetches the value stored for @key in @map.
200  *
201  * Since: 1.7.7
202  **/
206 {
207  return map->get (key);
208 }
209 
210 /**
211  * hb_map_del:
212  * @map: A map
213  * @key: The key to delete
214  *
215  * Removes @key and its stored value from @map.
216  *
217  * Since: 1.7.7
218  **/
219 void
222 {
223  map->del (key);
224 }
225 
226 /**
227  * hb_map_has:
228  * @map: A map
229  * @key: The key to query
230  *
231  * Tests whether @key is an element of @map.
232  *
233  * Return value: %true if @key is found in @map, false otherwise
234  *
235  * Since: 1.7.7
236  **/
237 hb_bool_t
240 {
241  return map->has (key);
242 }
243 
244 
245 /**
246  * hb_map_clear:
247  * @map: A map
248  *
249  * Clears out the contents of @map.
250  *
251  * Since: 1.7.7
252  **/
253 void
255 {
256  return map->clear ();
257 }
258 
259 /**
260  * hb_map_is_empty:
261  * @map: A map
262  *
263  * Tests whether @map is empty (contains no elements).
264  *
265  * Return value: %true if @map is empty
266  *
267  * Since: 1.7.7
268  **/
269 hb_bool_t
271 {
272  return map->is_empty ();
273 }
274 
275 /**
276  * hb_map_get_population:
277  * @map: A map
278  *
279  * Returns the number of key-value pairs in the map.
280  *
281  * Return value: The population of @map
282  *
283  * Since: 1.7.7
284  **/
285 unsigned int
287 {
288  return map->get_population ();
289 }
#define free(a)
Definition: decNumber.cpp:310
struct rect data
Definition: dvipdfm.c:64
void replace(char *, char *)
Definition: dvispc.c:2100
#define map
void(* hb_destroy_func_t)(void *user_data)
Definition: hb-common.h:690
uint32_t hb_codepoint_t
Definition: hb-common.h:106
int hb_bool_t
Definition: hb-common.h:97
hb_bool_t hb_map_has(const hb_map_t *map, hb_codepoint_t key)
Definition: hb-map.cc:238
void hb_map_clear(hb_map_t *map)
Definition: hb-map.cc:254
hb_bool_t hb_map_is_empty(const hb_map_t *map)
Definition: hb-map.cc:270
hb_codepoint_t hb_map_get(const hb_map_t *map, hb_codepoint_t key)
Definition: hb-map.cc:204
hb_map_t * hb_map_reference(hb_map_t *map)
Definition: hb-map.cc:90
hb_map_t * hb_map_create()
Definition: hb-map.cc:52
void * hb_map_get_user_data(hb_map_t *map, hb_user_data_key_t *key)
Definition: hb-map.cc:152
void hb_map_set(hb_map_t *map, hb_codepoint_t key, hb_codepoint_t value)
Definition: hb-map.cc:187
hb_bool_t hb_map_allocation_successful(const hb_map_t *map)
Definition: hb-map.cc:170
hb_map_t * hb_map_get_empty()
Definition: hb-map.cc:74
void hb_map_destroy(hb_map_t *map)
Definition: hb-map.cc:106
void hb_map_del(hb_map_t *map, hb_codepoint_t key)
Definition: hb-map.cc:220
hb_bool_t hb_map_set_user_data(hb_map_t *map, hb_user_data_key_t *key, void *data, hb_destroy_func_t destroy, hb_bool_t replace)
Definition: hb-map.cc:130
unsigned int hb_map_get_population(const hb_map_t *map)
Definition: hb-map.cc:286
#define Null(Type)
Definition: hb-null.hh:94
static void * hb_object_get_user_data(Type *obj, hb_user_data_key_t *key)
Definition: hb-object.hh:329
static bool hb_object_destroy(Type *obj)
Definition: hb-object.hh:274
static Type * hb_object_reference(Type *obj)
Definition: hb-object.hh:264
static bool hb_object_set_user_data(Type *obj, hb_user_data_key_t *key, void *data, hb_destroy_func_t destroy, hb_bool_t replace)
Definition: hb-object.hh:299
#define key
Definition: tex2xindy.c:753
Definition: obx.h:51