Mercurial > audlegacy
annotate src/audacious/tuple.c @ 3489:9580bb3e58fa trunk
Tuple handling API changed to include support for "hardcoded" fields.
| author | Matti Hamalainen <ccr@tnsp.org> |
|---|---|
| date | Sat, 01 Sep 2007 07:08:21 +0300 |
| parents | 86dafe2300f7 |
| children | 899a7ed37a70 |
| 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 |
| 3278 | 133 gboolean |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
134 tuple_associate_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string) |
| 3278 | 135 { |
| 136 TupleValue *value; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
137 const gchar *tfield; |
| 3278 | 138 |
| 139 g_return_val_if_fail(tuple != NULL, FALSE); | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
140 g_return_val_if_fail(nfield < FIELD_LAST, FALSE); |
| 3278 | 141 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
142 if (nfield < 0) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
143 tfield = field; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
144 else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
145 tfield = tuple_fields[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
146 tuple->values[nfield] = NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
147 } |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
148 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
149 if ((value = mowgli_dictionary_delete(tuple->dict, tfield))) |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
150 tuple_disassociate_now(value); |
| 3278 | 151 |
|
3329
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
152 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
|
153 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
|
154 |
| 3278 | 155 value = mowgli_heap_alloc(tuple_value_heap); |
| 156 value->type = TUPLE_STRING; | |
| 157 value->value.string = g_strdup(string); | |
| 158 | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
159 mowgli_dictionary_add(tuple->dict, tfield, value); |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
160 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
161 if (nfield >= 0) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
162 tuple->values[nfield] = value; |
| 3278 | 163 |
| 164 return TRUE; | |
| 165 } | |
| 166 | |
| 167 gboolean | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
168 tuple_associate_int(Tuple *tuple, const gint nfield, const gchar *field, gint integer) |
| 3278 | 169 { |
| 170 TupleValue *value; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
171 const gchar *tfield; |
| 3278 | 172 |
| 173 g_return_val_if_fail(tuple != NULL, FALSE); | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
174 g_return_val_if_fail(nfield < FIELD_LAST, FALSE); |
| 3278 | 175 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
176 if (nfield < 0) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
177 tfield = field; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
178 else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
179 tfield = tuple_fields[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
180 tuple->values[nfield] = NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
181 } |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
182 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
183 if ((value = mowgli_dictionary_delete(tuple->dict, tfield))) |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
184 tuple_disassociate_now(value); |
| 3278 | 185 |
| 186 value = mowgli_heap_alloc(tuple_value_heap); | |
| 187 value->type = TUPLE_INT; | |
| 188 value->value.integer = integer; | |
| 189 | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
190 mowgli_dictionary_add(tuple->dict, tfield, value); |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
191 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
192 if (nfield >= 0) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
193 tuple->values[nfield] = value; |
| 3278 | 194 |
| 195 return TRUE; | |
| 196 } | |
| 197 | |
| 198 void | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
199 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
|
200 { |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
201 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
|
202 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
|
203 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
204 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
|
205 } |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
206 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
207 void |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
208 tuple_disassociate(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 209 { |
| 210 TupleValue *value; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
211 const gchar *tfield; |
| 3278 | 212 |
| 213 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
|
214 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
|
215 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
216 if (nfield < 0) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
217 tfield = field; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
218 else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
219 tfield = tuple_fields[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
220 tuple->values[nfield] = NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
221 } |
| 3278 | 222 |
| 223 /* 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
|
224 if ((value = mowgli_dictionary_delete(tuple->dict, tfield)) == NULL) |
| 3278 | 225 return; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
226 |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
227 tuple_disassociate_now(value); |
| 3278 | 228 } |
| 229 | |
| 230 TupleValueType | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
231 tuple_get_value_type(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 232 { |
| 233 TupleValue *value; | |
| 234 | |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
235 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
|
236 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
|
237 |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
238 if (nfield < 0) { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
239 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
|
240 return value->type; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
241 } else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
242 if (tuple->values[nfield]) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
243 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
|
244 } |
| 3278 | 245 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
246 return TUPLE_UNKNOWN; |
| 3278 | 247 } |
| 248 | |
| 249 const gchar * | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
250 tuple_get_string(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 251 { |
| 252 TupleValue *value; | |
| 253 | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
254 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
|
255 g_return_val_if_fail(nfield < FIELD_LAST, NULL); |
| 3278 | 256 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
257 if (nfield < 0) { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
258 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
|
259 return NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
260 } else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
261 if (tuple->values[nfield]) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
262 value = tuple->values[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
263 else |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
264 return NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
265 } |
| 3278 | 266 |
| 267 if (value->type != TUPLE_STRING) | |
| 268 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL); | |
| 269 | |
| 270 return value->value.string; | |
| 271 } | |
| 272 | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
273 gint |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
274 tuple_get_int(Tuple *tuple, const gint nfield, const gchar *field) |
| 3278 | 275 { |
| 276 TupleValue *value; | |
| 277 | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
278 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
|
279 g_return_val_if_fail(nfield < FIELD_LAST, 0); |
| 3278 | 280 |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
281 if (nfield < 0) { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
282 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
|
283 return 0; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
284 } else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
285 if (tuple->values[nfield]) |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
286 value = tuple->values[nfield]; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
287 else |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
288 return 0; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
289 } |
| 3278 | 290 |
| 291 if (value->type != TUPLE_INT) | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
292 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0); |
| 3278 | 293 |
| 294 return value->value.integer; | |
| 295 } |
