Audacious $Id:Doxyfile42802007-03-2104:39:00Znenolod$
Functions | Variables
tuple.c File Reference

Basic Tuple handling API. More...

#include <glib.h>
#include <mowgli.h>
#include "tuple.h"
#include "audstrings.h"
#include "stringpool.h"

Go to the source code of this file.

Defines

#define TUPLE_LOCK_WRITE(X)   g_static_rw_lock_writer_lock(&tuple_rwlock)
 Convenience macro for read/write locking of the globally used internal Tuple system structures.
#define TUPLE_UNLOCK_WRITE(X)   g_static_rw_lock_writer_unlock(&tuple_rwlock)
 Convenience macro for read/write locking of the globally used internal Tuple system structures.
#define TUPLE_LOCK_READ(X)   g_static_rw_lock_reader_lock(&tuple_rwlock)
 Convenience macro for read/write locking of the globally used internal Tuple system structures.
#define TUPLE_UNLOCK_READ(X)   g_static_rw_lock_reader_unlock(&tuple_rwlock)
 Convenience macro for read/write locking of the globally used internal Tuple system structures.

Functions

static void tuple_value_destroy (mowgli_dictionary_elem_t *delem, gpointer privdata)
static void tuple_destroy (gpointer data)
static Tupletuple_new_unlocked (void)
Tupletuple_new (void)
 Allocates a new empty Tuple structure.
static TupleValuetuple_associate_data (Tuple *tuple, const gint cnfield, const gchar *field, TupleValueType ftype)
 (Re)associates data into given Tuple field.
void tuple_set_filename (Tuple *tuple, const gchar *filename)
 Sets filename/URI related fields of a Tuple structure, based on the given filename argument.
static TupleValuetuple_copy_value (TupleValue *src)
 Creates a copy of given TupleValue structure, with copied data.
Tupletuple_copy (const Tuple *src)
 Creates a copy of given Tuple structure, with copied data.
Tupletuple_new_from_filename (const gchar *filename)
 Allocates a new Tuple structure, setting filename/URI related fields based on the given filename argument by calling tuple_set_filename.
static gint tuple_get_nfield (const gchar *field)
gboolean tuple_associate_string (Tuple *tuple, const gint nfield, const gchar *field, const gchar *string)
 Associates copy of given string to a field in specified Tuple.
gboolean tuple_associate_string_rel (Tuple *tuple, const gint nfield, const gchar *field, gchar *string)
 Associates given string to a field in specified Tuple.
gboolean tuple_associate_int (Tuple *tuple, const gint nfield, const gchar *field, gint integer)
 Associates given integer to a field in specified Tuple.
void tuple_disassociate (Tuple *tuple, const gint cnfield, const gchar *field)
 Disassociates given field from specified Tuple structure.
TupleValueType tuple_get_value_type (const Tuple *tuple, gint cnfield, const gchar *field)
 Returns TupleValueType of given Tuple field.
const gchar * tuple_get_string (const Tuple *tuple, gint cnfield, const gchar *field)
 Returns pointer to a string associated to Tuple field.
gint tuple_get_int (const Tuple *tuple, gint cnfield, const gchar *field)
 Returns integer associated to Tuple field.

Variables

const TupleBasicType tuple_fields [FIELD_LAST]
 Ordered table of basic Tuple field names and their TupleValueType.
static mowgli_heap_t * tuple_heap = NULL
 A mowgli heap containing all the allocated tuples.
static mowgli_heap_t * tuple_value_heap = NULL
 A mowgli heap containing values contained by tuples.
static mowgli_object_class_t tuple_klass
static GStaticRWLock tuple_rwlock = G_STATIC_RW_LOCK_INIT
 Global R/W lock for preserve data consistency of heaps.

Detailed Description

Basic Tuple handling API.

Definition in file tuple.c.


Define Documentation

#define TUPLE_LOCK_READ (   X)    g_static_rw_lock_reader_lock(&tuple_rwlock)

Convenience macro for read/write locking of the globally used internal Tuple system structures.

Definition at line 95 of file tuple.c.

Referenced by tuple_get_int(), tuple_get_string(), and tuple_get_value_type().

#define TUPLE_LOCK_WRITE (   X)    g_static_rw_lock_writer_lock(&tuple_rwlock)

