1 /*
2  * Copyright (C) 2008 Murray Cumming <murrayc@murrayc.com>
3  * Copyright (C) 2008 - 2011 Vivien Malerba <malerba@gnome-db.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA  02110-1301, USA.
19  */
20 
21 
22 #ifndef __GDA_DATA_COMPARATOR_H_
23 #define __GDA_DATA_COMPARATOR_H_
24 
25 #include "gda-decl.h"
26 #include <glib-object.h>
27 
28 G_BEGIN_DECLS
29 
30 #define GDA_TYPE_DATA_COMPARATOR          (gda_data_comparator_get_type())
31 #define GDA_DATA_COMPARATOR(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, gda_data_comparator_get_type(), GdaDataComparator)
32 #define GDA_DATA_COMPARATOR_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, gda_data_comparator_get_type (), GdaDataComparatorClass)
33 #define GDA_IS_DATA_COMPARATOR(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, gda_data_comparator_get_type ())
34 
35 typedef struct _GdaDataComparator GdaDataComparator;
36 typedef struct _GdaDataComparatorClass GdaDataComparatorClass;
37 typedef struct _GdaDataComparatorPrivate GdaDataComparatorPrivate;
38 
39 /* error reporting */
40 extern GQuark gda_data_comparator_error_quark (void);
41 #define GDA_DATA_COMPARATOR_ERROR gda_data_comparator_error_quark ()
42 
43 typedef enum {
44 	GDA_DATA_COMPARATOR_MISSING_DATA_MODEL_ERROR,
45 	GDA_DATA_COMPARATOR_COLUMN_TYPES_MISMATCH_ERROR,
46 	GDA_DATA_COMPARATOR_MODEL_ACCESS_ERROR,
47 	GDA_DATA_COMPARATOR_USER_CANCELLED_ERROR
48 } GdaDataComparatorError;
49 
50 /* differences reporting */
51 typedef enum {
52 	GDA_DIFF_ADD_ROW,
53 	GDA_DIFF_REMOVE_ROW,
54 	GDA_DIFF_MODIFY_ROW
55 } GdaDiffType;
56 
57 typedef struct {
58 	GdaDiffType  type;
59 	gint         old_row;
60 	gint         new_row;
61 	GHashTable  *values; /* key = ('+' or '-') and a column position starting at 0 (string)
62 			      * value = a GValue pointer */
63 } GdaDiff;
64 
65 /* struct for the object's data */
66 struct _GdaDataComparator
67 {
68 	GObject                   object;
69 	GdaDataComparatorPrivate *priv;
70 };
71 
72 /* struct for the object's class */
73 struct _GdaDataComparatorClass
74 {
75 	GObjectClass              parent_class;
76 	gboolean               (* diff_computed)  (GdaDataComparator *comp, GdaDiff *diff);
77 
78 	/*< private >*/
79 	/* Padding for future expansion */
80 	void (*_gda_reserved1) (void);
81 	void (*_gda_reserved2) (void);
82 	void (*_gda_reserved3) (void);
83 	void (*_gda_reserved4) (void);
84 };
85 
86 /**
87  * SECTION:gda-data-comparator
88  * @short_description: Simple data model's contents comparison
89  * @title: GdaDataComparator
90  * @stability: Stable
91  * @see_also: #GdaDataModel
92  *
93  * The #GdaDataComparator is a simple object which takes two #GdaDataModel objects and compare them.
94  * Actual comparison is performed when the gda_data_comparator_compute_diff() is called; for each
95  * difference found, the <link linkend="GdaDataComparator-diff-computed">diff-computed</link> signal
96  * is emitted (any user installed signal handler which returns FALSE stops the computing process).
97  *
98  * There are some limitations to this object:
99  * <itemizedlist>
100  *   <listitem><para>The data models compared must have the same number and type of columns</para></listitem>
101  *   <listitem><para>The comparison is done column-for-column: one cannot omit columns in the comparison, nor compare
102  *   columns with different positions</para></listitem>
103  * </itemizedlist>
104  */
105 
106 
107 GType             gda_data_comparator_get_type        (void) G_GNUC_CONST;
108 GObject          *gda_data_comparator_new             (GdaDataModel *old_model, GdaDataModel *new_model);
109 void              gda_data_comparator_set_key_columns (GdaDataComparator *comp, const gint *col_numbers, gint nb_cols);
110 gboolean          gda_data_comparator_compute_diff    (GdaDataComparator *comp, GError **error);
111 gint              gda_data_comparator_get_n_diffs     (GdaDataComparator *comp);
112 const GdaDiff    *gda_data_comparator_get_diff        (GdaDataComparator *comp, gint pos);
113 
114 G_END_DECLS
115 
116 #endif
117