glib.Relation.Relation Class Reference

List of all members.

Detailed Description

Description A GRelation is a table of data which can be indexed on any number of fields, rather like simple database tables.

A GRelation contains a number of records, called tuples. Each record contains a number of fields. Records are not ordered, so it is not possible to find the record at a particular index. Note that GRelation tables are currently limited to 2 fields. To create a GRelation, use g_relation_new(). To specify which fields should be indexed, use g_relation_index(). Note that this must be called before any tuples are added to the GRelation. To add records to a GRelation use g_relation_insert(). To determine if a given record appears in a GRelation, use g_relation_exists(). Note that fields are compared directly, so pointers must point to the exact same position (i.e. different copies of the same string will not match.) To count the number of records which have a particular value in a given field, use g_relation_count(). To get all the records which have a particular value in a given field, use g_relation_select(). To access fields of the resulting records, use g_tuples_index(). To free the resulting records use g_tuples_destroy(). To delete all records which have a particular value in a given field, use g_relation_delete(). To destroy the GRelation, use g_relation_destroy(). To help debug GRelation objects, use g_relation_print().


Public Member Functions

GRelationgetRelationStruct ()
 this (GRelation *gRelation)
 Sets our main struct and passes it to the parent class.
 this (int fields)
 Creates a new GRelation with the given number of fields.
void index (int field, GHashFunc hashFunc, GEqualFunc keyEqualFunc)
 Creates an index on the given field.
void insert (...)
 Inserts a record into a GRelation.
int exists (...)
 Returns TRUE if a record with the given values exists in a GRelation.
int count (void *key, int field)
 Returns the number of tuples in a GRelation that have the given value in the given field.
Tuples select (void *key, int field)
 Returns all of the tuples which have the given key in the given field.
int delet (void *key, int field)
 Deletes any records from a GRelation that have the given key value in the given field.
void destroy ()
 Destroys the GRelation, freeing all memory allocated.
void print ()
 Outputs information about all records in a GRelation, as well as the indexes.

Protected Member Functions

void * getStruct ()
 the main Gtk struct as a void*

Protected Attributes

GRelationgRelation
 the main Gtk struct


Constructor & Destructor Documentation

glib.Relation.Relation.this ( GRelation gRelation  ) 

Sets our main struct and passes it to the parent class.

glib.Relation.Relation.this ( int  fields  ) 

Creates a new GRelation with the given number of fields.

Note that currently the number of fields must be 2. fields: the number of fields. Returns: a new GRelation.


Member Function Documentation

int glib.Relation.Relation.count ( void *  key,
int  field 
)

Returns the number of tuples in a GRelation that have the given value in the given field.

relation: a GRelation. key: the value to compare with. field: the field of each record to match. Returns: the number of matches.

int glib.Relation.Relation.delet ( void *  key,
int  field 
)

Deletes any records from a GRelation that have the given key value in the given field.

relation: a GRelation. key: the value to compare with. field: the field of each record to match. Returns: the number of records deleted.

void glib.Relation.Relation.destroy (  ) 

Destroys the GRelation, freeing all memory allocated.

However, it does not free memory allocated for the tuple data, so you should free that first if appropriate. relation: a GRelation.

int glib.Relation.Relation.exists (   ...  ) 

Returns TRUE if a record with the given values exists in a GRelation.

Note that the values are compared directly, so that, for example, two copies of the same string will not match. relation: a GRelation. ...: the fields of the record to compare. The number must match the number of fields in the GRelation. Returns: TRUE if a record matches.

GRelation* glib.Relation.Relation.getRelationStruct (  ) 

void* glib.Relation.Relation.getStruct (  )  [protected]

the main Gtk struct as a void*

void glib.Relation.Relation.index ( int  field,
GHashFunc  hashFunc,
GEqualFunc  keyEqualFunc 
)

Creates an index on the given field.

Note that this must be called before any records are added to the GRelation. relation: a GRelation. field: the field to index, counting from 0. hash_func: a function to produce a hash value from the field data. key_equal_func: a function to compare two values of the given field.

void glib.Relation.Relation.insert (   ...  ) 

Inserts a record into a GRelation.

relation: a GRelation. ...: the fields of the record to add. These must match the number of fields in the GRelation, and of type gpointer or gconstpointer.

void glib.Relation.Relation.print (  ) 

Outputs information about all records in a GRelation, as well as the indexes.

It is for debugging. relation: a GRelation.

Tuples glib.Relation.Relation.select ( void *  key,
int  field 
)

Returns all of the tuples which have the given key in the given field.

Use g_tuples_index() to access the returned records. The returned records should be freed with g_tuples_destroy(). relation: a GRelation. key: the value to compare with. field: the field of each record to match. Returns: the records (tuples) that matched.


Member Data Documentation

GRelation* glib.Relation.Relation.gRelation [protected]

the main Gtk struct


SourceForge.net Logo DSource.org Logo digitalmars.com Logo