Mercurial > audlegacy
annotate src/audacious/tuple.c @ 3494:7d1dee4f660a trunk
Check for known fields in tuple_associate_data() when given nfield is
undefined.
| author | Matti Hamalainen <ccr@tnsp.org> |
|---|---|
| date | Wed, 05 Sep 2007 03:28:30 +0300 |
| parents | 899a7ed37a70 |
| children | 6f34cc4217b9 |
| rev | line source |
|---|---|
| 3278 | 1 /* |
| 2 * Audacious | |
| 3 * Copyright (c) 2006-2007 Audacious team | |
| 4 * | |
| 5 * This program is free software; you can redistribute it and/or modify | |
| 6 * it under the terms of the GNU General Public License as published by | |
| 7 * the Free Software Foundation; under version 3 of the License. | |
| 8 * | |
| 9 * This program is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
| 16 * | |
| 17 * The Audacious team does not consider modular code linking to | |
| 18 * Audacious or using our public API to be a derived work. | |
| 19 */ | |
| 20 | |
| 21 #include <glib.h> | |
| 22 #include <mowgli.h> | |
| 23 | |
| 24 #include "tuple.h" | |
| 25 | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
26 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
27 const gchar *tuple_fields[FIELD_LAST] = { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
28 "artist", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
29 "title", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
30 "album", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
31 "comment", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
32 "genre", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
33 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
34 "track", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
35 "track-number", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
36 "length", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
37 "year", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
38 "quality", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
39 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
40 "codec", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
41 "file-name", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
42 "file-path", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
43 "file-ext", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
44 "song-artist", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
45 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
46 "mtime", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
47 "formatter", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
48 "performer", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
49 "copyright", |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
50 }; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
51 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
52 |
| 3278 | 53 static mowgli_heap_t *tuple_heap = NULL; |
| 54 static mowgli_heap_t *tuple_value_heap = NULL; | |
| 55 static mowgli_object_class_t tuple_klass; | |
| 56 | |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
57 /* iterative destructor of tuple values. */ |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
58 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
59 tuple_value_destroy(mowgli_dictionary_elem_t *delem, gpointer privdata) |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
60 { |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
61 TupleValue *value = (TupleValue *) delem->data; |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
62 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
63 if (value->type == TUPLE_STRING) |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
64 g_free(value->value.string); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
65 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
66 mowgli_heap_free(tuple_value_heap, value); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
67 } |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
68 |
| 3278 | 69 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
70 tuple_destroy(gpointer data) |
| 3278 | 71 { |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
72 Tuple *tuple = (Tuple *) data; |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
73 |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
74 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL); |
| 3278 | 75 mowgli_heap_free(tuple_heap, tuple); |
| 76 } | |
| 77 | |
| 78 Tuple * | |
| 79 tuple_new(void) | |
| 80 { | |
| 81 Tuple *tuple; | |
| 82 | |
| 83 if (tuple_heap == NULL) | |
| 84 { | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
85 tuple_heap = mowgli_heap_create(sizeof(Tuple), 32, BH_NOW); |
| 3281 | 86 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW); |
| 3278 | 87 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE); |
| 88 } | |
| 89 | |
| 90 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4 | |
| 91 when it is released --nenolod */ | |
| 92 tuple = mowgli_heap_alloc(tuple_heap); | |
| 93 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL); | |
| 94 | |
| 95 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp); | |
| 96 | |
| 97 return tuple; | |
| 98 } | |
| 99 | |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
100 Tuple * |
|
3304
00286cde2485
Make filename a const
Christian Birchinger <joker@netswarm.net>
parents:
3303
diff
changeset
|
101 tuple_new_from_filename(const gchar *filename) |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
102 { |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
103 gchar *scratch, *ext, *realfn; |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
104 Tuple *tuple; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
105 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
106 g_return_val_if_fail(filename != NULL, NULL); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
107 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
108 tuple = tuple_new(); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
109 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
110 g_return_val_if_fail(tuple != NULL, NULL); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
111 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
112 realfn = g_filename_from_uri(filename, NULL, NULL); |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
113 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
114 scratch = g_path_get_basename(realfn ? realfn : filename); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
115 tuple_associate_string(tuple, FIELD_FILE_NAME, NULL, scratch); |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
116 g_free(scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
117 |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
118 scratch = g_path_get_dirname(realfn ? realfn : filename); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
119 tuple_associate_string(tuple, FIELD_FILE_PATH, NULL, scratch); |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
120 g_free(scratch); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
121 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
122 g_free(realfn); realfn = NULL; |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
123 |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
124 ext = strrchr(filename, '.'); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
125 if (ext != NULL) { |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
126 ++ext; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
127 tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, scratch); |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
128 } |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
129 |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
130 return tuple; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
131 } |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
132 |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
133 |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
134 static gboolean |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
135 tuple_associate_data(const gchar **tfield, TupleValue **value, Tuple *tuple, gint *nfield, const gchar *field) |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
136 { |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
137 g_return_val_if_fail(tuple != NULL, FALSE); |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
138 g_return_val_if_fail(*nfield < FIELD_LAST, FALSE); |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
139 |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
140 /* Check for known fields */ |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
141 if (*nfield < 0) { |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
142 gint i; |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
143 *tfield = field; |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
144 for (i = 0; i < FIELD_LAST && *nfield < 0; i++) |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
145 if (!strcmp(field, tuple_fields[i])) *nfield = i; |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
146 } |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
147 |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
148 if (*nfield >= 0) { |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
149 *tfield = tuple_fields[*nfield]; |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
150 tuple->values[*nfield] = NULL; |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
151 } |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
152 |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
153 if ((*value = mowgli_dictionary_delete(tuple->dict, *tfield))) |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
154 tuple_disassociate_now(*value); |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
155 |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
156 return TRUE; |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
157 } |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
158 |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
159 static void |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
160 tuple_associate_data2(Tuple *tuple, const gint nfield, const gchar *field, TupleValue *value) |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
161 { |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
162 mowgli_dictionary_add(tuple->dict, field, value); |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
163 |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
164 if (nfield >= 0) |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
165 tuple->values[nfield] = value; |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
166 } |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
167 |
| 3278 | 168 gboolean |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
169 tuple_associate_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string) |
| 3278 | 170 { |
| 171 TupleValue *value; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
172 const gchar *tfield; |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
173 gint ifield = nfield; |
| 3278 | 174 |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
175 if (!tuple_associate_data(&tfield, &value, tuple, &ifield, field)) |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
176 return FALSE; |
| 3278 | 177 |
|
3329
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
178 if (string == NULL) |
|
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
179 return TRUE; |
|
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
180 |
| 3278 | 181 value = mowgli_heap_alloc(tuple_value_heap); |
| 182 value->type = TUPLE_STRING; | |
| 183 value->value.string = g_strdup(string); | |
| 184 | |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
185 tuple_associate_data2(tuple, ifield, tfield, value); |
| 3278 | 186 return TRUE; |
| 187 } | |
| 188 | |
| 189 gboolean | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
190 tuple_associate_int(Tuple *tuple, const gint nfield, const gchar *field, gint integer) |
| 3278 | 191 { |
| 192 TupleValue *value; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
193 const gchar *tfield; |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
194 gint ifield = nfield; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
195 |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
196 if (!tuple_associate_data(&tfield, &value, tuple, &ifield, field)) |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
197 return FALSE; |
| 3278 | 198 |
| 199 value = mowgli_heap_alloc(tuple_value_heap); | |
| 200 value->type = TUPLE_INT; | |
| 201 value->value.integer = integer; | |
| 202 | |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
203 tuple_associate_data2(tuple, ifield, tfield, value); |
| 3278 | 204 return TRUE; |
| 205 } | |
| 206 | |
| 207 void | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
208 tuple_disassociate_now(TupleValue *value) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
209 { |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
210 if (value->type == TUPLE_STRING) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
211 g_free(value->value.string); |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
212 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
213 mowgli_heap_free(tuple_value_heap, value); |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
214 } |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
215 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
216 void |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
217 tuple_disassociate(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 218 { |
| 219 TupleValue *value; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
220 const gchar *tfield; |
| 3278 | 221 |
| 222 g_return_if_fail(tuple != NULL); | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
223 g_return_if_fail(nfield < FIELD_LAST); |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
224 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
225 if (nfield < 0) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
226 tfield = field; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
227 else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
228 tfield = tuple_fields[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
229 tuple->values[nfield] = NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
230 } |
| 3278 | 231 |
| 232 /* why _delete()? because _delete() returns the dictnode's data on success */ | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
233 if ((value = mowgli_dictionary_delete(tuple->dict, tfield)) == NULL) |
| 3278 | 234 return; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
235 |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
236 tuple_disassociate_now(value); |
| 3278 | 237 } |
| 238 | |
| 239 TupleValueType | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
240 tuple_get_value_type(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 241 { |
| 242 TupleValue *value; | |
| 243 | |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
244 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
245 g_return_val_if_fail(nfield < FIELD_LAST, TUPLE_UNKNOWN); |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
246 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
247 if (nfield < 0) { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
248 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) != NULL) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
249 return value->type; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
250 } else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
251 if (tuple->values[nfield]) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
252 return tuple->values[nfield]->type; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
253 } |
| 3278 | 254 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
255 return TUPLE_UNKNOWN; |
| 3278 | 256 } |
| 257 | |
| 258 const gchar * | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
259 tuple_get_string(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 260 { |
| 261 TupleValue *value; | |
| 262 | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
263 g_return_val_if_fail(tuple != NULL, NULL); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
264 g_return_val_if_fail(nfield < FIELD_LAST, NULL); |
| 3278 | 265 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
266 if (nfield < 0) { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
267 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
268 return NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
269 } else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
270 if (tuple->values[nfield]) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
271 value = tuple->values[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
272 else |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
273 return NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
274 } |
| 3278 | 275 |
| 276 if (value->type != TUPLE_STRING) | |
| 277 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL); | |
| 278 | |
| 279 return value->value.string; | |
| 280 } | |
| 281 | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
282 gint |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
283 tuple_get_int(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 284 { |
| 285 TupleValue *value; | |
| 286 | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
287 g_return_val_if_fail(tuple != NULL, 0); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
288 g_return_val_if_fail(nfield < FIELD_LAST, 0); |
| 3278 | 289 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
290 if (nfield < 0) { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
291 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
292 return 0; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
293 } else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
294 if (tuple->values[nfield]) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
295 value = tuple->values[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
296 else |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
297 return 0; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
298 } |
| 3278 | 299 |
| 300 if (value->type != TUPLE_INT) | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
301 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0); |
| 3278 | 302 |
| 303 return value->value.integer; | |
| 304 } |
