Lines Matching +full:key +full:- +full:value
10 * See the COPYING.LIB file in the top-level directory.
19 #include "qobject-internal.h"
38 * (from module-init-tools)
42 unsigned value; /* Used to compute the hash value. */ in tdb_hash() local
45 /* Set the initial value from the key size. */ in tdb_hash()
46 for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++) { in tdb_hash()
47 value = (value + (((const unsigned char *)name)[i] << (i * 5 % 24))); in tdb_hash()
50 return (1103515243 * value + 12345); in tdb_hash()
56 static QDictEntry *alloc_entry(const char *key, QObject *value) in alloc_entry() argument
61 entry->key = g_strdup(key); in alloc_entry()
62 entry->value = value; in alloc_entry()
68 * qdict_entry_value(): Return qdict entry value
74 return entry->value; in qdict_entry_value()
78 * qdict_entry_key(): Return qdict entry key
85 return entry->key; in qdict_entry_key()
92 const char *key, unsigned int bucket) in qdict_find() argument
96 QLIST_FOREACH(entry, &qdict->table[bucket], next) in qdict_find()
97 if (!strcmp(entry->key, key)) { in qdict_find()
107 * Insert the pair 'key:value' into 'qdict', if 'key' already exists
108 * its 'value' will be replaced.
113 * NOTE: ownership of 'value' is transferred to the QDict
115 void qdict_put_obj(QDict *qdict, const char *key, QObject *value) in qdict_put_obj() argument
120 bucket = tdb_hash(key) % QDICT_BUCKET_MAX; in qdict_put_obj()
121 entry = qdict_find(qdict, key, bucket); in qdict_put_obj()
123 /* replace key's value */ in qdict_put_obj()
124 qobject_unref(entry->value); in qdict_put_obj()
125 entry->value = value; in qdict_put_obj()
128 entry = alloc_entry(key, value); in qdict_put_obj()
129 QLIST_INSERT_HEAD(&qdict->table[bucket], entry, next); in qdict_put_obj()
130 qdict->size++; in qdict_put_obj()
134 void qdict_put_int(QDict *qdict, const char *key, int64_t value) in qdict_put_int() argument
136 qdict_put(qdict, key, qnum_from_int(value)); in qdict_put_int()
139 void qdict_put_bool(QDict *qdict, const char *key, bool value) in qdict_put_bool() argument
141 qdict_put(qdict, key, qbool_from_bool(value)); in qdict_put_bool()
144 void qdict_put_str(QDict *qdict, const char *key, const char *value) in qdict_put_str() argument
146 qdict_put(qdict, key, qstring_from_str(value)); in qdict_put_str()
149 void qdict_put_null(QDict *qdict, const char *key) in qdict_put_null() argument
151 qdict_put(qdict, key, qnull()); in qdict_put_null()
155 * qdict_get(): Lookup for a given 'key'
157 * Return a weak reference to the QObject associated with 'key' if
158 * 'key' is present in the dictionary, NULL otherwise.
160 QObject *qdict_get(const QDict *qdict, const char *key) in qdict_get() argument
164 entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_BUCKET_MAX); in qdict_get()
165 return (entry == NULL ? NULL : entry->value); in qdict_get()
169 * qdict_haskey(): Check if 'key' exists
171 * Return 1 if 'key' exists in the dict, 0 otherwise
173 int qdict_haskey(const QDict *qdict, const char *key) in qdict_haskey() argument
175 unsigned int bucket = tdb_hash(key) % QDICT_BUCKET_MAX; in qdict_haskey()
176 return (qdict_find(qdict, key, bucket) == NULL ? 0 : 1); in qdict_haskey()
184 return qdict->size; in qdict_size()
188 * qdict_get_double(): Get an number mapped by 'key'
190 * This function assumes that 'key' exists and it stores a QNum.
192 * Return number mapped by 'key'.
194 double qdict_get_double(const QDict *qdict, const char *key) in qdict_get_double() argument
196 return qnum_get_double(qobject_to(QNum, qdict_get(qdict, key))); in qdict_get_double()
200 * qdict_get_int(): Get an integer mapped by 'key'
202 * This function assumes that 'key' exists and it stores a
205 * Return integer mapped by 'key'.
207 int64_t qdict_get_int(const QDict *qdict, const char *key) in qdict_get_int() argument
209 return qnum_get_int(qobject_to(QNum, qdict_get(qdict, key))); in qdict_get_int()
213 * qdict_get_bool(): Get a bool mapped by 'key'
215 * This function assumes that 'key' exists and it stores a
218 * Return bool mapped by 'key'.
220 bool qdict_get_bool(const QDict *qdict, const char *key) in qdict_get_bool() argument
222 return qbool_get_bool(qobject_to(QBool, qdict_get(qdict, key))); in qdict_get_bool()
226 * qdict_get_qlist(): If @qdict maps @key to a QList, return it, else NULL.
228 QList *qdict_get_qlist(const QDict *qdict, const char *key) in qdict_get_qlist() argument
230 return qobject_to(QList, qdict_get(qdict, key)); in qdict_get_qlist()
234 * qdict_get_qdict(): If @qdict maps @key to a QDict, return it, else NULL.
236 QDict *qdict_get_qdict(const QDict *qdict, const char *key) in qdict_get_qdict() argument
238 return qobject_to(QDict, qdict_get(qdict, key)); in qdict_get_qdict()
243 * by 'key'
245 * This function assumes that 'key' exists and it stores a
248 * Return pointer to the string mapped by 'key'.
250 const char *qdict_get_str(const QDict *qdict, const char *key) in qdict_get_str() argument
252 return qstring_get_str(qobject_to(QString, qdict_get(qdict, key))); in qdict_get_str()
256 * qdict_get_try_int(): Try to get integer mapped by 'key'
258 * Return integer mapped by 'key', if it is not present in the
262 int64_t qdict_get_try_int(const QDict *qdict, const char *key, in qdict_get_try_int() argument
265 QNum *qnum = qobject_to(QNum, qdict_get(qdict, key)); in qdict_get_try_int()
276 * qdict_get_try_bool(): Try to get a bool mapped by 'key'
278 * Return bool mapped by 'key', if it is not present in the
282 bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value) in qdict_get_try_bool() argument
284 QBool *qbool = qobject_to(QBool, qdict_get(qdict, key)); in qdict_get_try_bool()
291 * mapped by 'key'
293 * Return a pointer to the string mapped by 'key', if it is not present
297 const char *qdict_get_try_str(const QDict *qdict, const char *key) in qdict_get_try_str() argument
299 QString *qstr = qobject_to(QString, qdict_get(qdict, key)); in qdict_get_try_str()
309 if (!QLIST_EMPTY(&qdict->table[i])) { in qdict_next_entry()
310 return QLIST_FIRST(&qdict->table[i]); in qdict_next_entry()
334 unsigned int bucket = tdb_hash(entry->key) % QDICT_BUCKET_MAX; in qdict_next()
354 QLIST_FOREACH(entry, &src->table[i], next) { in qdict_clone_shallow()
355 qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); in qdict_clone_shallow()
368 assert(e->key != NULL); in qentry_destroy()
369 assert(e->value != NULL); in qentry_destroy()
371 qobject_unref(e->value); in qentry_destroy()
372 g_free(e->key); in qentry_destroy()
377 * qdict_del(): Delete a 'key:value' pair from the dictionary
381 void qdict_del(QDict *qdict, const char *key) in qdict_del() argument
385 entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_BUCKET_MAX); in qdict_del()
389 qdict->size--; in qdict_del()
434 QDictEntry *entry = QLIST_FIRST(&qdict->table[i]); in qdict_destroy_obj()