Convenience macro for read/write locking of the globally used internal Tuple system structures.

Definition at line 93 of file tuple.c.

Referenced by tuple_associate_int(), tuple_associate_string(), tuple_copy(), tuple_destroy(), tuple_disassociate(), and tuple_new().

#define TUPLE_UNLOCK_READ (   X)    g_static_rw_lock_reader_unlock(&tuple_rwlock)

Convenience macro for read/write locking of the globally used internal Tuple system structures.

Definition at line 96 of file tuple.c.

Referenced by tuple_get_int(), tuple_get_string(), and tuple_get_value_type().

#define TUPLE_UNLOCK_WRITE (   X)    g_static_rw_lock_writer_unlock(&tuple_rwlock)

Convenience macro for read/write locking of the globally used internal Tuple system structures.

Definition at line 94 of file tuple.c.

Referenced by tuple_associate_data(), tuple_associate_int(), tuple_associate_string(), tuple_copy(), tuple_destroy(), tuple_disassociate(), and tuple_new().


Function Documentation

static TupleValue * tuple_associate_data ( Tuple tuple,
const gint  cnfield,
const gchar *  field,
TupleValueType  ftype 
) [static]

(Re)associates data into given Tuple field.

If specified field already exists in the Tuple, any data from it is freed and this current TupleValue struct is returned.

If field does NOT exist, a new structure is allocated from global heap, added to Tuple and returned.

Attention:
This function has (unbalanced) Tuple structure unlocking, so please make sure you use it only exactly like it is used in tuple_associate_string(), etc.
Parameters:
[in]tupleTuple structure to be manipulated.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]ftypeType of the field to be associated.
Returns:
Pointer to associated TupleValue structure.

Definition at line 360 of file tuple.c.

Referenced by tuple_associate_int(), and tuple_associate_string().

gboolean tuple_associate_int ( Tuple tuple,
const gint  nfield,
const gchar *  field,
gint  integer 
)

Associates given integer to a field in specified Tuple.

If field already exists, old value is freed and replaced.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]nfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]integerInteger to be associated to given field in Tuple.
Returns:
TRUE if operation was succesful, FALSE if not.

Definition at line 486 of file tuple.c.

Referenced by tuple_set_filename().

gboolean tuple_associate_string ( Tuple tuple,
const gint  nfield,
const gchar *  field,
const gchar *  string 
)

Associates copy of given string to a field in specified Tuple.

If field already exists, old value is freed and replaced.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]nfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]stringString to be associated to given field in Tuple.
Returns:
TRUE if operation was succesful, FALSE if not.

Definition at line 425 of file tuple.c.

Referenced by tuple_associate_string_rel(), and tuple_set_filename().

gboolean tuple_associate_string_rel ( Tuple tuple,
const gint  nfield,
const gchar *  field,
gchar *  string 
)

Associates given string to a field in specified Tuple.

The caller gives up ownership of the string. If field already exists, old value is freed and replaced.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]nfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]stringString to be associated to given field in Tuple.
Returns:
TRUE if operation was succesful, FALSE if not.

Definition at line 464 of file tuple.c.

Tuple* tuple_copy ( const Tuple src)

Creates a copy of given Tuple structure, with copied data.

Parameters:
[in]srcTuple structure to be made a copy of.
Returns:
Pointer to newly allocated Tuple.

Definition at line 277 of file tuple.c.

static TupleValue* tuple_copy_value ( TupleValue src) [static]

Creates a copy of given TupleValue structure, with copied data.

Parameters:
[in]srcTupleValue structure to be made a copy of.
Returns:
Pointer to newly allocated TupleValue or NULL if error occured or source was NULL.

Definition at line 247 of file tuple.c.

Referenced by tuple_copy().

static void tuple_destroy ( gpointer  data) [static]

Definition at line 114 of file tuple.c.

Referenced by tuple_new_unlocked().

void tuple_disassociate ( Tuple tuple,
const gint  cnfield,
const gchar *  field 
)

Disassociates given field from specified Tuple structure.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.

Definition at line 510 of file tuple.c.

gint tuple_get_int ( const Tuple tuple,
gint  cnfield,
const gchar *  field 
)

