GdaDataComparator

GdaDataComparator — Simple data model's contents comparison

Stability Level

Stable, unless otherwise indicated

Properties

GdaDataModel * new-model Read / Write
GdaDataModel * old-model Read / Write

Object Hierarchy

    GObject
    ╰── GdaDataComparator

Description

The GdaDataComparator is a simple object which takes two GdaDataModel objects and compare them. Actual comparison is performed when the gda_data_comparator_compute_diff() is called; for each difference found, the diff-computed signal is emitted (any user installed signal handler which returns FALSE stops the computing process).

There are some limitations to this object:

  • The data models compared must have the same number and type of columns

  • The comparison is done column-for-column: one cannot omit columns in the comparison, nor compare columns with different positions

Functions

gda_data_comparator_error_quark ()

GQuark
gda_data_comparator_error_quark (void);

gda_data_comparator_new ()

GObject *
gda_data_comparator_new (GdaDataModel *old_model,
                         GdaDataModel *new_model);

Creates a new comparator to compute the differences from old_model to new_model : if one applies all the computed differences (as GdaDiff structures) to old_model , the resulting data model should have the same contents as new_model .

Parameters

old_model

Data model to which the modifications should be applied

 

new_model

Target data model.

 

Returns

a new GdaDataComparator object.

[type GdaDataComparator][transfer full]


gda_data_comparator_set_key_columns ()

void
gda_data_comparator_set_key_columns (GdaDataComparator *comp,
                                     const gint *col_numbers,
                                     gint nb_cols);

Defines the columns which will be used as a key when searching data. This is not mandatory but will speed things up as less data will be processed.

Parameters

comp

a GdaDataComparator object

 

nb_cols

the size of the col_numbers array

 

col_numbers

an array of nb_cols values.

[array length=nb_cols]

gda_data_comparator_compute_diff ()

gboolean
gda_data_comparator_compute_diff (GdaDataComparator *comp,
                                  GError **error);

Actually computes the differences between the data models for which comp is defined.

For each difference computed, stored in a GdaDiff structure, the "diff-computed" signal is emitted. If one connects to this signal and returns FALSE in the signal handler, then computing differences will be stopped and an error will be returned.

Parameters

comp

a GdaDataComparator object

 

error

a place to store errors, or NULL

 

Returns

TRUE if all the differences have been successfully computed, and FALSE if an error occurred


gda_data_comparator_get_n_diffs ()

gint
gda_data_comparator_get_n_diffs (GdaDataComparator *comp);

Get the number of differences as computed by the last time gda_data_comparator_compute_diff() was called.

Parameters

comp

a GdaDataComparator object

 

Returns

the number of computed differences


gda_data_comparator_get_diff ()

const GdaDiff *
gda_data_comparator_get_diff (GdaDataComparator *comp,
                              gint pos);

Get a pointer to the GdaDiff structure representing the difference which number is pos

Parameters

comp

a GdaDataComparator object

 

pos

the requested difference number (starting at 0)

 

Returns

a pointer to a GdaDiff, or NULL if pos is invalid.

[transfer none]

Types and Values

GDA_DATA_COMPARATOR_ERROR

#define GDA_DATA_COMPARATOR_ERROR gda_data_comparator_error_quark ()

enum GdaDataComparatorError

Members

GDA_DATA_COMPARATOR_MISSING_DATA_MODEL_ERROR

   

GDA_DATA_COMPARATOR_COLUMN_TYPES_MISMATCH_ERROR

   

GDA_DATA_COMPARATOR_MODEL_ACCESS_ERROR

   

GDA_DATA_COMPARATOR_USER_CANCELLED_ERROR

   

enum GdaDiffType

Members

GDA_DIFF_ADD_ROW

   

GDA_DIFF_REMOVE_ROW

   

GDA_DIFF_MODIFY_ROW

   

GdaDiff

typedef struct {
	GdaDiffType  type;
	gint         old_row;
	gint         new_row;
	GHashTable  *values; /* key = ('+' or '-') and a column position starting at 0 (string)
			      * value = a GValue pointer */
} GdaDiff;

Property Details

The “new-model” property

  “new-model”                GdaDataModel *

Flags: Read / Write


The “old-model” property

  “old-model”                GdaDataModel *

Flags: Read / Write

Signal Details

The “diff-computed” signal

gboolean
user_function (GdaDataComparator *gdadatacomparator,
               gpointer           arg1,
               gpointer           user_data)

Flags: Run Last

See Also

GdaDataModel