LIRC libraries
LinuxInfraredRemoteControl
dictionary.h
Go to the documentation of this file.
1 #ifndef _DICTIONARY_H_
2 #define _DICTIONARY_H_
3 
4 /* Copyright (c) 2000-2007 by Nicolas Devillard.
5  * Copyright (x) 2009 by Tim Post <tinkertim@gmail.com>
6  * MIT License
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <unistd.h>
36 
67 typedef struct _dictionary_ {
68  int n;
69  int size;
70  char** val;
71  char** key;
72  unsigned* hash;
73 } dictionary;
74 
85 unsigned dictionary_hash(const char* key);
86 
96 dictionary* dictionary_new(int size);
97 
105 void dictionary_del(dictionary* vd);
106 
119 const char* dictionary_get(dictionary* d, const char* key, const char* def);
120 
145 int dictionary_set(dictionary* vd, const char* key, const char* val);
146 
156 void dictionary_unset(dictionary* d, const char* key);
157 
168 void dictionary_dump(dictionary* d, FILE* out);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif
175 
int dictionary_set(dictionary *d, const char *key, const char *val)
Set a value in a dictionary.
Definition: dictionary.c:147
const char * dictionary_get(dictionary *d, const char *key, const char *def)
Get a value from a dictionary.
Definition: dictionary.c:128
dictionary * dictionary_new(int size)
Create a new dictionary object.
Definition: dictionary.c:92
struct _dictionary_ dictionary
Dictionary object.
void dictionary_del(dictionary *d)
Delete a dictionary object.
Definition: dictionary.c:109
void dictionary_unset(dictionary *d, const char *key)
Delete a key in a dictionary.
Definition: dictionary.c:206
void dictionary_dump(dictionary *d, FILE *out)
Dump a dictionary to an opened file pointer.
Definition: dictionary.c:241
Dictionary object.
Definition: dictionary.h:67
unsigned dictionary_hash(const char *key)
Compute the hash key for a string.
Definition: dictionary.c:74