Returns integer associated to Tuple field.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
Returns:
Integer value or 0 if the field/key did not exist.
Bug:
There is no way to distinguish error situations if the associated value is zero.

Definition at line 634 of file tuple.c.

Referenced by entry_set_tuple_real(), read_gain_from_tuple(), tuple_compare_int(), tuple_formatter_expression_empty(), tuple_formatter_expression_match(), tuple_formatter_process_expr(), and tuple_value_to_gvalue().

static gint tuple_get_nfield ( const gchar *  field) [static]
const gchar* tuple_get_string ( const Tuple tuple,
gint  cnfield,
const gchar *  field 
)

Returns pointer to a string associated to Tuple field.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
Returns:
Pointer to string or NULL if the field/key did not exist. The returned string is const, and must not be freed or modified.

Definition at line 592 of file tuple.c.

Referenced by playlist_select_by_patterns(), title_from_tuple(), tuple_compare_string(), tuple_formatter_expression_empty(), tuple_formatter_expression_match(), tuple_formatter_make_title_string(), tuple_formatter_process_expr(), and tuple_value_to_gvalue().

TupleValueType tuple_get_value_type ( const Tuple tuple,
gint  cnfield,
const gchar *  field 
)

Returns TupleValueType of given Tuple field.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
Returns:
TupleValueType of the field or TUPLE_UNKNOWN if there was an error.

Definition at line 555 of file tuple.c.

Referenced by entry_set_tuple_real(), tuple_compare_int(), tuple_formatter_expression_empty(), tuple_formatter_expression_match(), tuple_formatter_process_expr(), and tuple_value_to_gvalue().

Tuple* tuple_new ( void  )

Allocates a new empty Tuple structure.

Must be freed via tuple_free().

Returns:
Pointer to newly allocated Tuple.

Definition at line 169 of file tuple.c.

Referenced by tuple_new_from_filename().

Tuple* tuple_new_from_filename ( const gchar *  filename)

Allocates a new Tuple structure, setting filename/URI related fields based on the given filename argument by calling tuple_set_filename.

Parameters:
[in]filenameFilename URI.
Returns:
Pointer to newly allocated Tuple.

Definition at line 321 of file tuple.c.

Referenced by entry_set_failed().

static Tuple* tuple_new_unlocked ( void  ) [static]

Definition at line 141 of file tuple.c.

Referenced by tuple_copy(), and tuple_new().

void tuple_set_filename ( Tuple tuple,
const gchar *  filename 
)

Sets filename/URI related fields of a Tuple structure, based on the given filename argument.

The fields set are: FIELD_FILE_PATH, FIELD_FILE_NAME and FIELD_FILE_EXT.

Parameters:
[in]filenameFilename URI.
[in,out]tupleTuple structure to manipulate.

Definition at line 194 of file tuple.c.

Referenced by tuple_new_from_filename().

static void tuple_value_destroy ( mowgli_dictionary_elem_t *  delem,
gpointer  privdata 
) [static]

Definition at line 101 of file tuple.c.

Referenced by tuple_destroy().


Variable Documentation

const TupleBasicType tuple_fields[FIELD_LAST]

Ordered table of basic Tuple field names and their TupleValueType.

Definition at line 34 of file tuple.c.

Referenced by audacious_rc_get_tuple_fields(), and tuple_evalctx_add_var().

mowgli_heap_t* tuple_heap = NULL [static]

A mowgli heap containing all the allocated tuples.

Definition at line 79 of file tuple.c.

Referenced by tuple_destroy(), and tuple_new_unlocked().

mowgli_object_class_t tuple_klass [static]

Definition at line 83 of file tuple.c.

Referenced by tuple_new_unlocked().

GStaticRWLock tuple_rwlock = G_STATIC_RW_LOCK_INIT [static]

Global R/W lock for preserve data consistency of heaps.

Definition at line 86 of file tuple.c.

mowgli_heap_t* tuple_value_heap = NULL [static]

A mowgli heap containing values contained by tuples.

Definition at line 82 of file tuple.c.

Referenced by tuple_associate_data(), tuple_copy_value(), tuple_destroy(), tuple_disassociate(), tuple_new_unlocked(), and tuple_value_destroy().