2
* * Copyright (C) 2006-2011 Anders Brander <anders@brander.dk>,
3
* * Anders Kvist <akv@lnxbx.dk> and Klaus Post <klauspost@gmail.com>
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "rs-filter-param.h"
22
#define RS_TYPE_FLOAT4 rs_float4_get_type()
25
float4_copy(const gpointer boxed)
27
return g_memdup(boxed, sizeof(gfloat)*4);
31
rs_float4_get_type(void)
33
static GType type = 0;
35
type = g_boxed_type_register_static(g_intern_static_string("RSFloat4"), float4_copy, g_free);
39
G_DEFINE_TYPE(RSFilterParam, rs_filter_param, G_TYPE_OBJECT)
42
rs_filter_param_dispose(GObject *object)
44
RSFilterParam *filter_param = RS_FILTER_PARAM(object);
46
if (!filter_param->dispose_has_run)
48
filter_param->dispose_has_run = TRUE;
50
g_hash_table_destroy(filter_param->properties);
53
G_OBJECT_CLASS(rs_filter_param_parent_class)->dispose (object);
57
rs_filter_param_finalize(GObject *object)
59
G_OBJECT_CLASS(rs_filter_param_parent_class)->finalize (object);
63
rs_filter_param_class_init(RSFilterParamClass *klass)
65
GObjectClass *object_class = G_OBJECT_CLASS (klass);
67
object_class->dispose = rs_filter_param_dispose;
68
object_class->finalize = rs_filter_param_finalize;
71
static inline GValue *
74
GValue *value = g_slice_new0(GValue);
75
g_value_init(value, type);
81
free_value(gpointer data)
83
GValue *value = (GValue *) data;
86
g_slice_free(GValue, value);
89
static inline GValue *
90
clone_value(const GValue *value)
92
GType type = G_VALUE_TYPE(value);
93
GValue *ret = new_value(type);
94
g_value_copy(value, ret);
100
rs_filter_param_init(RSFilterParam *param)
102
param->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_value);
106
rs_filter_param_new(void)
108
return g_object_new (RS_TYPE_FILTER_PARAM, NULL);
112
rs_filter_param_clone(RSFilterParam *destination, const RSFilterParam *source)
114
g_assert(RS_IS_FILTER_PARAM(destination));
115
g_assert(RS_IS_FILTER_PARAM(source));
117
/* Clone the properties table */
121
g_hash_table_iter_init (&iter, source->properties);
122
while (g_hash_table_iter_next (&iter, &key, &value))
123
g_hash_table_insert(destination->properties, (gpointer) g_strdup(key), clone_value(value));
127
rs_filter_param_set_gvalue(RSFilterParam *filter_param, const gchar *name, GValue * value)
129
g_assert(RS_IS_FILTER_PARAM(filter_param));
130
g_assert(name != NULL);
131
g_assert(name[0] != '\0');
133
g_hash_table_insert(filter_param->properties, (gpointer) g_strdup(name), value);
137
rs_filter_param_get_gvalue(const RSFilterParam *filter_param, const gchar *name)
139
g_assert(RS_IS_FILTER_PARAM(filter_param));
141
GValue *value = g_hash_table_lookup(filter_param->properties, name);
147
* Delete a property from a RSFilterParam
148
* @param filter_param A RSFilterParam
149
* @param name The name of the property
150
* @return TRUE if the property was found, FALSE otherwise
153
rs_filter_param_delete(RSFilterParam *filter_param, const gchar *name)
155
g_assert(RS_IS_FILTER_PARAM(filter_param));
157
return g_hash_table_remove(filter_param->properties, name);
161
* Set a string property
162
* @param filter_param A RSFilterParam
163
* @param name The name of the property
164
* @param str NULL-terminated string to set (will be copied)
167
rs_filter_param_set_string(RSFilterParam *filter_param, const gchar *name, const gchar *str)
169
GValue *val = new_value(G_TYPE_STRING);
170
g_value_set_string(val, str);
172
rs_filter_param_set_gvalue(filter_param, name, val);
176
* Get a string property
177
* @param filter_param A RSFilterParam
178
* @param name The name of the property
179
* @param str A pointer to a string pointer where the value of the property can be saved. Should not be freed
180
* @return TRUE if the property was found, FALSE otherwise
183
rs_filter_param_get_string(const RSFilterParam *filter_param, const gchar *name, const gchar ** const str)
185
GValue *val = rs_filter_param_get_gvalue(filter_param, name);
187
if (val && G_VALUE_HOLDS_STRING(val))
188
*str = g_value_get_string(val);
190
return (val != NULL);
194
* Set a boolean property
195
* @param filter_param A RSFilterParam
196
* @param name The name of the property
197
* @param value A value to store
200
rs_filter_param_set_boolean(RSFilterParam *filter_param, const gchar *name, const gboolean value)
202
GValue *val = new_value(G_TYPE_BOOLEAN);
203
g_value_set_boolean(val, value);
205
rs_filter_param_set_gvalue(filter_param, name, val);
209
* Get a gboolean property
210
* @param filter_param A RSFilterParam
211
* @param name The name of the property
212
* @param value A pointer to a gboolean where the value will be stored
213
* @return TRUE if the property was found, FALSE otherwise
216
rs_filter_param_get_boolean(const RSFilterParam *filter_param, const gchar *name, gboolean *value)
218
GValue *val = rs_filter_param_get_gvalue(filter_param, name);
220
if (val && G_VALUE_HOLDS_BOOLEAN(val))
221
*value = g_value_get_boolean(val);
223
return (val != NULL);
227
* Set a integer property
228
* @param filter_param A RSFilterParam
229
* @param name The name of the property
230
* @param value A value to store
233
rs_filter_param_set_integer(RSFilterParam *filter_param, const gchar *name, const gint value)
235
GValue *val = new_value(G_TYPE_INT);
236
g_value_set_int(val, value);
238
rs_filter_param_set_gvalue(filter_param, name, val);
242
* Get a integer property
243
* @param filter_param A RSFilterParam
244
* @param name The name of the property
245
* @param value A pointer to a gint where the value will be stored
246
* @return TRUE if the property was found, FALSE otherwise
249
rs_filter_param_get_integer(const RSFilterParam *filter_param, const gchar *name, gint *value)
251
GValue *val = rs_filter_param_get_gvalue(filter_param, name);
253
if (val && G_VALUE_HOLDS_INT(val))
254
*value = g_value_get_int(val);
256
return (val != NULL);
260
* Set a float property
261
* @param filter_param A RSFilterParam
262
* @param name The name of the property
263
* @param value A value to store
266
rs_filter_param_set_float(RSFilterParam *filter_param, const gchar *name, const gfloat value)
268
GValue *val = new_value(G_TYPE_FLOAT);
269
g_value_set_float(val, value);
271
rs_filter_param_set_gvalue(filter_param, name, val);
275
* Get a float property
276
* @param filter_param A RSFilterParam
277
* @param name The name of the property
278
* @param value A pointer to a gfloat where the value will be stored
279
* @return TRUE if the property was found, FALSE otherwise
282
rs_filter_param_get_float(const RSFilterParam *filter_param, const gchar *name, gfloat *value)
284
GValue *val = rs_filter_param_get_gvalue(filter_param, name);
286
if (val && G_VALUE_HOLDS_FLOAT(val))
287
*value = g_value_get_float(val);
289
return (val != NULL);
293
* Set a float[4] property
294
* @param filter_param A RSFilterParam
295
* @param name The name of the property
296
* @param value A value to store
299
rs_filter_param_set_float4(RSFilterParam *filter_param, const gchar *name, const gfloat value[4])
301
GValue *val = new_value(RS_TYPE_FLOAT4);
302
g_value_set_boxed(val, value);
304
rs_filter_param_set_gvalue(filter_param, name, val);
308
* Get a float property
309
* @param filter_param A RSFilterParam
310
* @param name The name of the property
311
* @param value A pointer to a gfloat [4] where the values will be stored
312
* @return TRUE if the property was found, FALSE otherwise
315
rs_filter_param_get_float4(const RSFilterParam *filter_param, const gchar *name, gfloat value[4])
317
typedef gfloat buh[4];
318
GValue *val = rs_filter_param_get_gvalue(filter_param, name);
320
if (val && G_TYPE_CHECK_VALUE_TYPE(val, RS_TYPE_FLOAT4))
322
gfloat *boxed = g_value_get_boxed(val);
330
return (val != NULL);
334
* Set an object property
335
* @param filter_param A RSFilterParam
336
* @param name The name of the property
337
* @param value An object to store. Refcount will be incremented by one
340
rs_filter_param_set_object(RSFilterParam *filter_param, const gchar *name, gpointer object)
342
g_return_if_fail(G_IS_OBJECT(object));
344
GValue *val = new_value(G_OBJECT_TYPE(object));
345
g_value_set_object(val, object);
347
rs_filter_param_set_gvalue(filter_param, name, val);
351
* Get an object property
352
* @param filter_param A RSFilterParam
353
* @param name The name of the property
354
* @return The object if found, NULL otherwise
357
rs_filter_param_get_object(const RSFilterParam *filter_param, const gchar *name)
359
gpointer object = NULL;
360
GValue *val = rs_filter_param_get_gvalue(filter_param, name);
362
if (val && G_VALUE_HOLDS_OBJECT(val))
363
object = g_value_dup_object(val);
369
* Get an object property
370
* @param filter_param A RSFilterParam
371
* @param name The name of the property
372
* @param type A desired GType, if the type doesn't match, the result is treated as non-existent
373
* @return The object if found, NULL otherwise
376
rs_filter_param_get_object_with_type(const RSFilterParam *filter_param, const gchar *name, GType type)
378
gpointer object = NULL;
379
GValue *val = rs_filter_param_get_gvalue(filter_param, name);
381
if (val && G_TYPE_CHECK_VALUE_TYPE(val, type))
382
object = g_value_dup_object(val);