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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
1 /*
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
2 * Audacious
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
3 * Copyright (c) 2006-2007 Audacious team
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
4 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
7 * the Free Software Foundation; under version 3 of the License.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
8 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
12 * GNU General Public License for more details.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
13 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses>.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
16 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
17 * The Audacious team does not consider modular code linking to
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
18 * Audacious or using our public API to be a derived work.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
19 */
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
20
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
21 #include <glib.h>
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
22 #include <mowgli.h>
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
23
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
24 #include "tuple.h"
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
53 static mowgli_heap_t *tuple_heap = NULL;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
54 static mowgli_heap_t *tuple_value_heap = NULL;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
55 static mowgli_object_class_t tuple_klass;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
69 static void
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
70 tuple_destroy(gpointer data)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
75 mowgli_heap_free(tuple_heap, tuple);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
76 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
77
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
78 Tuple *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
79 tuple_new(void)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
80 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
81 Tuple *tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
82
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
83 if (tuple_heap == NULL)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
be80d9b2c9ef Error fixes.
William Pitcock <nenolod@atheme-project.org>
parents: 3280
diff changeset
86 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
87 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
88 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
89
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
90 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
91 when it is released --nenolod */
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
92 tuple = mowgli_heap_alloc(tuple_heap);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
93 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
94
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
95 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
96
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
97 return tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
98 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
135 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
138
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
155 value = mowgli_heap_alloc(tuple_value_heap);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
156 value->type = TUPLE_STRING;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
157 value->value.string = g_strdup(string);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
163
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
164 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
165 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
166
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
169 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
172
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
185
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
186 value = mowgli_heap_alloc(tuple_value_heap);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
187 value->type = TUPLE_INT;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
188 value->value.integer = integer;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
194
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
195 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
196 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
197
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
209 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
212
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
222
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
228 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
229
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
232 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
233 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
247 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
248
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
251 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
252 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
266
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
267 if (value->type != TUPLE_STRING)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
268 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
269
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
270 return value->value.string;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
271 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
275 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
276 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
290
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
293
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
294 return value->value.integer;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
295 }